This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php

49 lines
1.5 KiB
PHP
Raw Normal View History

2011-01-26 23:14:31 +00:00
<?php
2011-05-31 09:57:06 +01:00
/*
2012-03-31 22:00:32 +01:00
* This file is part of the Symfony package.
2011-05-31 09:57:06 +01:00
*
* (c) Fabien Potencier <fabien@symfony.com>
*
2012-03-31 22:00:32 +01:00
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2011-05-31 09:57:06 +01:00
*/
2011-01-26 23:14:31 +00:00
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2011-01-26 23:14:31 +00:00
/**
2014-12-21 17:00:50 +00:00
* Checks the validity of references.
2011-01-26 23:14:31 +00:00
*
* The following checks are performed by this pass:
* - target definitions are not abstract
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class CheckReferenceValidityPass extends AbstractRecursivePass
2011-01-26 23:14:31 +00:00
{
protected function processValue($value, $isRoot = false)
2011-01-26 23:14:31 +00:00
{
if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {
return $value;
2011-01-26 23:14:31 +00:00
}
if ($value instanceof Reference && $this->container->hasDefinition((string) $value)) {
$targetDefinition = $this->container->getDefinition((string) $value);
if ($targetDefinition->isAbstract()) {
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
));
2011-01-26 23:14:31 +00:00
}
}
return parent::processValue($value, $isRoot);
2011-01-26 23:14:31 +00:00
}
}