comparison vendor/symfony/dependency-injection/Compiler/AutowireExceptionPass.php @ 14:1fec387a4317

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