4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Compiler;
14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
15 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
17 use Symfony\Component\DependencyInjection\Reference;
20 * Checks that all references are pointing to a valid service.
22 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
24 class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
26 protected function processValue($value, $isRoot = false)
28 if (!$value instanceof Reference) {
29 return parent::processValue($value, $isRoot);
31 if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
32 throw new ServiceNotFoundException($id, $this->currentId);
34 if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior() && $this->container->has($id = (string) $value) && !$this->container->findDefinition($id)->isShared()) {
35 throw new InvalidArgumentException(sprintf('Invalid ignore-on-uninitialized reference found in service "%s": target service "%s" is not shared.', $this->currentId, $id));