annotate vendor/symfony/dependency-injection/Compiler/CheckReferenceValidityPass.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
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@17 15 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
Chris@0 16 use Symfony\Component\DependencyInjection\Reference;
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@17 37 throw new RuntimeException(sprintf('The definition "%s" has a reference to an abstract definition "%s". Abstract definitions cannot be the target of references.', $this->currentId, $value));
Chris@0 38 }
Chris@0 39 }
Chris@0 40
Chris@14 41 return parent::processValue($value, $isRoot);
Chris@0 42 }
Chris@0 43 }