You are here

class KeyProvider in Akamai 8.3

Wrapper around the optional key.provider service.

Hierarchy

Expanded class hierarchy of KeyProvider

1 string reference to 'KeyProvider'
akamai.services.yml in ./akamai.services.yml
akamai.services.yml
1 service uses KeyProvider
akamai.key_provider in ./akamai.services.yml
Drupal\akamai\KeyProvider

File

src/KeyProvider.php, line 8

Namespace

Drupal\akamai
View source
class KeyProvider implements KeyProviderInterface {

  /**
   * The key repository service if valid.
   *
   * @var \Drupal\key\KeyRepositoryInterface|null
   */
  protected $keyRepository;

  /**
   * Creates a new key provider service.
   *
   * @param mixed $key_repository
   *   Optional key.repository service (from key module).
   */
  public function __construct($key_repository) {
    $this->keyRepository = $key_repository;
  }

  /**
   * {@inheritdoc}
   */
  public function hasKeyRepository() {
    return isset($this->keyRepository);
  }

  /**
   * {@inheritdoc}
   */
  public function getKey($key) {
    if (!$this
      ->hasKeyRepository()) {
      throw new \Exception('Missing key.repository service. Ensure key module is enabled.');
    }
    $key_entity = $this->keyRepository
      ->getKey($key);
    if (isset($key_entity)) {
      return $key_entity
        ->getKeyValue();
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getKeys() {
    if (!$this
      ->hasKeyRepository()) {
      throw new \Exception('Missing key.repository service. Ensure key module is enabled.');
    }
    return $this->keyRepository
      ->getKeys();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyProvider::$keyRepository protected property The key repository service if valid.
KeyProvider::getKey public function Retrieves a key from the key module. Overrides KeyProviderInterface::getKey
KeyProvider::getKeys public function Retrieves all keys from the key module. Overrides KeyProviderInterface::getKeys
KeyProvider::hasKeyRepository public function Confirms if key.repository service exists. Overrides KeyProviderInterface::hasKeyRepository
KeyProvider::__construct public function Creates a new key provider service.