Created
February 3, 2013 21:02
-
-
Save EclipseGc/4703642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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