Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/dependency-injection/Definition.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/symfony/dependency-injection/Definition.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/dependency-injection/Definition.php Mon Apr 23 09:46:53 2018 +0100 @@ -11,6 +11,7 @@ namespace Symfony\Component\DependencyInjection; +use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; @@ -29,31 +30,63 @@ private $deprecationTemplate; private $properties = array(); private $calls = array(); + private $instanceof = array(); + private $autoconfigured = false; private $configurator; private $tags = array(); private $public = true; + private $private = true; private $synthetic = false; private $abstract = false; private $lazy = false; private $decoratedService; private $autowired = false; private $autowiringTypes = array(); + private $changes = array(); + private $bindings = array(); + private $errors = array(); + + protected $arguments = array(); private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.'; - protected $arguments; - /** * @param string|null $class The service class * @param array $arguments An array of arguments to pass to the service constructor */ public function __construct($class = null, array $arguments = array()) { - $this->class = $class; + if (null !== $class) { + $this->setClass($class); + } $this->arguments = $arguments; } /** + * Returns all changes tracked for the Definition object. + * + * @return array An array of changes for this Definition + */ + public function getChanges() + { + return $this->changes; + } + + /** + * Sets the tracked changes for the Definition object. + * + * @param array $changes An array of changes for this Definition + * + * @return $this + */ + public function setChanges(array $changes) + { + $this->changes = $changes; + + return $this; + } + + /** * Sets a factory. * * @param string|array $factory A PHP function or an array containing a class/Reference and a method to call @@ -62,7 +95,9 @@ */ public function setFactory($factory) { - if (is_string($factory) && strpos($factory, '::') !== false) { + $this->changes['factory'] = true; + + if (is_string($factory) && false !== strpos($factory, '::')) { $factory = explode('::', $factory, 2); } @@ -90,14 +125,16 @@ * * @return $this * - * @throws InvalidArgumentException In case the decorated service id and the new decorated service id are equals. + * @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals */ public function setDecoratedService($id, $renamedId = null, $priority = 0) { - if ($renamedId && $id == $renamedId) { + if ($renamedId && $id === $renamedId) { throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id)); } + $this->changes['decorated_service'] = true; + if (null === $id) { $this->decoratedService = null; } else { @@ -126,6 +163,8 @@ */ public function setClass($class) { + $this->changes['class'] = true; + $this->class = $class; return $this; @@ -144,8 +183,6 @@ /** * Sets the arguments to pass to the service constructor/factory method. * - * @param array $arguments An array of arguments - * * @return $this */ public function setArguments(array $arguments) @@ -155,6 +192,11 @@ return $this; } + /** + * Sets the properties to define when creating the service. + * + * @return $this + */ public function setProperties(array $properties) { $this->properties = $properties; @@ -162,11 +204,24 @@ return $this; } + /** + * Gets the properties to define when creating the service. + * + * @return array + */ public function getProperties() { return $this->properties; } + /** + * Sets a specific property. + * + * @param string $name + * @param mixed $value + * + * @return $this + */ public function setProperty($name, $value) { $this->properties[$name] = $value; @@ -189,10 +244,10 @@ } /** - * Sets a specific argument. + * Replaces a specific argument. * - * @param int $index - * @param mixed $argument + * @param int|string $index + * @param mixed $argument * * @return $this * @@ -204,16 +259,35 @@ throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.'); } - if ($index < 0 || $index > count($this->arguments) - 1) { + if (is_int($index) && ($index < 0 || $index > count($this->arguments) - 1)) { throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1)); } + if (!array_key_exists($index, $this->arguments)) { + throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index)); + } + $this->arguments[$index] = $argument; return $this; } /** + * Sets a specific argument. + * + * @param int|string $key + * @param mixed $value + * + * @return $this + */ + public function setArgument($key, $value) + { + $this->arguments[$key] = $value; + + return $this; + } + + /** * Gets the arguments to pass to the service constructor/factory method. * * @return array The array of arguments @@ -226,7 +300,7 @@ /** * Gets an argument to pass to the service constructor/factory method. * - * @param int $index + * @param int|string $index * * @return mixed The argument value * @@ -234,8 +308,8 @@ */ public function getArgument($index) { - if ($index < 0 || $index > count($this->arguments) - 1) { - throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1)); + if (!array_key_exists($index, $this->arguments)) { + throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index)); } return $this->arguments[$index]; @@ -244,8 +318,6 @@ /** * Sets the methods to call after service initialization. * - * @param array $calls An array of method calls - * * @return $this */ public function setMethodCalls(array $calls = array()) @@ -326,10 +398,56 @@ } /** + * Sets the definition templates to conditionally apply on the current definition, keyed by parent interface/class. + * + * @param $instanceof ChildDefinition[] + * + * @return $this + */ + public function setInstanceofConditionals(array $instanceof) + { + $this->instanceof = $instanceof; + + return $this; + } + + /** + * Gets the definition templates to conditionally apply on the current definition, keyed by parent interface/class. + * + * @return ChildDefinition[] + */ + public function getInstanceofConditionals() + { + return $this->instanceof; + } + + /** + * Sets whether or not instanceof conditionals should be prepended with a global set. + * + * @param bool $autoconfigured + * + * @return $this + */ + public function setAutoconfigured($autoconfigured) + { + $this->changes['autoconfigured'] = true; + + $this->autoconfigured = $autoconfigured; + + return $this; + } + + /** + * @return bool + */ + public function isAutoconfigured() + { + return $this->autoconfigured; + } + + /** * Sets tags for this definition. * - * @param array $tags - * * @return $this */ public function setTags(array $tags) @@ -423,6 +541,8 @@ */ public function setFile($file) { + $this->changes['file'] = true; + $this->file = $file; return $this; @@ -447,6 +567,8 @@ */ public function setShared($shared) { + $this->changes['shared'] = true; + $this->shared = (bool) $shared; return $this; @@ -471,7 +593,10 @@ */ public function setPublic($boolean) { + $this->changes['public'] = true; + $this->public = (bool) $boolean; + $this->private = false; return $this; } @@ -487,6 +612,35 @@ } /** + * Sets if this service is private. + * + * When set, the "private" state has a higher precedence than "public". + * In version 3.4, a "private" service always remains publicly accessible, + * but triggers a deprecation notice when accessed from the container, + * so that the service can be made really private in 4.0. + * + * @param bool $boolean + * + * @return $this + */ + public function setPrivate($boolean) + { + $this->private = (bool) $boolean; + + return $this; + } + + /** + * Whether this service is private. + * + * @return bool + */ + public function isPrivate() + { + return $this->private; + } + + /** * Sets the lazy flag of this service. * * @param bool $lazy @@ -495,6 +649,8 @@ */ public function setLazy($lazy) { + $this->changes['lazy'] = true; + $this->lazy = (bool) $lazy; return $this; @@ -571,7 +727,7 @@ * * @return $this * - * @throws InvalidArgumentException When the message template is invalid. + * @throws InvalidArgumentException when the message template is invalid */ public function setDeprecated($status = true, $template = null) { @@ -587,6 +743,8 @@ $this->deprecationTemplate = $template; } + $this->changes['deprecated'] = true; + $this->deprecated = (bool) $status; return $this; @@ -624,7 +782,9 @@ */ public function setConfigurator($configurator) { - if (is_string($configurator) && strpos($configurator, '::') !== false) { + $this->changes['configurator'] = true; + + if (is_string($configurator) && false !== strpos($configurator, '::')) { $configurator = explode('::', $configurator, 2); } @@ -649,9 +809,13 @@ * @param string[] $types * * @return $this + * + * @deprecated since version 3.3, to be removed in 4.0. */ public function setAutowiringTypes(array $types) { + @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED); + $this->autowiringTypes = array(); foreach ($types as $type) { @@ -672,7 +836,7 @@ } /** - * Sets autowired. + * Enables/disables autowiring. * * @param bool $autowired * @@ -680,7 +844,9 @@ */ public function setAutowired($autowired) { - $this->autowired = $autowired; + $this->changes['autowired'] = true; + + $this->autowired = (bool) $autowired; return $this; } @@ -689,9 +855,15 @@ * Gets autowiring types that will default to this definition. * * @return string[] + * + * @deprecated since version 3.3, to be removed in 4.0. */ - public function getAutowiringTypes() + public function getAutowiringTypes(/*$triggerDeprecation = true*/) { + if (1 > func_num_args() || func_get_arg(0)) { + @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED); + } + return array_keys($this->autowiringTypes); } @@ -701,9 +873,13 @@ * @param string $type * * @return $this + * + * @deprecated since version 3.3, to be removed in 4.0. */ public function addAutowiringType($type) { + @trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED); + $this->autowiringTypes[$type] = true; return $this; @@ -715,9 +891,13 @@ * @param string $type * * @return $this + * + * @deprecated since version 3.3, to be removed in 4.0. */ public function removeAutowiringType($type) { + @trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED); + unset($this->autowiringTypes[$type]); return $this; @@ -729,9 +909,67 @@ * @param string $type * * @return bool + * + * @deprecated since version 3.3, to be removed in 4.0. */ public function hasAutowiringType($type) { + @trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED); + return isset($this->autowiringTypes[$type]); } + + /** + * Gets bindings. + * + * @return array + */ + public function getBindings() + { + return $this->bindings; + } + + /** + * Sets bindings. + * + * Bindings map $named or FQCN arguments to values that should be + * injected in the matching parameters (of the constructor, of methods + * called and of controller actions). + * + * @param array $bindings + * + * @return $this + */ + public function setBindings(array $bindings) + { + foreach ($bindings as $key => $binding) { + if (!$binding instanceof BoundArgument) { + $bindings[$key] = new BoundArgument($binding); + } + } + + $this->bindings = $bindings; + + return $this; + } + + /** + * Add an error that occurred when building this Definition. + * + * @param string $error + */ + public function addError($error) + { + $this->errors[] = $error; + } + + /** + * Returns any errors that occurred while building this Definition. + * + * @return array + */ + public function getErrors() + { + return $this->errors; + } }