ResolveParameterPlaceHoldersPass.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. $calls = array();
  36. foreach ($definition->getMethodCalls() as $name => $arguments) {
  37. $calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
  38. }
  39. $definition->setMethodCalls($calls);
  40. $definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
  41. } catch (ParameterNotFoundException $e) {
  42. $e->setSourceId($id);
  43. throw $e;
  44. }
  45. }
  46. $aliases = array();
  47. foreach ($container->getAliases() as $name => $target) {
  48. $aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
  49. }
  50. $container->setAliases($aliases);
  51. $parameterBag->resolve();
  52. }
  53. }