Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Loader/Configurator/AbstractConfigurator.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\ArgumentInterface; | |
15 use Symfony\Component\DependencyInjection\Definition; | |
16 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | |
17 use Symfony\Component\DependencyInjection\Parameter; | |
18 use Symfony\Component\DependencyInjection\Reference; | |
19 use Symfony\Component\ExpressionLanguage\Expression; | |
20 | |
21 abstract class AbstractConfigurator | |
22 { | |
23 const FACTORY = 'unknown'; | |
24 | |
25 /** @internal */ | |
26 protected $definition; | |
27 | |
28 public function __call($method, $args) | |
29 { | |
30 if (method_exists($this, 'set'.$method)) { | |
31 return call_user_func_array(array($this, 'set'.$method), $args); | |
32 } | |
33 | |
34 throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $method)); | |
35 } | |
36 | |
37 /** | |
38 * Checks that a value is valid, optionally replacing Definition and Reference configurators by their configure value. | |
39 * | |
40 * @param mixed $value | |
41 * @param bool $allowServices whether Definition and Reference are allowed; by default, only scalars and arrays are | |
42 * | |
43 * @return mixed the value, optionally cast to a Definition/Reference | |
44 */ | |
45 public static function processValue($value, $allowServices = false) | |
46 { | |
47 if (is_array($value)) { | |
48 foreach ($value as $k => $v) { | |
49 $value[$k] = static::processValue($v, $allowServices); | |
50 } | |
51 | |
52 return $value; | |
53 } | |
54 | |
55 if ($value instanceof ReferenceConfigurator) { | |
56 return new Reference($value->id, $value->invalidBehavior); | |
57 } | |
58 | |
59 if ($value instanceof InlineServiceConfigurator) { | |
60 $def = $value->definition; | |
61 $value->definition = null; | |
62 | |
63 return $def; | |
64 } | |
65 | |
66 if ($value instanceof self) { | |
67 throw new InvalidArgumentException(sprintf('"%s()" can be used only at the root of service configuration files.', $value::FACTORY)); | |
68 } | |
69 | |
70 switch (true) { | |
71 case null === $value: | |
72 case is_scalar($value): | |
73 return $value; | |
74 | |
75 case $value instanceof ArgumentInterface: | |
76 case $value instanceof Definition: | |
77 case $value instanceof Expression: | |
78 case $value instanceof Parameter: | |
79 case $value instanceof Reference: | |
80 if ($allowServices) { | |
81 return $value; | |
82 } | |
83 } | |
84 | |
85 throw new InvalidArgumentException(sprintf('Cannot use values of type "%s" in service configuration files.', is_object($value) ? get_class($value) : gettype($value))); | |
86 } | |
87 } |