annotate vendor/symfony/dependency-injection/Loader/Configurator/AbstractConfigurator.php @ 19:fa3358dc1485 tip

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