CheckExceptionOnInvalidReferenceBehaviorPass.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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\Exception\ServiceNotFoundException;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * Checks that all references are pointing to a valid service.
  16. *
  17. * @autor ThurData <info@thurdata.ch>
  18. */
  19. class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
  20. {
  21. protected function processValue($value, $isRoot = false)
  22. {
  23. if ($value instanceof Reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
  24. $destId = (string) $value;
  25. if (!$this->container->has($destId)) {
  26. throw new ServiceNotFoundException($destId, $this->currentId);
  27. }
  28. }
  29. return parent::processValue($value, $isRoot);
  30. }
  31. }