class SecretInfo in Lockr 8.4
Same name and namespace in other branches
- 8.3 src/SecretInfo.php \Drupal\lockr\SecretInfo
- 4.x src/SecretInfo.php \Drupal\lockr\SecretInfo
SecretInfo implements secret info for Lockr secrets.
Hierarchy
- class \Drupal\lockr\SecretInfo implements \Lockr\SecretInfoInterface
Expanded class hierarchy of SecretInfo
1 string reference to 'SecretInfo'
1 service uses SecretInfo
File
- src/
SecretInfo.php, line 14
Namespace
Drupal\lockrView source
class SecretInfo implements SecretInfoInterface {
/**
* Simple config factory.
*
* @var ConfigFactoryInterface
*/
protected $configFactory;
/**
* Key repository.
*
* @var KeyRepositoryInterface
*/
protected $keyRepository;
/**
* Constructs a new settings factory.
*
* @param ConfigFactoryInterface $config_factory
* The simple config factory.
* @param EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param KeyRepositoryInterface $key_repository
* The key respository.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, KeyRepositoryInterface $key_repository) {
$this->configFactory = $config_factory;
$this->secretStorage = $entity_type_manager
->getStorage('lockr_secret');
$this->keyRepository = $key_repository;
}
/**
* {@inheritdoc}
*/
public function getSecretInfo($name) {
/** @var \Drupal\lockr\SecretInterface */
$secret = $this->secretStorage
->load($name);
if (!is_null($secret)) {
return $secret
->getInfo();
}
$config = $this->configFactory
->get('lockr.secret_info');
$info = $config
->get($name);
if (!$info) {
$key = $this->keyRepository
->getKey($name);
if ($key) {
$provider = $key
->getKeyProvider();
$config = $provider
->getConfiguration();
if (isset($config['encoded'])) {
return [
'wrapping_key' => $config['encoded'],
];
}
}
}
return $info ?: [];
}
/**
* {@inheritdoc}
*/
public function setSecretInfo($name, array $info) {
$secret = $this->secretStorage
->load($name);
if (is_null($secret)) {
$secret = $this->secretStorage
->create([
'id' => $name,
'key_id' => $name,
]);
}
$secret
->setInfo($info);
$secret
->save();
}
/**
* {@inheritdoc}
*/
public function getAllSecretInfo() {
$info = [];
foreach ($this->secretStorage
->loadMultiple(NULL) as $secret) {
$info[$secret
->id()] = $secret
->getInfo();
}
return $info;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SecretInfo:: |
protected | property | Simple config factory. | |
SecretInfo:: |
protected | property | Key repository. | |
SecretInfo:: |
public | function | ||
SecretInfo:: |
public | function | ||
SecretInfo:: |
public | function | ||
SecretInfo:: |
public | function | Constructs a new settings factory. |