annotate vendor/symfony/dependency-injection/DefinitionDecorator.php @ 2:92f882872392

Trusted hosts, + remove migration modules
author Chris Cannam
date Tue, 05 Dec 2017 09:26:43 +0000
parents 4c8ae668cc8c
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\DependencyInjection;
Chris@0 13
Chris@0 14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Chris@0 15 use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
Chris@0 16
Chris@0 17 /**
Chris@0 18 * This definition decorates another definition.
Chris@0 19 *
Chris@0 20 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
Chris@0 21 */
Chris@0 22 class DefinitionDecorator extends Definition
Chris@0 23 {
Chris@0 24 private $parent;
Chris@0 25 private $changes = array();
Chris@0 26
Chris@0 27 /**
Chris@0 28 * @param string $parent The id of Definition instance to decorate
Chris@0 29 */
Chris@0 30 public function __construct($parent)
Chris@0 31 {
Chris@0 32 parent::__construct();
Chris@0 33
Chris@0 34 $this->parent = $parent;
Chris@0 35 }
Chris@0 36
Chris@0 37 /**
Chris@0 38 * Returns the Definition being decorated.
Chris@0 39 *
Chris@0 40 * @return string
Chris@0 41 */
Chris@0 42 public function getParent()
Chris@0 43 {
Chris@0 44 return $this->parent;
Chris@0 45 }
Chris@0 46
Chris@0 47 /**
Chris@0 48 * Returns all changes tracked for the Definition object.
Chris@0 49 *
Chris@0 50 * @return array An array of changes for this Definition
Chris@0 51 */
Chris@0 52 public function getChanges()
Chris@0 53 {
Chris@0 54 return $this->changes;
Chris@0 55 }
Chris@0 56
Chris@0 57 /**
Chris@0 58 * {@inheritdoc}
Chris@0 59 */
Chris@0 60 public function setClass($class)
Chris@0 61 {
Chris@0 62 $this->changes['class'] = true;
Chris@0 63
Chris@0 64 return parent::setClass($class);
Chris@0 65 }
Chris@0 66
Chris@0 67 /**
Chris@0 68 * {@inheritdoc}
Chris@0 69 */
Chris@0 70 public function setFactory($callable)
Chris@0 71 {
Chris@0 72 $this->changes['factory'] = true;
Chris@0 73
Chris@0 74 return parent::setFactory($callable);
Chris@0 75 }
Chris@0 76
Chris@0 77 /**
Chris@0 78 * {@inheritdoc}
Chris@0 79 */
Chris@0 80 public function setConfigurator($callable)
Chris@0 81 {
Chris@0 82 $this->changes['configurator'] = true;
Chris@0 83
Chris@0 84 return parent::setConfigurator($callable);
Chris@0 85 }
Chris@0 86
Chris@0 87 /**
Chris@0 88 * {@inheritdoc}
Chris@0 89 */
Chris@0 90 public function setFile($file)
Chris@0 91 {
Chris@0 92 $this->changes['file'] = true;
Chris@0 93
Chris@0 94 return parent::setFile($file);
Chris@0 95 }
Chris@0 96
Chris@0 97 /**
Chris@0 98 * {@inheritdoc}
Chris@0 99 */
Chris@0 100 public function setPublic($boolean)
Chris@0 101 {
Chris@0 102 $this->changes['public'] = true;
Chris@0 103
Chris@0 104 return parent::setPublic($boolean);
Chris@0 105 }
Chris@0 106
Chris@0 107 /**
Chris@0 108 * {@inheritdoc}
Chris@0 109 */
Chris@0 110 public function setLazy($boolean)
Chris@0 111 {
Chris@0 112 $this->changes['lazy'] = true;
Chris@0 113
Chris@0 114 return parent::setLazy($boolean);
Chris@0 115 }
Chris@0 116
Chris@0 117 /**
Chris@0 118 * {@inheritdoc}
Chris@0 119 */
Chris@0 120 public function setDecoratedService($id, $renamedId = null, $priority = 0)
Chris@0 121 {
Chris@0 122 $this->changes['decorated_service'] = true;
Chris@0 123
Chris@0 124 return parent::setDecoratedService($id, $renamedId, $priority);
Chris@0 125 }
Chris@0 126
Chris@0 127 /**
Chris@0 128 * {@inheritdoc}
Chris@0 129 */
Chris@0 130 public function setDeprecated($boolean = true, $template = null)
Chris@0 131 {
Chris@0 132 $this->changes['deprecated'] = true;
Chris@0 133
Chris@0 134 return parent::setDeprecated($boolean, $template);
Chris@0 135 }
Chris@0 136
Chris@0 137 /**
Chris@0 138 * {@inheritdoc}
Chris@0 139 */
Chris@0 140 public function setAutowired($autowired)
Chris@0 141 {
Chris@0 142 $this->changes['autowire'] = true;
Chris@0 143
Chris@0 144 return parent::setAutowired($autowired);
Chris@0 145 }
Chris@0 146
Chris@0 147 /**
Chris@0 148 * Gets an argument to pass to the service constructor/factory method.
Chris@0 149 *
Chris@0 150 * If replaceArgument() has been used to replace an argument, this method
Chris@0 151 * will return the replacement value.
Chris@0 152 *
Chris@0 153 * @param int $index
Chris@0 154 *
Chris@0 155 * @return mixed The argument value
Chris@0 156 *
Chris@0 157 * @throws OutOfBoundsException When the argument does not exist
Chris@0 158 */
Chris@0 159 public function getArgument($index)
Chris@0 160 {
Chris@0 161 if (array_key_exists('index_'.$index, $this->arguments)) {
Chris@0 162 return $this->arguments['index_'.$index];
Chris@0 163 }
Chris@0 164
Chris@0 165 $lastIndex = count(array_filter(array_keys($this->arguments), 'is_int')) - 1;
Chris@0 166
Chris@0 167 if ($index < 0 || $index > $lastIndex) {
Chris@0 168 throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, $lastIndex));
Chris@0 169 }
Chris@0 170
Chris@0 171 return $this->arguments[$index];
Chris@0 172 }
Chris@0 173
Chris@0 174 /**
Chris@0 175 * You should always use this method when overwriting existing arguments
Chris@0 176 * of the parent definition.
Chris@0 177 *
Chris@0 178 * If you directly call setArguments() keep in mind that you must follow
Chris@0 179 * certain conventions when you want to overwrite the arguments of the
Chris@0 180 * parent definition, otherwise your arguments will only be appended.
Chris@0 181 *
Chris@0 182 * @param int $index
Chris@0 183 * @param mixed $value
Chris@0 184 *
Chris@0 185 * @return $this
Chris@0 186 *
Chris@0 187 * @throws InvalidArgumentException when $index isn't an integer
Chris@0 188 */
Chris@0 189 public function replaceArgument($index, $value)
Chris@0 190 {
Chris@0 191 if (!is_int($index)) {
Chris@0 192 throw new InvalidArgumentException('$index must be an integer.');
Chris@0 193 }
Chris@0 194
Chris@0 195 $this->arguments['index_'.$index] = $value;
Chris@0 196
Chris@0 197 return $this;
Chris@0 198 }
Chris@0 199 }