Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Created February 3, 2013 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EclipseGc/4703642 to your computer and use it in GitHub Desktop.
Save EclipseGc/4703642 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Definition of Drupal\Core\Plugin\Factory\ContainerFactory.
*/
namespace Drupal\Core\Plugin\Factory;
use Drupal\Component\Plugin\Factory\ReflectionFactory;
/**
* A plugin factory that fulfills missing dependencies from the
* drupal_container() and maps instance configuration to constructor arguments.
*/
class ContainerFactory extends ReflectionFactory {
/**
* Implements Drupal\Component\Plugin\Factory\FactoryInterface::createInstance().
*/
public function createInstance($plugin_id, array $configuration) {
$definition = $this->discovery->getDefinition($plugin_id);
$dependencies = !empty($definition['dependencies']) ? $definition['dependencies'] : array();
foreach ($dependencies as $dependency => $service_id) {
if (empty($configuration[$dependency])) {
$configuration[$dependency] = drupal_container()->get($service_id);
}
}
return parent::createInstance($plugin_id, $configuration);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment