Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection; Chris@0: Chris@0: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@0: use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; Chris@0: Chris@0: /** Chris@0: * This definition decorates another definition. Chris@0: * Chris@0: * @author Johannes M. Schmitt Chris@0: */ Chris@0: class DefinitionDecorator extends Definition Chris@0: { Chris@0: private $parent; Chris@0: private $changes = array(); Chris@0: Chris@0: /** Chris@0: * @param string $parent The id of Definition instance to decorate Chris@0: */ Chris@0: public function __construct($parent) Chris@0: { Chris@0: parent::__construct(); Chris@0: Chris@0: $this->parent = $parent; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the Definition being decorated. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getParent() Chris@0: { Chris@0: return $this->parent; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns all changes tracked for the Definition object. Chris@0: * Chris@0: * @return array An array of changes for this Definition Chris@0: */ Chris@0: public function getChanges() Chris@0: { Chris@0: return $this->changes; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setClass($class) Chris@0: { Chris@0: $this->changes['class'] = true; Chris@0: Chris@0: return parent::setClass($class); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setFactory($callable) Chris@0: { Chris@0: $this->changes['factory'] = true; Chris@0: Chris@0: return parent::setFactory($callable); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setConfigurator($callable) Chris@0: { Chris@0: $this->changes['configurator'] = true; Chris@0: Chris@0: return parent::setConfigurator($callable); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setFile($file) Chris@0: { Chris@0: $this->changes['file'] = true; Chris@0: Chris@0: return parent::setFile($file); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setPublic($boolean) Chris@0: { Chris@0: $this->changes['public'] = true; Chris@0: Chris@0: return parent::setPublic($boolean); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setLazy($boolean) Chris@0: { Chris@0: $this->changes['lazy'] = true; Chris@0: Chris@0: return parent::setLazy($boolean); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setDecoratedService($id, $renamedId = null, $priority = 0) Chris@0: { Chris@0: $this->changes['decorated_service'] = true; Chris@0: Chris@0: return parent::setDecoratedService($id, $renamedId, $priority); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setDeprecated($boolean = true, $template = null) Chris@0: { Chris@0: $this->changes['deprecated'] = true; Chris@0: Chris@0: return parent::setDeprecated($boolean, $template); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setAutowired($autowired) Chris@0: { Chris@0: $this->changes['autowire'] = true; Chris@0: Chris@0: return parent::setAutowired($autowired); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets an argument to pass to the service constructor/factory method. Chris@0: * Chris@0: * If replaceArgument() has been used to replace an argument, this method Chris@0: * will return the replacement value. Chris@0: * Chris@0: * @param int $index Chris@0: * Chris@0: * @return mixed The argument value Chris@0: * Chris@0: * @throws OutOfBoundsException When the argument does not exist Chris@0: */ Chris@0: public function getArgument($index) Chris@0: { Chris@0: if (array_key_exists('index_'.$index, $this->arguments)) { Chris@0: return $this->arguments['index_'.$index]; Chris@0: } Chris@0: Chris@0: $lastIndex = count(array_filter(array_keys($this->arguments), 'is_int')) - 1; Chris@0: Chris@0: if ($index < 0 || $index > $lastIndex) { Chris@0: throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, $lastIndex)); Chris@0: } Chris@0: Chris@0: return $this->arguments[$index]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * You should always use this method when overwriting existing arguments Chris@0: * of the parent definition. Chris@0: * Chris@0: * If you directly call setArguments() keep in mind that you must follow Chris@0: * certain conventions when you want to overwrite the arguments of the Chris@0: * parent definition, otherwise your arguments will only be appended. Chris@0: * Chris@0: * @param int $index Chris@0: * @param mixed $value Chris@0: * Chris@0: * @return $this Chris@0: * Chris@0: * @throws InvalidArgumentException when $index isn't an integer Chris@0: */ Chris@0: public function replaceArgument($index, $value) Chris@0: { Chris@0: if (!is_int($index)) { Chris@0: throw new InvalidArgumentException('$index must be an integer.'); Chris@0: } Chris@0: Chris@0: $this->arguments['index_'.$index] = $value; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: }