annotate vendor/symfony/dependency-injection/ChildDefinition.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
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\BadMethodCallException;
Chris@0 15 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Chris@0 16 use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
Chris@0 17
Chris@0 18 /**
Chris@0 19 * This definition extends another definition.
Chris@0 20 *
Chris@0 21 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
Chris@0 22 */
Chris@0 23 class ChildDefinition extends Definition
Chris@0 24 {
Chris@0 25 private $parent;
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 $this->parent = $parent;
Chris@0 33 $this->setPrivate(false);
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * Returns the Definition to inherit from.
Chris@0 38 *
Chris@0 39 * @return string
Chris@0 40 */
Chris@0 41 public function getParent()
Chris@0 42 {
Chris@0 43 return $this->parent;
Chris@0 44 }
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Sets the Definition to inherit from.
Chris@0 48 *
Chris@0 49 * @param string $parent
Chris@0 50 *
Chris@0 51 * @return $this
Chris@0 52 */
Chris@0 53 public function setParent($parent)
Chris@0 54 {
Chris@0 55 $this->parent = $parent;
Chris@0 56
Chris@0 57 return $this;
Chris@0 58 }
Chris@0 59
Chris@0 60 /**
Chris@0 61 * Gets an argument to pass to the service constructor/factory method.
Chris@0 62 *
Chris@0 63 * If replaceArgument() has been used to replace an argument, this method
Chris@0 64 * will return the replacement value.
Chris@0 65 *
Chris@0 66 * @param int|string $index
Chris@0 67 *
Chris@0 68 * @return mixed The argument value
Chris@0 69 *
Chris@0 70 * @throws OutOfBoundsException When the argument does not exist
Chris@0 71 */
Chris@0 72 public function getArgument($index)
Chris@0 73 {
Chris@5 74 if (\array_key_exists('index_'.$index, $this->arguments)) {
Chris@0 75 return $this->arguments['index_'.$index];
Chris@0 76 }
Chris@0 77
Chris@0 78 return parent::getArgument($index);
Chris@0 79 }
Chris@0 80
Chris@0 81 /**
Chris@0 82 * You should always use this method when overwriting existing arguments
Chris@0 83 * of the parent definition.
Chris@0 84 *
Chris@0 85 * If you directly call setArguments() keep in mind that you must follow
Chris@0 86 * certain conventions when you want to overwrite the arguments of the
Chris@0 87 * parent definition, otherwise your arguments will only be appended.
Chris@0 88 *
Chris@0 89 * @param int|string $index
Chris@0 90 * @param mixed $value
Chris@0 91 *
Chris@0 92 * @return self the current instance
Chris@0 93 *
Chris@0 94 * @throws InvalidArgumentException when $index isn't an integer
Chris@0 95 */
Chris@0 96 public function replaceArgument($index, $value)
Chris@0 97 {
Chris@4 98 if (\is_int($index)) {
Chris@0 99 $this->arguments['index_'.$index] = $value;
Chris@0 100 } elseif (0 === strpos($index, '$')) {
Chris@0 101 $this->arguments[$index] = $value;
Chris@0 102 } else {
Chris@0 103 throw new InvalidArgumentException('The argument must be an existing index or the name of a constructor\'s parameter.');
Chris@0 104 }
Chris@0 105
Chris@0 106 return $this;
Chris@0 107 }
Chris@0 108
Chris@0 109 /**
Chris@0 110 * @internal
Chris@0 111 */
Chris@0 112 public function setAutoconfigured($autoconfigured)
Chris@0 113 {
Chris@0 114 throw new BadMethodCallException('A ChildDefinition cannot be autoconfigured.');
Chris@0 115 }
Chris@0 116
Chris@0 117 /**
Chris@0 118 * @internal
Chris@0 119 */
Chris@0 120 public function setInstanceofConditionals(array $instanceof)
Chris@0 121 {
Chris@0 122 throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.');
Chris@0 123 }
Chris@0 124 }
Chris@0 125
Chris@0 126 class_alias(ChildDefinition::class, DefinitionDecorator::class);