Drupal investigation

MergeExtensionConfigurationPass.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
  13. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  14. /**
  15. * Merges extension configs into the container builder.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class MergeExtensionConfigurationPass implements CompilerPassInterface
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function process(ContainerBuilder $container)
  25. {
  26. $parameters = $container->getParameterBag()->all();
  27. $definitions = $container->getDefinitions();
  28. $aliases = $container->getAliases();
  29. $exprLangProviders = $container->getExpressionLanguageProviders();
  30. foreach ($container->getExtensions() as $extension) {
  31. if ($extension instanceof PrependExtensionInterface) {
  32. $extension->prepend($container);
  33. }
  34. }
  35. foreach ($container->getExtensions() as $name => $extension) {
  36. if (!$config = $container->getExtensionConfig($name)) {
  37. // this extension was not called
  38. continue;
  39. }
  40. $config = $container->getParameterBag()->resolveValue($config);
  41. $tmpContainer = new ContainerBuilder($container->getParameterBag());
  42. $tmpContainer->setResourceTracking($container->isTrackingResources());
  43. $tmpContainer->addObjectResource($extension);
  44. if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
  45. $tmpContainer->addObjectResource($configuration);
  46. }
  47. foreach ($exprLangProviders as $provider) {
  48. $tmpContainer->addExpressionLanguageProvider($provider);
  49. }
  50. $extension->load($config, $tmpContainer);
  51. $container->merge($tmpContainer);
  52. $container->getParameterBag()->add($parameters);
  53. }
  54. $container->addDefinitions($definitions);
  55. $container->addAliases($aliases);
  56. }
  57. }