2017-05-08 01:40:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Throws autowire exceptions from AutowirePass for definitions that still exist.
|
|
|
|
*
|
|
|
|
* @author Ryan Weaver <ryan@knpuniversity.com>
|
|
|
|
*/
|
|
|
|
class AutowireExceptionPass implements CompilerPassInterface
|
|
|
|
{
|
|
|
|
private $autowirePass;
|
2017-05-22 15:33:24 +01:00
|
|
|
private $inlineServicePass;
|
2017-05-08 01:40:35 +01:00
|
|
|
|
2017-05-22 15:33:24 +01:00
|
|
|
public function __construct(AutowirePass $autowirePass, InlineServiceDefinitionsPass $inlineServicePass)
|
2017-05-08 01:40:35 +01:00
|
|
|
{
|
|
|
|
$this->autowirePass = $autowirePass;
|
2017-05-22 15:33:24 +01:00
|
|
|
$this->inlineServicePass = $inlineServicePass;
|
2017-05-08 01:40:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function process(ContainerBuilder $container)
|
|
|
|
{
|
2017-05-22 15:33:24 +01:00
|
|
|
// the pass should only be run once
|
|
|
|
if (null === $this->autowirePass || null === $this->inlineServicePass) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$inlinedIds = $this->inlineServicePass->getInlinedServiceIds();
|
|
|
|
$exceptions = $this->autowirePass->getAutowiringExceptions();
|
|
|
|
|
|
|
|
// free up references
|
|
|
|
$this->autowirePass = null;
|
|
|
|
$this->inlineServicePass = null;
|
|
|
|
|
|
|
|
foreach ($exceptions as $exception) {
|
2017-05-31 15:32:39 +01:00
|
|
|
if ($this->doesServiceExistInTheContainer($exception->getServiceId(), $container, $inlinedIds)) {
|
2017-05-08 01:40:35 +01:00
|
|
|
throw $exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 15:32:39 +01:00
|
|
|
|
|
|
|
private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $container, array $inlinedIds)
|
|
|
|
{
|
|
|
|
if ($container->hasDefinition($serviceId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// was the service inlined? Of so, does its parent service exist?
|
|
|
|
if (isset($inlinedIds[$serviceId])) {
|
2017-06-01 07:27:51 +01:00
|
|
|
foreach ($inlinedIds[$serviceId] as $parentId) {
|
|
|
|
if ($this->doesServiceExistInTheContainer($parentId, $container, $inlinedIds)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 15:32:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-08 01:40:35 +01:00
|
|
|
}
|