mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 22:18:46 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -22,39 +22,46 @@ use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
|
||||
*/
|
||||
class Definition
|
||||
{
|
||||
private const DEFAULT_DEPRECATION_TEMPLATE = 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.';
|
||||
|
||||
private $class;
|
||||
private $file;
|
||||
private $factory;
|
||||
private $shared = true;
|
||||
private $deprecated = false;
|
||||
private $deprecationTemplate;
|
||||
private $deprecation = [];
|
||||
private $properties = [];
|
||||
private $calls = [];
|
||||
private $instanceof = [];
|
||||
private $autoconfigured = false;
|
||||
private $configurator;
|
||||
private $tags = [];
|
||||
private $public = true;
|
||||
private $private = true;
|
||||
private $public = false;
|
||||
private $synthetic = false;
|
||||
private $abstract = false;
|
||||
private $lazy = false;
|
||||
private $decoratedService;
|
||||
private $autowired = false;
|
||||
private $autowiringTypes = [];
|
||||
private $changes = [];
|
||||
private $bindings = [];
|
||||
private $errors = [];
|
||||
|
||||
protected $arguments = [];
|
||||
|
||||
private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.';
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Used to store the name of the inner id when using service decoration together with autowiring
|
||||
*/
|
||||
public $innerServiceId;
|
||||
|
||||
/**
|
||||
* @param string|null $class The service class
|
||||
* @param array $arguments An array of arguments to pass to the service constructor
|
||||
* @internal
|
||||
*
|
||||
* Used to store the behavior to follow when using service decoration and the decorated service is invalid
|
||||
*/
|
||||
public function __construct($class = null, array $arguments = [])
|
||||
public $decorationOnInvalid;
|
||||
|
||||
public function __construct(string $class = null, array $arguments = [])
|
||||
{
|
||||
if (null !== $class) {
|
||||
$this->setClass($class);
|
||||
@@ -65,7 +72,7 @@ class Definition
|
||||
/**
|
||||
* Returns all changes tracked for the Definition object.
|
||||
*
|
||||
* @return array An array of changes for this Definition
|
||||
* @return array
|
||||
*/
|
||||
public function getChanges()
|
||||
{
|
||||
@@ -89,7 +96,7 @@ class Definition
|
||||
/**
|
||||
* Sets a factory.
|
||||
*
|
||||
* @param string|array $factory A PHP function or an array containing a class/Reference and a method to call
|
||||
* @param string|array|Reference|null $factory A PHP function, reference or an array containing a class/Reference and a method to call
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
@@ -97,8 +104,10 @@ class Definition
|
||||
{
|
||||
$this->changes['factory'] = true;
|
||||
|
||||
if (\is_string($factory) && false !== strpos($factory, '::')) {
|
||||
if (\is_string($factory) && str_contains($factory, '::')) {
|
||||
$factory = explode('::', $factory, 2);
|
||||
} elseif ($factory instanceof Reference) {
|
||||
$factory = [$factory, '__invoke'];
|
||||
}
|
||||
|
||||
$this->factory = $factory;
|
||||
@@ -121,13 +130,12 @@ class Definition
|
||||
*
|
||||
* @param string|null $id The decorated service id, use null to remove decoration
|
||||
* @param string|null $renamedId The new decorated service id
|
||||
* @param int $priority The priority of decoration
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals
|
||||
*/
|
||||
public function setDecoratedService($id, $renamedId = null, $priority = 0)
|
||||
public function setDecoratedService(?string $id, string $renamedId = null, int $priority = 0, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
|
||||
{
|
||||
if ($renamedId && $id === $renamedId) {
|
||||
throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
|
||||
@@ -138,7 +146,11 @@ class Definition
|
||||
if (null === $id) {
|
||||
$this->decoratedService = null;
|
||||
} else {
|
||||
$this->decoratedService = [$id, $renamedId, (int) $priority];
|
||||
$this->decoratedService = [$id, $renamedId, $priority];
|
||||
|
||||
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
|
||||
$this->decoratedService[] = $invalidBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -157,11 +169,9 @@ class Definition
|
||||
/**
|
||||
* Sets the service class.
|
||||
*
|
||||
* @param string $class The service class
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setClass($class)
|
||||
public function setClass(?string $class)
|
||||
{
|
||||
$this->changes['class'] = true;
|
||||
|
||||
@@ -173,7 +183,7 @@ class Definition
|
||||
/**
|
||||
* Gets the service class.
|
||||
*
|
||||
* @return string|null The service class
|
||||
* @return string|null
|
||||
*/
|
||||
public function getClass()
|
||||
{
|
||||
@@ -217,12 +227,11 @@ class Definition
|
||||
/**
|
||||
* Sets a specific property.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperty($name, $value)
|
||||
public function setProperty(string $name, $value)
|
||||
{
|
||||
$this->properties[$name] = $value;
|
||||
|
||||
@@ -256,15 +265,15 @@ class Definition
|
||||
public function replaceArgument($index, $argument)
|
||||
{
|
||||
if (0 === \count($this->arguments)) {
|
||||
throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.');
|
||||
throw new OutOfBoundsException(sprintf('Cannot replace arguments for class "%s" if none have been configured yet.', $this->class));
|
||||
}
|
||||
|
||||
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));
|
||||
throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d] of the arguments of class "%s".', $index, \count($this->arguments) - 1, $this->class));
|
||||
}
|
||||
|
||||
if (!\array_key_exists($index, $this->arguments)) {
|
||||
throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index));
|
||||
throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist in class "%s".', $index, $this->class));
|
||||
}
|
||||
|
||||
$this->arguments[$index] = $argument;
|
||||
@@ -290,7 +299,7 @@ class Definition
|
||||
/**
|
||||
* Gets the arguments to pass to the service constructor/factory method.
|
||||
*
|
||||
* @return array The array of arguments
|
||||
* @return array
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
@@ -302,14 +311,14 @@ class Definition
|
||||
*
|
||||
* @param int|string $index
|
||||
*
|
||||
* @return mixed The argument value
|
||||
* @return mixed
|
||||
*
|
||||
* @throws OutOfBoundsException When the argument does not exist
|
||||
*/
|
||||
public function getArgument($index)
|
||||
{
|
||||
if (!\array_key_exists($index, $this->arguments)) {
|
||||
throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index));
|
||||
throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist in class "%s".', $index, $this->class));
|
||||
}
|
||||
|
||||
return $this->arguments[$index];
|
||||
@@ -324,7 +333,7 @@ class Definition
|
||||
{
|
||||
$this->calls = [];
|
||||
foreach ($calls as $call) {
|
||||
$this->addMethodCall($call[0], $call[1]);
|
||||
$this->addMethodCall($call[0], $call[1], $call[2] ?? false);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -333,19 +342,20 @@ class Definition
|
||||
/**
|
||||
* Adds a method to call after service initialization.
|
||||
*
|
||||
* @param string $method The method name to call
|
||||
* @param array $arguments An array of arguments to pass to the method call
|
||||
* @param string $method The method name to call
|
||||
* @param array $arguments An array of arguments to pass to the method call
|
||||
* @param bool $returnsClone Whether the call returns the service instance or not
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidArgumentException on empty $method param
|
||||
*/
|
||||
public function addMethodCall($method, array $arguments = [])
|
||||
public function addMethodCall(string $method, array $arguments = [], bool $returnsClone = false)
|
||||
{
|
||||
if (empty($method)) {
|
||||
throw new InvalidArgumentException('Method name cannot be empty.');
|
||||
}
|
||||
$this->calls[] = [$method, $arguments];
|
||||
$this->calls[] = $returnsClone ? [$method, $arguments, true] : [$method, $arguments];
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -353,16 +363,13 @@ class Definition
|
||||
/**
|
||||
* Removes a method to call after service initialization.
|
||||
*
|
||||
* @param string $method The method name to remove
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeMethodCall($method)
|
||||
public function removeMethodCall(string $method)
|
||||
{
|
||||
foreach ($this->calls as $i => $call) {
|
||||
if ($call[0] === $method) {
|
||||
unset($this->calls[$i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,11 +379,9 @@ class Definition
|
||||
/**
|
||||
* Check if the current definition has a given method to call after service initialization.
|
||||
*
|
||||
* @param string $method The method name to search for
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMethodCall($method)
|
||||
public function hasMethodCall(string $method)
|
||||
{
|
||||
foreach ($this->calls as $call) {
|
||||
if ($call[0] === $method) {
|
||||
@@ -390,7 +395,7 @@ class Definition
|
||||
/**
|
||||
* Gets the methods to call after service initialization.
|
||||
*
|
||||
* @return array An array of method calls
|
||||
* @return array
|
||||
*/
|
||||
public function getMethodCalls()
|
||||
{
|
||||
@@ -424,11 +429,9 @@ class Definition
|
||||
/**
|
||||
* Sets whether or not instanceof conditionals should be prepended with a global set.
|
||||
*
|
||||
* @param bool $autoconfigured
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutoconfigured($autoconfigured)
|
||||
public function setAutoconfigured(bool $autoconfigured)
|
||||
{
|
||||
$this->changes['autoconfigured'] = true;
|
||||
|
||||
@@ -460,7 +463,7 @@ class Definition
|
||||
/**
|
||||
* Returns all tags.
|
||||
*
|
||||
* @return array An array of tags
|
||||
* @return array
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
@@ -470,24 +473,19 @@ class Definition
|
||||
/**
|
||||
* Gets a tag by name.
|
||||
*
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return array An array of attributes
|
||||
* @return array
|
||||
*/
|
||||
public function getTag($name)
|
||||
public function getTag(string $name)
|
||||
{
|
||||
return isset($this->tags[$name]) ? $this->tags[$name] : [];
|
||||
return $this->tags[$name] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tag for this definition.
|
||||
*
|
||||
* @param string $name The tag name
|
||||
* @param array $attributes An array of attributes
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addTag($name, array $attributes = [])
|
||||
public function addTag(string $name, array $attributes = [])
|
||||
{
|
||||
$this->tags[$name][] = $attributes;
|
||||
|
||||
@@ -497,11 +495,9 @@ class Definition
|
||||
/**
|
||||
* Whether this definition has a tag with the given name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTag($name)
|
||||
public function hasTag(string $name)
|
||||
{
|
||||
return isset($this->tags[$name]);
|
||||
}
|
||||
@@ -509,11 +505,9 @@ class Definition
|
||||
/**
|
||||
* Clears all tags for a given name.
|
||||
*
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function clearTag($name)
|
||||
public function clearTag(string $name)
|
||||
{
|
||||
unset($this->tags[$name]);
|
||||
|
||||
@@ -535,11 +529,9 @@ class Definition
|
||||
/**
|
||||
* Sets a file to require before creating the service.
|
||||
*
|
||||
* @param string $file A full pathname to include
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFile($file)
|
||||
public function setFile(?string $file)
|
||||
{
|
||||
$this->changes['file'] = true;
|
||||
|
||||
@@ -551,7 +543,7 @@ class Definition
|
||||
/**
|
||||
* Gets the file to require before creating the service.
|
||||
*
|
||||
* @return string|null The full pathname to include
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFile()
|
||||
{
|
||||
@@ -561,15 +553,13 @@ class Definition
|
||||
/**
|
||||
* Sets if the service must be shared or not.
|
||||
*
|
||||
* @param bool $shared Whether the service must be shared or not
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setShared($shared)
|
||||
public function setShared(bool $shared)
|
||||
{
|
||||
$this->changes['shared'] = true;
|
||||
|
||||
$this->shared = (bool) $shared;
|
||||
$this->shared = $shared;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -587,16 +577,13 @@ class Definition
|
||||
/**
|
||||
* Sets the visibility of this service.
|
||||
*
|
||||
* @param bool $boolean
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPublic($boolean)
|
||||
public function setPublic(bool $boolean)
|
||||
{
|
||||
$this->changes['public'] = true;
|
||||
|
||||
$this->public = (bool) $boolean;
|
||||
$this->private = false;
|
||||
$this->public = $boolean;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -614,20 +601,15 @@ class Definition
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated since Symfony 5.2, use setPublic() instead
|
||||
*/
|
||||
public function setPrivate($boolean)
|
||||
public function setPrivate(bool $boolean)
|
||||
{
|
||||
$this->private = (bool) $boolean;
|
||||
trigger_deprecation('symfony/dependency-injection', '5.2', 'The "%s()" method is deprecated, use "setPublic()" instead.', __METHOD__);
|
||||
|
||||
return $this;
|
||||
return $this->setPublic(!$boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -637,21 +619,19 @@ class Definition
|
||||
*/
|
||||
public function isPrivate()
|
||||
{
|
||||
return $this->private;
|
||||
return !$this->public;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lazy flag of this service.
|
||||
*
|
||||
* @param bool $lazy
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLazy($lazy)
|
||||
public function setLazy(bool $lazy)
|
||||
{
|
||||
$this->changes['lazy'] = true;
|
||||
|
||||
$this->lazy = (bool) $lazy;
|
||||
$this->lazy = $lazy;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -670,13 +650,15 @@ class Definition
|
||||
* Sets whether this definition is synthetic, that is not constructed by the
|
||||
* container, but dynamically injected.
|
||||
*
|
||||
* @param bool $boolean
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSynthetic($boolean)
|
||||
public function setSynthetic(bool $boolean)
|
||||
{
|
||||
$this->synthetic = (bool) $boolean;
|
||||
$this->synthetic = $boolean;
|
||||
|
||||
if (!isset($this->changes['public'])) {
|
||||
$this->setPublic(true);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -696,13 +678,11 @@ class Definition
|
||||
* Whether this definition is abstract, that means it merely serves as a
|
||||
* template for other definitions.
|
||||
*
|
||||
* @param bool $boolean
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAbstract($boolean)
|
||||
public function setAbstract(bool $boolean)
|
||||
{
|
||||
$this->abstract = (bool) $boolean;
|
||||
$this->abstract = $boolean;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -722,30 +702,48 @@ class Definition
|
||||
* Whether this definition is deprecated, that means it should not be called
|
||||
* anymore.
|
||||
*
|
||||
* @param bool $status
|
||||
* @param string $template Template message to use if the definition is deprecated
|
||||
* @param string $package The name of the composer package that is triggering the deprecation
|
||||
* @param string $version The version of the package that introduced the deprecation
|
||||
* @param string $message The deprecation message to use
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidArgumentException when the message template is invalid
|
||||
*/
|
||||
public function setDeprecated($status = true, $template = null)
|
||||
public function setDeprecated(/* string $package, string $version, string $message */)
|
||||
{
|
||||
if (null !== $template) {
|
||||
if (preg_match('#[\r\n]|\*/#', $template)) {
|
||||
$args = \func_get_args();
|
||||
|
||||
if (\func_num_args() < 3) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__);
|
||||
|
||||
$status = $args[0] ?? true;
|
||||
|
||||
if (!$status) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Passing a null message to un-deprecate a node is deprecated.');
|
||||
}
|
||||
|
||||
$message = (string) ($args[1] ?? null);
|
||||
$package = $version = '';
|
||||
} else {
|
||||
$status = true;
|
||||
$package = (string) $args[0];
|
||||
$version = (string) $args[1];
|
||||
$message = (string) $args[2];
|
||||
}
|
||||
|
||||
if ('' !== $message) {
|
||||
if (preg_match('#[\r\n]|\*/#', $message)) {
|
||||
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
|
||||
}
|
||||
|
||||
if (false === strpos($template, '%service_id%')) {
|
||||
if (!str_contains($message, '%service_id%')) {
|
||||
throw new InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.');
|
||||
}
|
||||
|
||||
$this->deprecationTemplate = $template;
|
||||
}
|
||||
|
||||
$this->changes['deprecated'] = true;
|
||||
|
||||
$this->deprecated = (bool) $status;
|
||||
$this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::DEFAULT_DEPRECATION_TEMPLATE] : [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -758,25 +756,41 @@ class Definition
|
||||
*/
|
||||
public function isDeprecated()
|
||||
{
|
||||
return $this->deprecated;
|
||||
return (bool) $this->deprecation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message to use if this definition is deprecated.
|
||||
*
|
||||
* @deprecated since Symfony 5.1, use "getDeprecation()" instead.
|
||||
*
|
||||
* @param string $id Service id relying on this definition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDeprecationMessage($id)
|
||||
public function getDeprecationMessage(string $id)
|
||||
{
|
||||
return str_replace('%service_id%', $id, $this->deprecationTemplate ?: self::$defaultDeprecationTemplate);
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'The "%s()" method is deprecated, use "getDeprecation()" instead.', __METHOD__);
|
||||
|
||||
return $this->getDeprecation($id)['message'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id Service id relying on this definition
|
||||
*/
|
||||
public function getDeprecation(string $id): array
|
||||
{
|
||||
return [
|
||||
'package' => $this->deprecation['package'],
|
||||
'version' => $this->deprecation['version'],
|
||||
'message' => str_replace('%service_id%', $id, $this->deprecation['message']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a configurator to call after the service is fully initialized.
|
||||
*
|
||||
* @param string|array $configurator A PHP callable
|
||||
* @param string|array|Reference|null $configurator A PHP function, reference or an array containing a class/Reference and a method to call
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
@@ -784,8 +798,10 @@ class Definition
|
||||
{
|
||||
$this->changes['configurator'] = true;
|
||||
|
||||
if (\is_string($configurator) && false !== strpos($configurator, '::')) {
|
||||
if (\is_string($configurator) && str_contains($configurator, '::')) {
|
||||
$configurator = explode('::', $configurator, 2);
|
||||
} elseif ($configurator instanceof Reference) {
|
||||
$configurator = [$configurator, '__invoke'];
|
||||
}
|
||||
|
||||
$this->configurator = $configurator;
|
||||
@@ -796,35 +812,13 @@ class Definition
|
||||
/**
|
||||
* Gets the configurator to call after the service is fully initialized.
|
||||
*
|
||||
* @return callable|array|null
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function getConfigurator()
|
||||
{
|
||||
return $this->configurator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets types that will default to this definition.
|
||||
*
|
||||
* @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 = [];
|
||||
|
||||
foreach ($types as $type) {
|
||||
$this->autowiringTypes[$type] = true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the definition autowired?
|
||||
*
|
||||
@@ -838,91 +832,21 @@ class Definition
|
||||
/**
|
||||
* Enables/disables autowiring.
|
||||
*
|
||||
* @param bool $autowired
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutowired($autowired)
|
||||
public function setAutowired(bool $autowired)
|
||||
{
|
||||
$this->changes['autowired'] = true;
|
||||
|
||||
$this->autowired = (bool) $autowired;
|
||||
$this->autowired = $autowired;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(/*$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a type that will default to this definition.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a type.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will this definition default for the given type?
|
||||
*
|
||||
* @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
|
||||
* @return BoundArgument[]
|
||||
*/
|
||||
public function getBindings()
|
||||
{
|
||||
@@ -941,6 +865,10 @@ class Definition
|
||||
public function setBindings(array $bindings)
|
||||
{
|
||||
foreach ($bindings as $key => $binding) {
|
||||
if (0 < strpos($key, '$') && $key !== $k = preg_replace('/[ \t]*\$/', ' $', $key)) {
|
||||
unset($bindings[$key]);
|
||||
$bindings[$key = $k] = $binding;
|
||||
}
|
||||
if (!$binding instanceof BoundArgument) {
|
||||
$bindings[$key] = new BoundArgument($binding);
|
||||
}
|
||||
@@ -954,11 +882,19 @@ class Definition
|
||||
/**
|
||||
* Add an error that occurred when building this Definition.
|
||||
*
|
||||
* @param string $error
|
||||
* @param string|\Closure|self $error
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addError($error)
|
||||
{
|
||||
$this->errors[] = $error;
|
||||
if ($error instanceof self) {
|
||||
$this->errors = array_merge($this->errors, $error->errors);
|
||||
} else {
|
||||
$this->errors[] = $error;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -968,6 +904,19 @@ class Definition
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
foreach ($this->errors as $i => $error) {
|
||||
if ($error instanceof \Closure) {
|
||||
$this->errors[$i] = (string) $error();
|
||||
} elseif (!\is_string($error)) {
|
||||
$this->errors[$i] = (string) $error;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
public function hasErrors(): bool
|
||||
{
|
||||
return (bool) $this->errors;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user