public function AcsfVariablesCommands::vget in Acquia Cloud Site Factory Connector 8.2
Retrieves a named ACSF variable.
@command acsf-vget @option exact Only retrieve the exact variable name specified.
Parameters
string $name: The name of the variable to retrieve.
array $options: The command options supplied to the executed command.
Return value
\Consolidation\OutputFormatters\StructuredData\PropertyList ProperyList of the variable.
Throws
\Drupal\acsf\AcsfException If the variable does not exist with the provided name or the acsf_variables module isn't enabled.
\InvalidArgumentException If one or more arguments are missing or invalid.
File
- acsf_variables/
src/ Commands/ AcsfVariablesCommands.php, line 34
Class
- AcsfVariablesCommands
- Provides drush commands for the acsf_variables module.
Namespace
Drupal\acsf_variables\CommandsCode
public function vget($name, array $options = [
'exact' => FALSE,
]) {
if (!\Drupal::moduleHandler()
->moduleExists('acsf_variables')) {
throw new AcsfException(dt('The acsf_variables module must be enabled.'));
}
if (empty($name)) {
throw new \InvalidArgumentException(dt('You must provide the name of the variable to retrieve as the first argument.'));
}
$exact = $options['exact'];
if ($exact) {
if (($value = \Drupal::service('acsf.variable_storage')
->get($name)) && !is_null($value)) {
$variables[$name] = $value;
}
}
else {
$variables = \Drupal::service('acsf.variable_storage')
->getMatch($name);
}
if (!empty($variables)) {
return new PropertyList($variables);
}
else {
throw new AcsfException(dt('@name not found.', [
'@name' => $name,
]));
}
}