protected function 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.

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()

File

drupal/core/lib/Drupal/Component/Plugin/Factory/ReflectionFactory.php, line 55
Definition of Drupal\Component\Plugin\Factory\ReflectionFactory.

Class

ReflectionFactory
A plugin factory that maps instance configuration to constructor arguments.

Namespace

Drupal\Component\Plugin\Factory

Code

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;
}