use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ExceptionInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
+use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
/**
* This replaces all ChildDefinition instances with their equivalent fully
*/
class ResolveChildDefinitionsPass extends AbstractRecursivePass
{
+ private $currentPath;
+
protected function processValue($value, $isRoot = false)
{
if (!$value instanceof Definition) {
$value = $this->container->getDefinition($this->currentId);
}
if ($value instanceof ChildDefinition) {
+ $this->currentPath = array();
$value = $this->resolveDefinition($value);
if ($isRoot) {
$this->container->setDefinition($this->currentId, $value);
{
try {
return $this->doResolveDefinition($definition);
+ } catch (ServiceCircularReferenceException $e) {
+ throw $e;
} catch (ExceptionInterface $e) {
$r = new \ReflectionProperty($e, 'message');
$r->setAccessible(true);
throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent));
}
+ $searchKey = array_search($parent, $this->currentPath);
+ $this->currentPath[] = $parent;
+
+ if (false !== $searchKey) {
+ throw new ServiceCircularReferenceException($parent, \array_slice($this->currentPath, $searchKey));
+ }
+
$parentDef = $this->container->findDefinition($parent);
if ($parentDef instanceof ChildDefinition) {
$id = $this->currentId;
if (is_numeric($k)) {
$def->addArgument($v);
} elseif (0 === strpos($k, 'index_')) {
- $def->replaceArgument((int) substr($k, strlen('index_')), $v);
+ $def->replaceArgument((int) substr($k, \strlen('index_')), $v);
} else {
$def->setArgument($k, $v);
}