Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.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 | 129ea1e6d783 |
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\Loader\Configurator; | |
13 | |
14 use Symfony\Component\DependencyInjection\Argument\IteratorArgument; | |
15 use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; | |
16 use Symfony\Component\DependencyInjection\ContainerBuilder; | |
17 use Symfony\Component\DependencyInjection\Definition; | |
18 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | |
19 use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; | |
20 use Symfony\Component\ExpressionLanguage\Expression; | |
21 | |
22 /** | |
23 * @author Nicolas Grekas <p@tchwork.com> | |
24 */ | |
25 class ContainerConfigurator extends AbstractConfigurator | |
26 { | |
27 const FACTORY = 'container'; | |
28 | |
29 private $container; | |
30 private $loader; | |
31 private $instanceof; | |
32 private $path; | |
33 private $file; | |
34 | |
35 public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, $path, $file) | |
36 { | |
37 $this->container = $container; | |
38 $this->loader = $loader; | |
39 $this->instanceof = &$instanceof; | |
40 $this->path = $path; | |
41 $this->file = $file; | |
42 } | |
43 | |
44 final public function extension($namespace, array $config) | |
45 { | |
46 if (!$this->container->hasExtension($namespace)) { | |
47 $extensions = array_filter(array_map(function ($ext) { return $ext->getAlias(); }, $this->container->getExtensions())); | |
48 throw new InvalidArgumentException(sprintf( | |
49 'There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s', | |
50 $namespace, | |
51 $this->file, | |
52 $namespace, | |
53 $extensions ? sprintf('"%s"', implode('", "', $extensions)) : 'none' | |
54 )); | |
55 } | |
56 | |
57 $this->container->loadFromExtension($namespace, static::processValue($config)); | |
58 } | |
59 | |
60 final public function import($resource, $type = null, $ignoreErrors = false) | |
61 { | |
62 $this->loader->setCurrentDir(dirname($this->path)); | |
63 $this->loader->import($resource, $type, $ignoreErrors, $this->file); | |
64 } | |
65 | |
66 /** | |
67 * @return ParametersConfigurator | |
68 */ | |
69 final public function parameters() | |
70 { | |
71 return new ParametersConfigurator($this->container); | |
72 } | |
73 | |
74 /** | |
75 * @return ServicesConfigurator | |
76 */ | |
77 final public function services() | |
78 { | |
79 return new ServicesConfigurator($this->container, $this->loader, $this->instanceof); | |
80 } | |
81 } | |
82 | |
83 /** | |
84 * Creates a service reference. | |
85 * | |
86 * @param string $id | |
87 * | |
88 * @return ReferenceConfigurator | |
89 */ | |
90 function ref($id) | |
91 { | |
92 return new ReferenceConfigurator($id); | |
93 } | |
94 | |
95 /** | |
96 * Creates an inline service. | |
97 * | |
98 * @param string|null $class | |
99 * | |
100 * @return InlineServiceConfigurator | |
101 */ | |
102 function inline($class = null) | |
103 { | |
104 return new InlineServiceConfigurator(new Definition($class)); | |
105 } | |
106 | |
107 /** | |
108 * Creates a lazy iterator. | |
109 * | |
110 * @param ReferenceConfigurator[] $values | |
111 * | |
112 * @return IteratorArgument | |
113 */ | |
114 function iterator(array $values) | |
115 { | |
116 return new IteratorArgument(AbstractConfigurator::processValue($values, true)); | |
117 } | |
118 | |
119 /** | |
120 * Creates a lazy iterator by tag name. | |
121 * | |
122 * @param string $tag | |
123 * | |
124 * @return TaggedIteratorArgument | |
125 */ | |
126 function tagged($tag) | |
127 { | |
128 return new TaggedIteratorArgument($tag); | |
129 } | |
130 | |
131 /** | |
132 * Creates an expression. | |
133 * | |
134 * @param string $expression an expression | |
135 * | |
136 * @return Expression | |
137 */ | |
138 function expr($expression) | |
139 { | |
140 return new Expression($expression); | |
141 } |