comparison vendor/symfony/dependency-injection/Definition.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
26 private $file; 26 private $file;
27 private $factory; 27 private $factory;
28 private $shared = true; 28 private $shared = true;
29 private $deprecated = false; 29 private $deprecated = false;
30 private $deprecationTemplate; 30 private $deprecationTemplate;
31 private $properties = array(); 31 private $properties = [];
32 private $calls = array(); 32 private $calls = [];
33 private $instanceof = array(); 33 private $instanceof = [];
34 private $autoconfigured = false; 34 private $autoconfigured = false;
35 private $configurator; 35 private $configurator;
36 private $tags = array(); 36 private $tags = [];
37 private $public = true; 37 private $public = true;
38 private $private = true; 38 private $private = true;
39 private $synthetic = false; 39 private $synthetic = false;
40 private $abstract = false; 40 private $abstract = false;
41 private $lazy = false; 41 private $lazy = false;
42 private $decoratedService; 42 private $decoratedService;
43 private $autowired = false; 43 private $autowired = false;
44 private $autowiringTypes = array(); 44 private $autowiringTypes = [];
45 private $changes = array(); 45 private $changes = [];
46 private $bindings = array(); 46 private $bindings = [];
47 private $errors = array(); 47 private $errors = [];
48 48
49 protected $arguments = array(); 49 protected $arguments = [];
50 50
51 private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.'; 51 private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.';
52 52
53 /** 53 /**
54 * @param string|null $class The service class 54 * @param string|null $class The service class
55 * @param array $arguments An array of arguments to pass to the service constructor 55 * @param array $arguments An array of arguments to pass to the service constructor
56 */ 56 */
57 public function __construct($class = null, array $arguments = array()) 57 public function __construct($class = null, array $arguments = [])
58 { 58 {
59 if (null !== $class) { 59 if (null !== $class) {
60 $this->setClass($class); 60 $this->setClass($class);
61 } 61 }
62 $this->arguments = $arguments; 62 $this->arguments = $arguments;
95 */ 95 */
96 public function setFactory($factory) 96 public function setFactory($factory)
97 { 97 {
98 $this->changes['factory'] = true; 98 $this->changes['factory'] = true;
99 99
100 if (is_string($factory) && false !== strpos($factory, '::')) { 100 if (\is_string($factory) && false !== strpos($factory, '::')) {
101 $factory = explode('::', $factory, 2); 101 $factory = explode('::', $factory, 2);
102 } 102 }
103 103
104 $this->factory = $factory; 104 $this->factory = $factory;
105 105
107 } 107 }
108 108
109 /** 109 /**
110 * Gets the factory. 110 * Gets the factory.
111 * 111 *
112 * @return string|array The PHP function or an array containing a class/Reference and a method to call 112 * @return string|array|null The PHP function or an array containing a class/Reference and a method to call
113 */ 113 */
114 public function getFactory() 114 public function getFactory()
115 { 115 {
116 return $this->factory; 116 return $this->factory;
117 } 117 }
118 118
119 /** 119 /**
120 * Sets the service that this service is decorating. 120 * Sets the service that this service is decorating.
121 * 121 *
122 * @param null|string $id The decorated service id, use null to remove decoration 122 * @param string|null $id The decorated service id, use null to remove decoration
123 * @param null|string $renamedId The new decorated service id 123 * @param string|null $renamedId The new decorated service id
124 * @param int $priority The priority of decoration 124 * @param int $priority The priority of decoration
125 * 125 *
126 * @return $this 126 * @return $this
127 * 127 *
128 * @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals 128 * @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals
136 $this->changes['decorated_service'] = true; 136 $this->changes['decorated_service'] = true;
137 137
138 if (null === $id) { 138 if (null === $id) {
139 $this->decoratedService = null; 139 $this->decoratedService = null;
140 } else { 140 } else {
141 $this->decoratedService = array($id, $renamedId, (int) $priority); 141 $this->decoratedService = [$id, $renamedId, (int) $priority];
142 } 142 }
143 143
144 return $this; 144 return $this;
145 } 145 }
146 146
147 /** 147 /**
148 * Gets the service that this service is decorating. 148 * Gets the service that this service is decorating.
149 * 149 *
150 * @return null|array An array composed of the decorated service id, the new id for it and the priority of decoration, null if no service is decorated 150 * @return array|null An array composed of the decorated service id, the new id for it and the priority of decoration, null if no service is decorated
151 */ 151 */
152 public function getDecoratedService() 152 public function getDecoratedService()
153 { 153 {
154 return $this->decoratedService; 154 return $this->decoratedService;
155 } 155 }
253 * 253 *
254 * @throws OutOfBoundsException When the replaced argument does not exist 254 * @throws OutOfBoundsException When the replaced argument does not exist
255 */ 255 */
256 public function replaceArgument($index, $argument) 256 public function replaceArgument($index, $argument)
257 { 257 {
258 if (0 === count($this->arguments)) { 258 if (0 === \count($this->arguments)) {
259 throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.'); 259 throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.');
260 } 260 }
261 261
262 if (is_int($index) && ($index < 0 || $index > count($this->arguments) - 1)) { 262 if (\is_int($index) && ($index < 0 || $index > \count($this->arguments) - 1)) {
263 throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1)); 263 throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, \count($this->arguments) - 1));
264 } 264 }
265 265
266 if (!array_key_exists($index, $this->arguments)) { 266 if (!array_key_exists($index, $this->arguments)) {
267 throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index)); 267 throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index));
268 } 268 }
318 /** 318 /**
319 * Sets the methods to call after service initialization. 319 * Sets the methods to call after service initialization.
320 * 320 *
321 * @return $this 321 * @return $this
322 */ 322 */
323 public function setMethodCalls(array $calls = array()) 323 public function setMethodCalls(array $calls = [])
324 { 324 {
325 $this->calls = array(); 325 $this->calls = [];
326 foreach ($calls as $call) { 326 foreach ($calls as $call) {
327 $this->addMethodCall($call[0], $call[1]); 327 $this->addMethodCall($call[0], $call[1]);
328 } 328 }
329 329
330 return $this; 330 return $this;
338 * 338 *
339 * @return $this 339 * @return $this
340 * 340 *
341 * @throws InvalidArgumentException on empty $method param 341 * @throws InvalidArgumentException on empty $method param
342 */ 342 */
343 public function addMethodCall($method, array $arguments = array()) 343 public function addMethodCall($method, array $arguments = [])
344 { 344 {
345 if (empty($method)) { 345 if (empty($method)) {
346 throw new InvalidArgumentException('Method name cannot be empty.'); 346 throw new InvalidArgumentException('Method name cannot be empty.');
347 } 347 }
348 $this->calls[] = array($method, $arguments); 348 $this->calls[] = [$method, $arguments];
349 349
350 return $this; 350 return $this;
351 } 351 }
352 352
353 /** 353 /**
398 } 398 }
399 399
400 /** 400 /**
401 * Sets the definition templates to conditionally apply on the current definition, keyed by parent interface/class. 401 * Sets the definition templates to conditionally apply on the current definition, keyed by parent interface/class.
402 * 402 *
403 * @param $instanceof ChildDefinition[] 403 * @param ChildDefinition[] $instanceof
404 * 404 *
405 * @return $this 405 * @return $this
406 */ 406 */
407 public function setInstanceofConditionals(array $instanceof) 407 public function setInstanceofConditionals(array $instanceof)
408 { 408 {
474 * 474 *
475 * @return array An array of attributes 475 * @return array An array of attributes
476 */ 476 */
477 public function getTag($name) 477 public function getTag($name)
478 { 478 {
479 return isset($this->tags[$name]) ? $this->tags[$name] : array(); 479 return isset($this->tags[$name]) ? $this->tags[$name] : [];
480 } 480 }
481 481
482 /** 482 /**
483 * Adds a tag for this definition. 483 * Adds a tag for this definition.
484 * 484 *
485 * @param string $name The tag name 485 * @param string $name The tag name
486 * @param array $attributes An array of attributes 486 * @param array $attributes An array of attributes
487 * 487 *
488 * @return $this 488 * @return $this
489 */ 489 */
490 public function addTag($name, array $attributes = array()) 490 public function addTag($name, array $attributes = [])
491 { 491 {
492 $this->tags[$name][] = $attributes; 492 $this->tags[$name][] = $attributes;
493 493
494 return $this; 494 return $this;
495 } 495 }
525 * 525 *
526 * @return $this 526 * @return $this
527 */ 527 */
528 public function clearTags() 528 public function clearTags()
529 { 529 {
530 $this->tags = array(); 530 $this->tags = [];
531 531
532 return $this; 532 return $this;
533 } 533 }
534 534
535 /** 535 /**
782 */ 782 */
783 public function setConfigurator($configurator) 783 public function setConfigurator($configurator)
784 { 784 {
785 $this->changes['configurator'] = true; 785 $this->changes['configurator'] = true;
786 786
787 if (is_string($configurator) && false !== strpos($configurator, '::')) { 787 if (\is_string($configurator) && false !== strpos($configurator, '::')) {
788 $configurator = explode('::', $configurator, 2); 788 $configurator = explode('::', $configurator, 2);
789 } 789 }
790 790
791 $this->configurator = $configurator; 791 $this->configurator = $configurator;
792 792
814 */ 814 */
815 public function setAutowiringTypes(array $types) 815 public function setAutowiringTypes(array $types)
816 { 816 {
817 @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED); 817 @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED);
818 818
819 $this->autowiringTypes = array(); 819 $this->autowiringTypes = [];
820 820
821 foreach ($types as $type) { 821 foreach ($types as $type) {
822 $this->autowiringTypes[$type] = true; 822 $this->autowiringTypes[$type] = true;
823 } 823 }
824 824
858 * 858 *
859 * @deprecated since version 3.3, to be removed in 4.0. 859 * @deprecated since version 3.3, to be removed in 4.0.
860 */ 860 */
861 public function getAutowiringTypes(/*$triggerDeprecation = true*/) 861 public function getAutowiringTypes(/*$triggerDeprecation = true*/)
862 { 862 {
863 if (1 > func_num_args() || func_get_arg(0)) { 863 if (1 > \func_num_args() || func_get_arg(0)) {
864 @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED); 864 @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED);
865 } 865 }
866 866
867 return array_keys($this->autowiringTypes); 867 return array_keys($this->autowiringTypes);
868 } 868 }