7ffedd3dc0523d53ad01a18fcb2e94d56736e2a9
[yaffs-website] / vendor / symfony / dependency-injection / Compiler / CheckExceptionOnInvalidReferenceBehaviorPass.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Compiler;
13
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;
18
19 /**
20  * Checks that all references are pointing to a valid service.
21  *
22  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
23  */
24 class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
25 {
26     protected function processValue($value, $isRoot = false)
27     {
28         if (!$value instanceof Reference) {
29             return parent::processValue($value, $isRoot);
30         }
31         if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
32             throw new ServiceNotFoundException($id, $this->currentId);
33         }
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));
36         }
37
38         return $value;
39     }
40 }