ResolveEnvPlaceholdersPass.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\Definition;
  12. /**
  13. * Replaces env var placeholders by their current values.
  14. */
  15. class ResolveEnvPlaceholdersPass extends AbstractRecursivePass
  16. {
  17. protected function processValue($value, bool $isRoot = false)
  18. {
  19. if (\is_string($value)) {
  20. return $this->container->resolveEnvPlaceholders($value, true);
  21. }
  22. if ($value instanceof Definition) {
  23. $changes = $value->getChanges();
  24. if (isset($changes['class'])) {
  25. $value->setClass($this->container->resolveEnvPlaceholders($value->getClass(), true));
  26. }
  27. if (isset($changes['file'])) {
  28. $value->setFile($this->container->resolveEnvPlaceholders($value->getFile(), true));
  29. }
  30. }
  31. $value = parent::processValue($value, $isRoot);
  32. if ($value && \is_array($value) && !$isRoot) {
  33. $value = array_combine($this->container->resolveEnvPlaceholders(array_keys($value), true), $value);
  34. }
  35. return $value;
  36. }
  37. }