public function FileKeyProvider::getKeyValue in Key 8
Returns the value of a key.
Parameters
\Drupal\key\KeyInterface $key: The key whose value will be retrieved.
Return value
string The key value.
Overrides KeyProviderInterface::getKeyValue
File
- src/
Plugin/ KeyProvider/ FileKeyProvider.php, line 104
Class
- FileKeyProvider
- Adds a key provider that allows a key to be stored in a file.
Namespace
Drupal\key\Plugin\KeyProviderCode
public function getKeyValue(KeyInterface $key) {
$file = $this->configuration['file_location'];
// Make sure the file exists and is readable.
if (!is_file($file) || !is_readable($file)) {
return NULL;
}
$key_value = file_get_contents($file);
if (isset($this->configuration['strip_line_breaks']) && $this->configuration['strip_line_breaks'] == TRUE) {
$key_value = rtrim($key_value, "\n\r");
}
if (isset($this->configuration['base64_encoded']) && $this->configuration['base64_encoded'] == TRUE) {
$key_value = base64_decode($key_value);
}
return $key_value;
}