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\Definition;
15 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
16 use Symfony\Component\DependencyInjection\Reference;
19 * Checks the validity of references.
21 * The following checks are performed by this pass:
22 * - target definitions are not abstract
24 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
26 class CheckReferenceValidityPass extends AbstractRecursivePass
28 protected function processValue($value, $isRoot = false)
30 if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {
33 if ($value instanceof Reference && $this->container->hasDefinition((string) $value)) {
34 $targetDefinition = $this->container->getDefinition((string) $value);
36 if ($targetDefinition->isAbstract()) {
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));
41 return parent::processValue($value, $isRoot);