You are here

public function EnvironmentVariablesKeyProvider::checkRequirements in Apigee Edge 8

Checks the requirements of the key provider.

Parameters

\Drupal\key\KeyInterface $key: The key entity.

Throws

\Drupal\apigee_edge\Exception\KeyProviderRequirementsException Exception thrown when the requirements of the key provider are not fulfilled.

Overrides KeyProviderRequirementsInterface::checkRequirements

File

src/Plugin/KeyProvider/EnvironmentVariablesKeyProvider.php, line 86

Class

EnvironmentVariablesKeyProvider
Stores Apigee Edge authentication credentials in environment variables.

Namespace

Drupal\apigee_edge\Plugin\KeyProvider

Code

public function checkRequirements(KeyInterface $key) : void {
  $missing_env_variables = [];
  foreach ($this
    ->getEnvironmentVariables($key, TRUE) as $variable) {
    if (!getenv($variable)) {
      $missing_env_variables[] = $variable;
    }
  }
  if (!empty($missing_env_variables)) {
    $missing_env_variables_to_string = implode(', ', $missing_env_variables);
    throw new KeyProviderRequirementsException('The following environment variables are not set: ' . $missing_env_variables_to_string, $this
      ->t('The following environment variables are not set: @missing_env_variables.', [
      '@missing_env_variables' => $missing_env_variables_to_string,
    ]));
  }
}