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;
|
2011-12-04 23:51:22 +00:00
|
|
|
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>
|
|
|
|
*/
|
2017-01-31 12:10:56 +00:00
|
|
|
class CheckReferenceValidityPass extends AbstractRecursivePass
|
2011-01-26 23:14:31 +00:00
|
|
|
{
|
2017-01-17 20:04:53 +00:00
|
|
|
protected function processValue($value, $isRoot = false)
|
2011-01-26 23:14:31 +00:00
|
|
|
{
|
2017-01-17 20:04:53 +00:00
|
|
|
if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {
|
|
|
|
return $value;
|
2011-01-26 23:14:31 +00:00
|
|
|
}
|
2017-01-17 20:04:53 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 20:04:53 +00:00
|
|
|
return parent::processValue($value, $isRoot);
|
2011-01-26 23:14:31 +00:00
|
|
|
}
|
|
|
|
}
|