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;
14 use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
15 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
16 use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
19 * This definition extends another definition.
21 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
23 class ChildDefinition extends Definition
28 * @param string $parent The id of Definition instance to decorate
30 public function __construct($parent)
32 $this->parent = $parent;
33 $this->setPrivate(false);
37 * Returns the Definition to inherit from.
41 public function getParent()
47 * Sets the Definition to inherit from.
49 * @param string $parent
53 public function setParent($parent)
55 $this->parent = $parent;
61 * Gets an argument to pass to the service constructor/factory method.
63 * If replaceArgument() has been used to replace an argument, this method
64 * will return the replacement value.
66 * @param int|string $index
68 * @return mixed The argument value
70 * @throws OutOfBoundsException When the argument does not exist
72 public function getArgument($index)
74 if (array_key_exists('index_'.$index, $this->arguments)) {
75 return $this->arguments['index_'.$index];
78 return parent::getArgument($index);
82 * You should always use this method when overwriting existing arguments
83 * of the parent definition.
85 * If you directly call setArguments() keep in mind that you must follow
86 * certain conventions when you want to overwrite the arguments of the
87 * parent definition, otherwise your arguments will only be appended.
89 * @param int|string $index
92 * @return self the current instance
94 * @throws InvalidArgumentException when $index isn't an integer
96 public function replaceArgument($index, $value)
99 $this->arguments['index_'.$index] = $value;
100 } elseif (0 === strpos($index, '$')) {
101 $this->arguments[$index] = $value;
103 throw new InvalidArgumentException('The argument must be an existing index or the name of a constructor\'s parameter.');
112 public function setAutoconfigured($autoconfigured)
114 throw new BadMethodCallException('A ChildDefinition cannot be autoconfigured.');
120 public function setInstanceofConditionals(array $instanceof)
122 throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.');
128 public function setBindings(array $bindings)
130 throw new BadMethodCallException('A ChildDefinition cannot have bindings set on it.');
134 class_alias(ChildDefinition::class, DefinitionDecorator::class);