"Fossies" - the Fresh Open Source Software Archive 
Member "drupal-9.4.5/vendor/symfony/dependency-injection/Loader/Configurator/AbstractConfigurator.php" (20 Jul 2022, 3171 Bytes) of package /linux/www/drupal-9.4.5.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "AbstractConfigurator.php":
9.4.4_vs_9.4.5.
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 public 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 $this->{'set'.$method}(...$args);
32 }
33
34 throw new \BadMethodCallException(sprintf('Call to undefined method "%s::%s()".', static::class, $method));
35 }
36
37 /**
38 * @return array
39 */
40 public function __sleep()
41 {
42 throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
43 }
44
45 public function __wakeup()
46 {
47 throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
48 }
49
50 /**
51 * Checks that a value is valid, optionally replacing Definition and Reference configurators by their configure value.
52 *
53 * @param mixed $value
54 * @param bool $allowServices whether Definition and Reference are allowed; by default, only scalars and arrays are
55 *
56 * @return mixed the value, optionally cast to a Definition/Reference
57 */
58 public static function processValue($value, $allowServices = false)
59 {
60 if (\is_array($value)) {
61 foreach ($value as $k => $v) {
62 $value[$k] = static::processValue($v, $allowServices);
63 }
64
65 return $value;
66 }
67
68 if ($value instanceof ReferenceConfigurator) {
69 return new Reference($value->id, $value->invalidBehavior);
70 }
71
72 if ($value instanceof InlineServiceConfigurator) {
73 $def = $value->definition;
74 $value->definition = null;
75
76 return $def;
77 }
78
79 if ($value instanceof self) {
80 throw new InvalidArgumentException(sprintf('"%s()" can be used only at the root of service configuration files.', $value::FACTORY));
81 }
82
83 switch (true) {
84 case null === $value:
85 case \is_scalar($value):
86 return $value;
87
88 case $value instanceof ArgumentInterface:
89 case $value instanceof Definition:
90 case $value instanceof Expression:
91 case $value instanceof Parameter:
92 case $value instanceof Reference:
93 if ($allowServices) {
94 return $value;
95 }
96 }
97
98 throw new InvalidArgumentException(sprintf('Cannot use values of type "%s" in service configuration files.', \is_object($value) ? \get_class($value) : \gettype($value)));
99 }
100 }