protected function ReflectionFactory::getInstanceArguments in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Component/Plugin/Factory/ReflectionFactory.php \Drupal\Component\Plugin\Factory\ReflectionFactory::getInstanceArguments()
Inspects the plugin class and build a list of arguments for the constructor.
This is provided as a helper method so factories extending this class can replace this and insert their own reflection logic.
Parameters
\ReflectionClass $reflector: The reflector object being used to inspect the plugin class.
string $plugin_id: The identifier of the plugin implementation.
mixed $plugin_definition: The definition associated with the plugin_id.
array $configuration: An array of configuration that may be passed to the instance.
Return value
array An array of arguments to be passed to the constructor.
1 call to ReflectionFactory::getInstanceArguments()
- ReflectionFactory::createInstance in core/
lib/ Drupal/ Component/ Plugin/ Factory/ ReflectionFactory.php - Creates a pre-configured instance of a plugin.
File
- core/
lib/ Drupal/ Component/ Plugin/ Factory/ ReflectionFactory.php, line 56 - Contains \Drupal\Component\Plugin\Factory\ReflectionFactory.
Class
- ReflectionFactory
- A plugin factory that maps instance configuration to constructor arguments.
Namespace
Drupal\Component\Plugin\FactoryCode
protected function getInstanceArguments(\ReflectionClass $reflector, $plugin_id, $plugin_definition, array $configuration) {
$arguments = array();
foreach ($reflector
->getMethod('__construct')
->getParameters() as $param) {
$param_name = $param
->getName();
if ($param_name == 'plugin_id') {
$arguments[] = $plugin_id;
}
elseif ($param_name == 'plugin_definition') {
$arguments[] = $plugin_definition;
}
elseif ($param_name == 'configuration') {
$arguments[] = $configuration;
}
elseif (isset($configuration[$param_name]) || array_key_exists($param_name, $configuration)) {
$arguments[] = $configuration[$param_name];
}
elseif ($param
->isDefaultValueAvailable()) {
$arguments[] = $param
->getDefaultValue();
}
else {
$arguments[] = NULL;
}
}
return $arguments;
}