Drupal investigation

ResolveParameterPlaceHoldersPass.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Exception\ParameterNotFoundException;
  13. /**
  14. * Resolves all parameter placeholders "%somevalue%" to their real values.
  15. *
  16. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  17. */
  18. class ResolveParameterPlaceHoldersPass implements CompilerPassInterface
  19. {
  20. /**
  21. * Processes the ContainerBuilder to resolve parameter placeholders.
  22. *
  23. * @param ContainerBuilder $container
  24. *
  25. * @throws ParameterNotFoundException
  26. */
  27. public function process(ContainerBuilder $container)
  28. {
  29. $parameterBag = $container->getParameterBag();
  30. foreach ($container->getDefinitions() as $id => $definition) {
  31. try {
  32. $definition->setClass($parameterBag->resolveValue($definition->getClass()));
  33. $definition->setFile($parameterBag->resolveValue($definition->getFile()));
  34. $definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
  35. if ($definition->getFactoryClass(false)) {
  36. $definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass(false)));
  37. }
  38. $factory = $definition->getFactory();
  39. if (is_array($factory) && isset($factory[0])) {
  40. $factory[0] = $parameterBag->resolveValue($factory[0]);
  41. $definition->setFactory($factory);
  42. }
  43. $calls = array();
  44. foreach ($definition->getMethodCalls() as $name => $arguments) {
  45. $calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
  46. }
  47. $definition->setMethodCalls($calls);
  48. $definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
  49. } catch (ParameterNotFoundException $e) {
  50. $e->setSourceId($id);
  51. throw $e;
  52. }
  53. }
  54. $aliases = array();
  55. foreach ($container->getAliases() as $name => $target) {
  56. $aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
  57. }
  58. $container->setAliases($aliases);
  59. $parameterBag->resolve();
  60. }
  61. }