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 @trigger_error('The '.__NAMESPACE__.'\AutowireExceptionPass class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the DefinitionErrorExceptionPass class instead.', E_USER_DEPRECATED);
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
19 * Throws autowire exceptions from AutowirePass for definitions that still exist.
21 * @deprecated since version 3.4, will be removed in 4.0.
23 * @author Ryan Weaver <ryan@knpuniversity.com>
25 class AutowireExceptionPass implements CompilerPassInterface
27 private $autowirePass;
28 private $inlineServicePass;
30 public function __construct(AutowirePass $autowirePass, InlineServiceDefinitionsPass $inlineServicePass)
32 $this->autowirePass = $autowirePass;
33 $this->inlineServicePass = $inlineServicePass;
36 public function process(ContainerBuilder $container)
38 // the pass should only be run once
39 if (null === $this->autowirePass || null === $this->inlineServicePass) {
43 $inlinedIds = $this->inlineServicePass->getInlinedServiceIds();
44 $exceptions = $this->autowirePass->getAutowiringExceptions();
47 $this->autowirePass = null;
48 $this->inlineServicePass = null;
50 foreach ($exceptions as $exception) {
51 if ($this->doesServiceExistInTheContainer($exception->getServiceId(), $container, $inlinedIds)) {
57 private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $container, array $inlinedIds)
59 if ($container->hasDefinition($serviceId)) {
63 // was the service inlined? Of so, does its parent service exist?
64 if (isset($inlinedIds[$serviceId])) {
65 foreach ($inlinedIds[$serviceId] as $parentId) {
66 if ($this->doesServiceExistInTheContainer($parentId, $container, $inlinedIds)) {