protected function Spec::resolveArguments in Little helpers 7.2
Resolve all special arguments in the argument array.
1 call to Spec::resolveArguments()
- Spec::instantiate in src/
Services/ Spec.php - Create a new class instance based on the spec.
File
- src/
Services/ Spec.php, line 126
Class
- Spec
- A class instantiation spec.
Namespace
Drupal\little_helpers\ServicesCode
protected function resolveArguments(array $spec_args, array $kwargs) {
$resolvers = [
'@' => [
$this->container,
'loadService',
],
'%' => function ($key) use ($kwargs) {
if (!array_key_exists($key, $kwargs)) {
throw new MissingArgumentException("Argument %{$key} was referenced in the spec but was not passed in kwargs.");
}
return $kwargs[$key];
},
'!' => function ($key) {
return module_exists('variable') ? variable_get_value($key) : variable_get($key);
},
];
foreach ($spec_args as &$arg) {
if (is_string($arg) && $arg && ($resolver = $resolvers[$arg[0]] ?? NULL)) {
$name = substr($arg, 1);
$arg = $resolver($name);
}
}
return $spec_args;
}