KeyProvider.php in Entity Share 8.3
File
modules/entity_share_client/src/Service/KeyProvider.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_client\Service;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Drupal\key\Entity\Key;
use Drupal\entity_share_client\ClientAuthorization\ClientAuthorizationInterface;
use Drupal\key\KeyRepositoryInterface;
class KeyProvider {
protected $keyRepository;
protected $keyValueStore;
public function __construct(KeyValueFactoryInterface $key_value_factory) {
$this->keyValueStore = $key_value_factory
->get(ClientAuthorizationInterface::LOCAL_STORAGE_KEY_VALUE_COLLECTION);
}
public function setKeyRepository(KeyRepositoryInterface $repository) {
$this->keyRepository = $repository;
}
public function additionalProviders() {
return $this->keyRepository instanceof KeyRepositoryInterface;
}
public function getCredentials(ClientAuthorizationInterface $plugin) {
$provider = $plugin
->getCredentialProvider();
$credentials = [];
if (empty($provider)) {
return $credentials;
}
switch ($provider) {
case 'key':
$keyEntity = $this->keyRepository
->getKey($plugin
->getStorageKey());
if ($keyEntity instanceof Key) {
$credentials = $keyEntity
->getKeyValues();
}
break;
default:
$credentials = $this->keyValueStore
->get($plugin
->getStorageKey());
}
return $credentials;
}
}
Classes
Name |
Description |
KeyProvider |
Abstraction layer to support local storage and Key module. |