public function KeyCommands::valueGet in Key 8
Display a list of available key providers.
@command key:value-get
@option base64 Base64-encode the key value. This is useful in the case of binary encryption keys that would otherwise not be displayed in a readable way. @aliases key-value-get, key-value @format table
Parameters
string $id: The ID (machine name) of the key whose value should be retrieved.
array $options: Options array.
File
- src/
Commands/ KeyCommands.php, line 350
Class
- KeyCommands
- Class KeyCommands.
Namespace
Drupal\key\CommandsCode
public function valueGet($id, array $options = [
'base64' => NULL,
]) {
$result = [];
// Look for a key with the specified ID. If one does not exist, set an
// error and abort.
/* @var $key \Drupal\key\Entity\Key */
$key = $this->repository
->getKey($id);
if (!$key) {
throw new \Exception(dt('Key !id does not exist.', [
'!id' => $id,
]));
}
// Retrieve the key value.
$key_value = $key
->getKeyValue(TRUE);
// If the Base64 option was specified, encode the key value.
$base64 = $options['base64'];
if ($base64) {
$key_value = base64_encode($key_value);
}
$row = [];
$row['Key value'] = $key_value;
$result[] = $row;
return new RowsOfFields($result);
}