Chris@14
|
1 <?php
|
Chris@14
|
2
|
Chris@14
|
3 /*
|
Chris@14
|
4 * This file is part of the Symfony package.
|
Chris@14
|
5 *
|
Chris@14
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@14
|
7 *
|
Chris@14
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@14
|
9 * file that was distributed with this source code.
|
Chris@14
|
10 */
|
Chris@14
|
11
|
Chris@14
|
12 namespace Symfony\Component\DependencyInjection\Compiler;
|
Chris@14
|
13
|
Chris@14
|
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);
|
Chris@14
|
15
|
Chris@14
|
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
|
Chris@14
|
17
|
Chris@14
|
18 /**
|
Chris@14
|
19 * Throws autowire exceptions from AutowirePass for definitions that still exist.
|
Chris@14
|
20 *
|
Chris@14
|
21 * @deprecated since version 3.4, will be removed in 4.0.
|
Chris@14
|
22 *
|
Chris@14
|
23 * @author Ryan Weaver <ryan@knpuniversity.com>
|
Chris@14
|
24 */
|
Chris@14
|
25 class AutowireExceptionPass implements CompilerPassInterface
|
Chris@14
|
26 {
|
Chris@14
|
27 private $autowirePass;
|
Chris@14
|
28 private $inlineServicePass;
|
Chris@14
|
29
|
Chris@14
|
30 public function __construct(AutowirePass $autowirePass, InlineServiceDefinitionsPass $inlineServicePass)
|
Chris@14
|
31 {
|
Chris@14
|
32 $this->autowirePass = $autowirePass;
|
Chris@14
|
33 $this->inlineServicePass = $inlineServicePass;
|
Chris@14
|
34 }
|
Chris@14
|
35
|
Chris@14
|
36 public function process(ContainerBuilder $container)
|
Chris@14
|
37 {
|
Chris@14
|
38 // the pass should only be run once
|
Chris@14
|
39 if (null === $this->autowirePass || null === $this->inlineServicePass) {
|
Chris@14
|
40 return;
|
Chris@14
|
41 }
|
Chris@14
|
42
|
Chris@14
|
43 $inlinedIds = $this->inlineServicePass->getInlinedServiceIds();
|
Chris@14
|
44 $exceptions = $this->autowirePass->getAutowiringExceptions();
|
Chris@14
|
45
|
Chris@14
|
46 // free up references
|
Chris@14
|
47 $this->autowirePass = null;
|
Chris@14
|
48 $this->inlineServicePass = null;
|
Chris@14
|
49
|
Chris@14
|
50 foreach ($exceptions as $exception) {
|
Chris@14
|
51 if ($this->doesServiceExistInTheContainer($exception->getServiceId(), $container, $inlinedIds)) {
|
Chris@14
|
52 throw $exception;
|
Chris@14
|
53 }
|
Chris@14
|
54 }
|
Chris@14
|
55 }
|
Chris@14
|
56
|
Chris@14
|
57 private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $container, array $inlinedIds)
|
Chris@14
|
58 {
|
Chris@14
|
59 if ($container->hasDefinition($serviceId)) {
|
Chris@14
|
60 return true;
|
Chris@14
|
61 }
|
Chris@14
|
62
|
Chris@14
|
63 // was the service inlined? Of so, does its parent service exist?
|
Chris@14
|
64 if (isset($inlinedIds[$serviceId])) {
|
Chris@14
|
65 foreach ($inlinedIds[$serviceId] as $parentId) {
|
Chris@14
|
66 if ($this->doesServiceExistInTheContainer($parentId, $container, $inlinedIds)) {
|
Chris@14
|
67 return true;
|
Chris@14
|
68 }
|
Chris@14
|
69 }
|
Chris@14
|
70 }
|
Chris@14
|
71
|
Chris@14
|
72 return false;
|
Chris@14
|
73 }
|
Chris@14
|
74 }
|