Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection; Chris@0: Chris@14: use Symfony\Component\DependencyInjection\Argument\BoundArgument; Chris@0: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@0: use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; Chris@0: Chris@0: /** Chris@0: * Definition represents a service definition. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class Definition Chris@0: { Chris@0: private $class; Chris@0: private $file; Chris@0: private $factory; Chris@0: private $shared = true; Chris@0: private $deprecated = false; Chris@12: private $deprecationTemplate; Chris@17: private $properties = []; Chris@17: private $calls = []; Chris@17: private $instanceof = []; Chris@14: private $autoconfigured = false; Chris@0: private $configurator; Chris@17: private $tags = []; Chris@0: private $public = true; Chris@14: private $private = true; Chris@0: private $synthetic = false; Chris@0: private $abstract = false; Chris@0: private $lazy = false; Chris@0: private $decoratedService; Chris@0: private $autowired = false; Chris@17: private $autowiringTypes = []; Chris@17: private $changes = []; Chris@17: private $bindings = []; Chris@17: private $errors = []; Chris@14: Chris@17: protected $arguments = []; Chris@0: Chris@12: private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.'; Chris@12: Chris@0: /** Chris@0: * @param string|null $class The service class Chris@0: * @param array $arguments An array of arguments to pass to the service constructor Chris@0: */ Chris@17: public function __construct($class = null, array $arguments = []) Chris@0: { Chris@14: if (null !== $class) { Chris@14: $this->setClass($class); Chris@14: } Chris@0: $this->arguments = $arguments; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Returns all changes tracked for the Definition object. Chris@14: * Chris@14: * @return array An array of changes for this Definition Chris@14: */ Chris@14: public function getChanges() Chris@14: { Chris@14: return $this->changes; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Sets the tracked changes for the Definition object. Chris@14: * Chris@14: * @param array $changes An array of changes for this Definition Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setChanges(array $changes) Chris@14: { Chris@14: $this->changes = $changes; Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@0: * Sets a factory. Chris@0: * Chris@0: * @param string|array $factory A PHP function or an array containing a class/Reference and a method to call Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setFactory($factory) Chris@0: { Chris@14: $this->changes['factory'] = true; Chris@14: Chris@17: if (\is_string($factory) && false !== strpos($factory, '::')) { Chris@0: $factory = explode('::', $factory, 2); Chris@0: } Chris@0: Chris@0: $this->factory = $factory; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the factory. Chris@0: * Chris@17: * @return string|array|null The PHP function or an array containing a class/Reference and a method to call Chris@0: */ Chris@0: public function getFactory() Chris@0: { Chris@0: return $this->factory; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the service that this service is decorating. Chris@0: * Chris@17: * @param string|null $id The decorated service id, use null to remove decoration Chris@17: * @param string|null $renamedId The new decorated service id Chris@0: * @param int $priority The priority of decoration Chris@0: * Chris@0: * @return $this Chris@0: * Chris@14: * @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals Chris@0: */ Chris@0: public function setDecoratedService($id, $renamedId = null, $priority = 0) Chris@0: { Chris@14: if ($renamedId && $id === $renamedId) { Chris@0: throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id)); Chris@0: } Chris@0: Chris@14: $this->changes['decorated_service'] = true; Chris@14: Chris@0: if (null === $id) { Chris@0: $this->decoratedService = null; Chris@0: } else { Chris@17: $this->decoratedService = [$id, $renamedId, (int) $priority]; Chris@0: } Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the service that this service is decorating. Chris@0: * Chris@17: * @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 Chris@0: */ Chris@0: public function getDecoratedService() Chris@0: { Chris@0: return $this->decoratedService; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the service class. Chris@0: * Chris@0: * @param string $class The service class Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setClass($class) Chris@0: { Chris@14: $this->changes['class'] = true; Chris@14: Chris@0: $this->class = $class; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the service class. Chris@0: * Chris@0: * @return string|null The service class Chris@0: */ Chris@0: public function getClass() Chris@0: { Chris@0: return $this->class; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the arguments to pass to the service constructor/factory method. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setArguments(array $arguments) Chris@0: { Chris@0: $this->arguments = $arguments; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@14: /** Chris@14: * Sets the properties to define when creating the service. Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@0: public function setProperties(array $properties) Chris@0: { Chris@0: $this->properties = $properties; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@14: /** Chris@14: * Gets the properties to define when creating the service. Chris@14: * Chris@14: * @return array Chris@14: */ Chris@0: public function getProperties() Chris@0: { Chris@0: return $this->properties; Chris@0: } Chris@0: Chris@14: /** Chris@14: * Sets a specific property. Chris@14: * Chris@14: * @param string $name Chris@14: * @param mixed $value Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@0: public function setProperty($name, $value) Chris@0: { Chris@0: $this->properties[$name] = $value; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds an argument to pass to the service constructor/factory method. Chris@0: * Chris@0: * @param mixed $argument An argument Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function addArgument($argument) Chris@0: { Chris@0: $this->arguments[] = $argument; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Replaces a specific argument. Chris@0: * Chris@14: * @param int|string $index Chris@14: * @param mixed $argument Chris@0: * Chris@0: * @return $this Chris@0: * Chris@0: * @throws OutOfBoundsException When the replaced argument does not exist Chris@0: */ Chris@0: public function replaceArgument($index, $argument) Chris@0: { Chris@17: if (0 === \count($this->arguments)) { Chris@0: throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.'); Chris@0: } Chris@0: Chris@17: if (\is_int($index) && ($index < 0 || $index > \count($this->arguments) - 1)) { Chris@17: throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, \count($this->arguments) - 1)); Chris@0: } Chris@0: Chris@18: if (!\array_key_exists($index, $this->arguments)) { Chris@14: throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index)); Chris@14: } Chris@14: Chris@0: $this->arguments[$index] = $argument; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Sets a specific argument. Chris@14: * Chris@14: * @param int|string $key Chris@14: * @param mixed $value Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setArgument($key, $value) Chris@14: { Chris@14: $this->arguments[$key] = $value; Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@0: * Gets the arguments to pass to the service constructor/factory method. Chris@0: * Chris@0: * @return array The array of arguments Chris@0: */ Chris@0: public function getArguments() Chris@0: { Chris@0: return $this->arguments; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets an argument to pass to the service constructor/factory method. Chris@0: * Chris@14: * @param int|string $index Chris@0: * Chris@0: * @return mixed The argument value Chris@0: * Chris@0: * @throws OutOfBoundsException When the argument does not exist Chris@0: */ Chris@0: public function getArgument($index) Chris@0: { Chris@18: if (!\array_key_exists($index, $this->arguments)) { Chris@14: throw new OutOfBoundsException(sprintf('The argument "%s" doesn\'t exist.', $index)); Chris@0: } Chris@0: Chris@0: return $this->arguments[$index]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the methods to call after service initialization. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@17: public function setMethodCalls(array $calls = []) Chris@0: { Chris@17: $this->calls = []; Chris@0: foreach ($calls as $call) { Chris@0: $this->addMethodCall($call[0], $call[1]); Chris@0: } Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a method to call after service initialization. Chris@0: * Chris@0: * @param string $method The method name to call Chris@0: * @param array $arguments An array of arguments to pass to the method call Chris@0: * Chris@0: * @return $this Chris@0: * Chris@0: * @throws InvalidArgumentException on empty $method param Chris@0: */ Chris@17: public function addMethodCall($method, array $arguments = []) Chris@0: { Chris@0: if (empty($method)) { Chris@0: throw new InvalidArgumentException('Method name cannot be empty.'); Chris@0: } Chris@17: $this->calls[] = [$method, $arguments]; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes a method to call after service initialization. Chris@0: * Chris@0: * @param string $method The method name to remove Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function removeMethodCall($method) Chris@0: { Chris@0: foreach ($this->calls as $i => $call) { Chris@0: if ($call[0] === $method) { Chris@0: unset($this->calls[$i]); Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Check if the current definition has a given method to call after service initialization. Chris@0: * Chris@0: * @param string $method The method name to search for Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function hasMethodCall($method) Chris@0: { Chris@0: foreach ($this->calls as $call) { Chris@0: if ($call[0] === $method) { Chris@0: return true; Chris@0: } Chris@0: } Chris@0: Chris@0: return false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the methods to call after service initialization. Chris@0: * Chris@0: * @return array An array of method calls Chris@0: */ Chris@0: public function getMethodCalls() Chris@0: { Chris@0: return $this->calls; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Sets the definition templates to conditionally apply on the current definition, keyed by parent interface/class. Chris@14: * Chris@17: * @param ChildDefinition[] $instanceof Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setInstanceofConditionals(array $instanceof) Chris@14: { Chris@14: $this->instanceof = $instanceof; Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Gets the definition templates to conditionally apply on the current definition, keyed by parent interface/class. Chris@14: * Chris@14: * @return ChildDefinition[] Chris@14: */ Chris@14: public function getInstanceofConditionals() Chris@14: { Chris@14: return $this->instanceof; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Sets whether or not instanceof conditionals should be prepended with a global set. Chris@14: * Chris@14: * @param bool $autoconfigured Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setAutoconfigured($autoconfigured) Chris@14: { Chris@14: $this->changes['autoconfigured'] = true; Chris@14: Chris@14: $this->autoconfigured = $autoconfigured; Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @return bool Chris@14: */ Chris@14: public function isAutoconfigured() Chris@14: { Chris@14: return $this->autoconfigured; Chris@14: } Chris@14: Chris@14: /** Chris@0: * Sets tags for this definition. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setTags(array $tags) Chris@0: { Chris@0: $this->tags = $tags; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns all tags. Chris@0: * Chris@0: * @return array An array of tags Chris@0: */ Chris@0: public function getTags() Chris@0: { Chris@0: return $this->tags; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets a tag by name. Chris@0: * Chris@0: * @param string $name The tag name Chris@0: * Chris@0: * @return array An array of attributes Chris@0: */ Chris@0: public function getTag($name) Chris@0: { Chris@17: return isset($this->tags[$name]) ? $this->tags[$name] : []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a tag for this definition. Chris@0: * Chris@0: * @param string $name The tag name Chris@0: * @param array $attributes An array of attributes Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@17: public function addTag($name, array $attributes = []) Chris@0: { Chris@0: $this->tags[$name][] = $attributes; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this definition has a tag with the given name. Chris@0: * Chris@0: * @param string $name Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function hasTag($name) Chris@0: { Chris@0: return isset($this->tags[$name]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Clears all tags for a given name. Chris@0: * Chris@0: * @param string $name The tag name Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function clearTag($name) Chris@0: { Chris@0: unset($this->tags[$name]); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Clears the tags for this definition. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function clearTags() Chris@0: { Chris@17: $this->tags = []; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets a file to require before creating the service. Chris@0: * Chris@0: * @param string $file A full pathname to include Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setFile($file) Chris@0: { Chris@14: $this->changes['file'] = true; Chris@14: Chris@0: $this->file = $file; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the file to require before creating the service. Chris@0: * Chris@0: * @return string|null The full pathname to include Chris@0: */ Chris@0: public function getFile() Chris@0: { Chris@0: return $this->file; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets if the service must be shared or not. Chris@0: * Chris@0: * @param bool $shared Whether the service must be shared or not Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setShared($shared) Chris@0: { Chris@14: $this->changes['shared'] = true; Chris@14: Chris@0: $this->shared = (bool) $shared; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this service is shared. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isShared() Chris@0: { Chris@0: return $this->shared; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the visibility of this service. Chris@0: * Chris@0: * @param bool $boolean Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setPublic($boolean) Chris@0: { Chris@14: $this->changes['public'] = true; Chris@14: Chris@0: $this->public = (bool) $boolean; Chris@14: $this->private = false; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this service is public facing. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isPublic() Chris@0: { Chris@0: return $this->public; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Sets if this service is private. Chris@14: * Chris@14: * When set, the "private" state has a higher precedence than "public". Chris@14: * In version 3.4, a "private" service always remains publicly accessible, Chris@14: * but triggers a deprecation notice when accessed from the container, Chris@14: * so that the service can be made really private in 4.0. Chris@14: * Chris@14: * @param bool $boolean Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setPrivate($boolean) Chris@14: { Chris@14: $this->private = (bool) $boolean; Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Whether this service is private. Chris@14: * Chris@14: * @return bool Chris@14: */ Chris@14: public function isPrivate() Chris@14: { Chris@14: return $this->private; Chris@14: } Chris@14: Chris@14: /** Chris@0: * Sets the lazy flag of this service. Chris@0: * Chris@0: * @param bool $lazy Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setLazy($lazy) Chris@0: { Chris@14: $this->changes['lazy'] = true; Chris@14: Chris@0: $this->lazy = (bool) $lazy; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this service is lazy. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isLazy() Chris@0: { Chris@0: return $this->lazy; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets whether this definition is synthetic, that is not constructed by the Chris@0: * container, but dynamically injected. Chris@0: * Chris@0: * @param bool $boolean Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setSynthetic($boolean) Chris@0: { Chris@0: $this->synthetic = (bool) $boolean; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this definition is synthetic, that is not constructed by the Chris@0: * container, but dynamically injected. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isSynthetic() Chris@0: { Chris@0: return $this->synthetic; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this definition is abstract, that means it merely serves as a Chris@0: * template for other definitions. Chris@0: * Chris@0: * @param bool $boolean Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setAbstract($boolean) Chris@0: { Chris@0: $this->abstract = (bool) $boolean; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this definition is abstract, that means it merely serves as a Chris@0: * template for other definitions. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isAbstract() Chris@0: { Chris@0: return $this->abstract; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this definition is deprecated, that means it should not be called Chris@0: * anymore. Chris@0: * Chris@0: * @param bool $status Chris@0: * @param string $template Template message to use if the definition is deprecated Chris@0: * Chris@0: * @return $this Chris@0: * Chris@14: * @throws InvalidArgumentException when the message template is invalid Chris@0: */ Chris@0: public function setDeprecated($status = true, $template = null) Chris@0: { Chris@0: if (null !== $template) { Chris@0: if (preg_match('#[\r\n]|\*/#', $template)) { Chris@0: throw new InvalidArgumentException('Invalid characters found in deprecation template.'); Chris@0: } Chris@0: Chris@0: if (false === strpos($template, '%service_id%')) { Chris@0: throw new InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.'); Chris@0: } Chris@0: Chris@0: $this->deprecationTemplate = $template; Chris@0: } Chris@0: Chris@14: $this->changes['deprecated'] = true; Chris@14: Chris@0: $this->deprecated = (bool) $status; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether this definition is deprecated, that means it should not be called Chris@0: * anymore. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isDeprecated() Chris@0: { Chris@0: return $this->deprecated; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Message to use if this definition is deprecated. Chris@0: * Chris@0: * @param string $id Service id relying on this definition Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getDeprecationMessage($id) Chris@0: { Chris@12: return str_replace('%service_id%', $id, $this->deprecationTemplate ?: self::$defaultDeprecationTemplate); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets a configurator to call after the service is fully initialized. Chris@0: * Chris@0: * @param string|array $configurator A PHP callable Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setConfigurator($configurator) Chris@0: { Chris@14: $this->changes['configurator'] = true; Chris@14: Chris@17: if (\is_string($configurator) && false !== strpos($configurator, '::')) { Chris@0: $configurator = explode('::', $configurator, 2); Chris@0: } Chris@0: Chris@0: $this->configurator = $configurator; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the configurator to call after the service is fully initialized. Chris@0: * Chris@0: * @return callable|null The PHP callable to call Chris@0: */ Chris@0: public function getConfigurator() Chris@0: { Chris@0: return $this->configurator; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets types that will default to this definition. Chris@0: * Chris@0: * @param string[] $types Chris@0: * Chris@0: * @return $this Chris@14: * Chris@14: * @deprecated since version 3.3, to be removed in 4.0. Chris@0: */ Chris@0: public function setAutowiringTypes(array $types) Chris@0: { Chris@14: @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED); Chris@14: Chris@17: $this->autowiringTypes = []; Chris@0: Chris@0: foreach ($types as $type) { Chris@0: $this->autowiringTypes[$type] = true; Chris@0: } Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Is the definition autowired? Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isAutowired() Chris@0: { Chris@0: return $this->autowired; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Enables/disables autowiring. Chris@0: * Chris@0: * @param bool $autowired Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setAutowired($autowired) Chris@0: { Chris@14: $this->changes['autowired'] = true; Chris@14: Chris@14: $this->autowired = (bool) $autowired; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets autowiring types that will default to this definition. Chris@0: * Chris@0: * @return string[] Chris@14: * Chris@14: * @deprecated since version 3.3, to be removed in 4.0. Chris@0: */ Chris@14: public function getAutowiringTypes(/*$triggerDeprecation = true*/) Chris@0: { Chris@17: if (1 > \func_num_args() || func_get_arg(0)) { Chris@14: @trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED); Chris@14: } Chris@14: Chris@0: return array_keys($this->autowiringTypes); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a type that will default to this definition. Chris@0: * Chris@0: * @param string $type Chris@0: * Chris@0: * @return $this Chris@14: * Chris@14: * @deprecated since version 3.3, to be removed in 4.0. Chris@0: */ Chris@0: public function addAutowiringType($type) Chris@0: { Chris@14: @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); Chris@14: Chris@0: $this->autowiringTypes[$type] = true; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes a type. Chris@0: * Chris@0: * @param string $type Chris@0: * Chris@0: * @return $this Chris@14: * Chris@14: * @deprecated since version 3.3, to be removed in 4.0. Chris@0: */ Chris@0: public function removeAutowiringType($type) Chris@0: { Chris@14: @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); Chris@14: Chris@0: unset($this->autowiringTypes[$type]); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Will this definition default for the given type? Chris@0: * Chris@0: * @param string $type Chris@0: * Chris@0: * @return bool Chris@14: * Chris@14: * @deprecated since version 3.3, to be removed in 4.0. Chris@0: */ Chris@0: public function hasAutowiringType($type) Chris@0: { Chris@14: @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); Chris@14: Chris@0: return isset($this->autowiringTypes[$type]); Chris@0: } Chris@14: Chris@14: /** Chris@14: * Gets bindings. Chris@14: * Chris@14: * @return array Chris@14: */ Chris@14: public function getBindings() Chris@14: { Chris@14: return $this->bindings; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Sets bindings. Chris@14: * Chris@14: * Bindings map $named or FQCN arguments to values that should be Chris@14: * injected in the matching parameters (of the constructor, of methods Chris@14: * called and of controller actions). Chris@14: * Chris@14: * @param array $bindings Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setBindings(array $bindings) Chris@14: { Chris@14: foreach ($bindings as $key => $binding) { Chris@14: if (!$binding instanceof BoundArgument) { Chris@14: $bindings[$key] = new BoundArgument($binding); Chris@14: } Chris@14: } Chris@14: Chris@14: $this->bindings = $bindings; Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Add an error that occurred when building this Definition. Chris@14: * Chris@14: * @param string $error Chris@14: */ Chris@14: public function addError($error) Chris@14: { Chris@14: $this->errors[] = $error; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns any errors that occurred while building this Definition. Chris@14: * Chris@14: * @return array Chris@14: */ Chris@14: public function getErrors() Chris@14: { Chris@14: return $this->errors; Chris@14: } Chris@0: }