Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\DependencyInjection\Compiler;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\DependencyInjection\Definition;
|
Chris@0
|
15 use Symfony\Component\DependencyInjection\Reference;
|
Chris@0
|
16 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Checks the validity of references.
|
Chris@0
|
20 *
|
Chris@0
|
21 * The following checks are performed by this pass:
|
Chris@0
|
22 * - target definitions are not abstract
|
Chris@0
|
23 *
|
Chris@0
|
24 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
Chris@0
|
25 */
|
Chris@14
|
26 class CheckReferenceValidityPass extends AbstractRecursivePass
|
Chris@0
|
27 {
|
Chris@14
|
28 protected function processValue($value, $isRoot = false)
|
Chris@14
|
29 {
|
Chris@14
|
30 if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {
|
Chris@14
|
31 return $value;
|
Chris@14
|
32 }
|
Chris@14
|
33 if ($value instanceof Reference && $this->container->hasDefinition((string) $value)) {
|
Chris@14
|
34 $targetDefinition = $this->container->getDefinition((string) $value);
|
Chris@0
|
35
|
Chris@14
|
36 if ($targetDefinition->isAbstract()) {
|
Chris@14
|
37 throw new RuntimeException(sprintf(
|
Chris@14
|
38 'The definition "%s" has a reference to an abstract definition "%s". '
|
Chris@14
|
39 .'Abstract definitions cannot be the target of references.',
|
Chris@14
|
40 $this->currentId,
|
Chris@14
|
41 $value
|
Chris@14
|
42 ));
|
Chris@0
|
43 }
|
Chris@0
|
44 }
|
Chris@0
|
45
|
Chris@14
|
46 return parent::processValue($value, $isRoot);
|
Chris@0
|
47 }
|
Chris@0
|
48 }
|