Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements FactoryInterface::getInstance().
- */
- public function getInstance($options) {
- $config = $this->getConfiguration($options);
- $plugin_class = $this->getPluginClass($config);
- // Lets figure out of there's a constructor for this class and pull
- // arguments from the $options array if so to populate it.
- $reflector = new ReflectionClass($plugin_class);
- if ($reflector->hasMethod('__construct')) {
- $params = $reflector->getMethod('__construct')->getParameters();
- $args = array();
- foreach ($params as $param) {
- $args[$param->name] = $options[$param->name];
- }
- $instance = $reflector->newInstanceArgs($args);
- }
- else {
- $instance = new $plugin_class();
- }
- if ($instance instanceof PluginDerivativeInterface && isset($options['derivative'])) {
- $instance->getDerivative($options['derivative']);
- }
- if ($instance instanceof PluginContextInterface) {
- // @TODO: Once the Symfony Request component is in, we can revisit this.
- /*$container = drupal_container();
- $instance->setContext($container['context']);*/
- }
- return $instance;
- }
Advertisement
Add Comment
Please, Sign In to add comment