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.
ReflectionClass $reflector: The reflector object being used to inspect the plugin class.
string $plugin_id: The identifier of the plugin implementation.
array $configuration: An array of configuration that may be passed to the instance.
array An array of arguments to be passed to the constructor.
protected function getInstanceArguments(ReflectionClass $reflector, $plugin_id, array $configuration) {
$arguments = array();
foreach ($reflector
->getMethod('__construct')
->getParameters() as $param) {
$param_name = $param
->getName();
$param_class = $param
->getClass();
if ($param_name == 'plugin_id') {
$arguments[] = $plugin_id;
}
elseif ($param_name == 'configuration') {
$arguments[] = $configuration;
}
elseif ($param_class && $param_class
->isInstance($this->discovery)) {
$arguments[] = $this->discovery;
}
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;
}