Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection; Chris@14: Chris@14: use Symfony\Component\DependencyInjection\Exception\BadMethodCallException; Chris@14: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@14: use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; Chris@14: Chris@14: /** Chris@14: * This definition extends another definition. Chris@14: * Chris@14: * @author Johannes M. Schmitt Chris@14: */ Chris@14: class ChildDefinition extends Definition Chris@14: { Chris@14: private $parent; Chris@14: Chris@14: /** Chris@14: * @param string $parent The id of Definition instance to decorate Chris@14: */ Chris@14: public function __construct($parent) Chris@14: { Chris@14: $this->parent = $parent; Chris@14: $this->setPrivate(false); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the Definition to inherit from. Chris@14: * Chris@14: * @return string Chris@14: */ Chris@14: public function getParent() Chris@14: { Chris@14: return $this->parent; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Sets the Definition to inherit from. Chris@14: * Chris@14: * @param string $parent Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setParent($parent) Chris@14: { Chris@14: $this->parent = $parent; Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Gets an argument to pass to the service constructor/factory method. Chris@14: * Chris@14: * If replaceArgument() has been used to replace an argument, this method Chris@14: * will return the replacement value. Chris@14: * Chris@14: * @param int|string $index Chris@14: * Chris@14: * @return mixed The argument value Chris@14: * Chris@14: * @throws OutOfBoundsException When the argument does not exist Chris@14: */ Chris@14: public function getArgument($index) Chris@14: { Chris@18: if (\array_key_exists('index_'.$index, $this->arguments)) { Chris@14: return $this->arguments['index_'.$index]; Chris@14: } Chris@14: Chris@14: return parent::getArgument($index); Chris@14: } Chris@14: Chris@14: /** Chris@14: * You should always use this method when overwriting existing arguments Chris@14: * of the parent definition. Chris@14: * Chris@14: * If you directly call setArguments() keep in mind that you must follow Chris@14: * certain conventions when you want to overwrite the arguments of the Chris@14: * parent definition, otherwise your arguments will only be appended. Chris@14: * Chris@14: * @param int|string $index Chris@14: * @param mixed $value Chris@14: * Chris@14: * @return self the current instance Chris@14: * Chris@14: * @throws InvalidArgumentException when $index isn't an integer Chris@14: */ Chris@14: public function replaceArgument($index, $value) Chris@14: { Chris@17: if (\is_int($index)) { Chris@14: $this->arguments['index_'.$index] = $value; Chris@14: } elseif (0 === strpos($index, '$')) { Chris@14: $this->arguments[$index] = $value; Chris@14: } else { Chris@14: throw new InvalidArgumentException('The argument must be an existing index or the name of a constructor\'s parameter.'); Chris@14: } Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @internal Chris@14: */ Chris@14: public function setAutoconfigured($autoconfigured) Chris@14: { Chris@14: throw new BadMethodCallException('A ChildDefinition cannot be autoconfigured.'); Chris@14: } Chris@14: Chris@14: /** Chris@14: * @internal Chris@14: */ Chris@14: public function setInstanceofConditionals(array $instanceof) Chris@14: { Chris@14: throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.'); Chris@14: } Chris@14: } Chris@14: Chris@14: class_alias(ChildDefinition::class, DefinitionDecorator::class);