protected function GetSettingsFromEnvVar::isValidCredential in Acquia Content Hub 8.2
Checks credentials are all set and valid.
Parameters
array $credentials: Credentials for registering ACH.
Return value
bool TRUE if there is no error at all.
1 call to GetSettingsFromEnvVar::isValidCredential()
- GetSettingsFromEnvVar::onGetSettings in src/
EventSubscriber/ GetSettings/ GetSettingsFromEnvVar.php - Extract settings from environment and create a Settings object.
File
- src/
EventSubscriber/ GetSettings/ GetSettingsFromEnvVar.php, line 132
Class
- GetSettingsFromEnvVar
- Gets the ContentHub Server settings from environment variable.
Namespace
Drupal\acquia_contenthub\EventSubscriber\GetSettingsCode
protected function isValidCredential(array $credentials) : bool {
$errors = [];
if (count(self::ENVIRONMENT_VARIABLES) !== count($credentials)) {
$errors[] = $this
->t('Some of the credentials missing from the environment variables.');
}
foreach (self::ENVIRONMENT_VARIABLES as $variable) {
if (!isset($credentials[$variable])) {
$errors[] = $this
->t('Credential missing from environment variables: @var', [
'@var' => $variable,
]);
}
}
foreach ([
'acquia_contenthub_hostname',
'acquia_contenthub_webhook_url',
] as $url) {
if (isset($credentials[$url]) && !UrlHelper::isValid($credentials[$url], TRUE)) {
$errors[] = $this
->t('@url is not a valid url. Please insert another one.', [
'@url' => $url,
]);
}
}
foreach ($errors as $error) {
$this->messenger
->addWarning($this
->t('Environment variables set for registering ACH, but something went wrong. Error: @error', [
'@error' => $error,
]));
$this->logger
->error($this
->t('Environment variables set for registering ACH, but something went wrong. Error: @error', [
'@error' => $error,
]));
}
return empty($errors);
}