You are here

public function EnvKeyProvider::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/EnvKeyProvider.php, line 96

Class

EnvKeyProvider
A key provider that allows a key to be stored in an environment variable.

Namespace

Drupal\key\Plugin\KeyProvider

Code

public function getKeyValue(KeyInterface $key) {
  $env_variable = $this->configuration['env_variable'];
  $key_value = getenv($env_variable);
  if (!$key_value) {
    return NULL;
  }
  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;
}