4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Loader\Configurator;
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;
21 abstract class AbstractConfigurator
23 const FACTORY = 'unknown';
26 protected $definition;
28 public function __call($method, $args)
30 if (method_exists($this, 'set'.$method)) {
31 return \call_user_func_array(array($this, 'set'.$method), $args);
34 throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', \get_class($this), $method));
38 * Checks that a value is valid, optionally replacing Definition and Reference configurators by their configure value.
41 * @param bool $allowServices whether Definition and Reference are allowed; by default, only scalars and arrays are
43 * @return mixed the value, optionally cast to a Definition/Reference
45 public static function processValue($value, $allowServices = false)
47 if (\is_array($value)) {
48 foreach ($value as $k => $v) {
49 $value[$k] = static::processValue($v, $allowServices);
55 if ($value instanceof ReferenceConfigurator) {
56 return new Reference($value->id, $value->invalidBehavior);
59 if ($value instanceof InlineServiceConfigurator) {
60 $def = $value->definition;
61 $value->definition = null;
66 if ($value instanceof self) {
67 throw new InvalidArgumentException(sprintf('"%s()" can be used only at the root of service configuration files.', $value::FACTORY));
72 case is_scalar($value):
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:
85 throw new InvalidArgumentException(sprintf('Cannot use values of type "%s" in service configuration files.', \is_object($value) ? \get_class($value) : \gettype($value)));