2010-01-04 14:26:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-01-04 14:26:20 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-01-04 14:26:20 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-01-04 14:26:20 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection;
|
|
|
|
|
2011-11-30 13:11:00 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
2011-12-04 23:51:22 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
|
2011-11-30 13:11:00 +00:00
|
|
|
|
2010-01-04 14:26:20 +00:00
|
|
|
/**
|
|
|
|
* Definition represents a service definition.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-01-04 14:26:20 +00:00
|
|
|
*/
|
|
|
|
class Definition
|
|
|
|
{
|
2011-03-11 13:50:46 +00:00
|
|
|
private $class;
|
|
|
|
private $file;
|
2014-04-13 16:18:39 +01:00
|
|
|
private $factory;
|
2015-06-15 03:41:59 +01:00
|
|
|
private $shared = true;
|
2015-08-10 13:35:12 +01:00
|
|
|
private $deprecated = false;
|
|
|
|
private $deprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.';
|
2013-11-10 17:06:47 +00:00
|
|
|
private $properties = array();
|
|
|
|
private $calls = array();
|
2011-03-11 13:50:46 +00:00
|
|
|
private $configurator;
|
2013-11-10 17:06:47 +00:00
|
|
|
private $tags = array();
|
|
|
|
private $public = true;
|
|
|
|
private $synthetic = false;
|
|
|
|
private $abstract = false;
|
|
|
|
private $lazy = false;
|
2013-09-12 11:15:48 +01:00
|
|
|
private $decoratedService;
|
2016-10-05 21:46:29 +01:00
|
|
|
private $autowiredMethods = array();
|
2015-08-24 02:36:41 +01:00
|
|
|
private $autowiringTypes = array();
|
2011-03-11 13:50:46 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $arguments;
|
|
|
|
|
|
|
|
/**
|
2013-11-10 17:06:47 +00:00
|
|
|
* @param string|null $class The service class
|
|
|
|
* @param array $arguments An array of arguments to pass to the service constructor
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2010-07-04 17:56:48 +01:00
|
|
|
public function __construct($class = null, array $arguments = array())
|
2010-01-04 14:26:20 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->class = $class;
|
|
|
|
$this->arguments = $arguments;
|
2010-01-04 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
2014-04-13 16:18:39 +01:00
|
|
|
/**
|
2014-09-24 07:35:53 +01:00
|
|
|
* Sets a factory.
|
2014-04-13 16:18:39 +01:00
|
|
|
*
|
2014-09-24 07:35:53 +01:00
|
|
|
* @param string|array $factory A PHP function or an array containing a class/Reference and a method to call
|
2014-04-13 16:18:39 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2014-04-13 16:18:39 +01:00
|
|
|
*/
|
|
|
|
public function setFactory($factory)
|
|
|
|
{
|
2014-09-27 17:06:30 +01:00
|
|
|
if (is_string($factory) && strpos($factory, '::') !== false) {
|
|
|
|
$factory = explode('::', $factory, 2);
|
|
|
|
}
|
|
|
|
|
2014-04-13 16:18:39 +01:00
|
|
|
$this->factory = $factory;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-24 07:35:53 +01:00
|
|
|
* Gets the factory.
|
2014-04-13 16:18:39 +01:00
|
|
|
*
|
2014-09-24 07:35:53 +01:00
|
|
|
* @return string|array The PHP function or an array containing a class/Reference and a method to call
|
2014-04-13 16:18:39 +01:00
|
|
|
*/
|
|
|
|
public function getFactory()
|
|
|
|
{
|
|
|
|
return $this->factory;
|
|
|
|
}
|
|
|
|
|
2013-09-12 11:15:48 +01:00
|
|
|
/**
|
|
|
|
* Sets the service that this service is decorating.
|
|
|
|
*
|
2014-03-31 16:58:40 +01:00
|
|
|
* @param null|string $id The decorated service id, use null to remove decoration
|
|
|
|
* @param null|string $renamedId The new decorated service id
|
2015-07-31 02:41:40 +01:00
|
|
|
* @param int $priority The priority of decoration
|
2014-03-31 16:58:40 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2014-03-31 16:58:40 +01:00
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException In case the decorated service id and the new decorated service id are equals.
|
2013-09-12 11:15:48 +01:00
|
|
|
*/
|
2015-07-31 02:41:40 +01:00
|
|
|
public function setDecoratedService($id, $renamedId = null, $priority = 0)
|
2013-09-12 11:15:48 +01:00
|
|
|
{
|
|
|
|
if ($renamedId && $id == $renamedId) {
|
2016-09-09 11:12:11 +01:00
|
|
|
throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
|
2013-09-12 11:15:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-31 16:58:40 +01:00
|
|
|
if (null === $id) {
|
|
|
|
$this->decoratedService = null;
|
|
|
|
} else {
|
2015-07-31 02:41:40 +01:00
|
|
|
$this->decoratedService = array($id, $renamedId, (int) $priority);
|
2014-03-31 16:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
2013-09-12 11:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the service that decorates this service.
|
|
|
|
*
|
2015-07-31 02:41:40 +01:00
|
|
|
* @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
|
2013-09-12 11:15:48 +01:00
|
|
|
*/
|
|
|
|
public function getDecoratedService()
|
|
|
|
{
|
|
|
|
return $this->decoratedService;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Sets the service class.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $class The service class
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setClass($class)
|
|
|
|
{
|
|
|
|
$this->class = $class;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-21 10:25:22 +01:00
|
|
|
* Gets the service class.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2013-11-10 17:06:47 +00:00
|
|
|
* @return string|null The service class
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getClass()
|
|
|
|
{
|
|
|
|
return $this->class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-05 08:47:14 +01:00
|
|
|
* Sets the arguments to pass to the service constructor/factory method.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param array $arguments An array of arguments
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setArguments(array $arguments)
|
|
|
|
{
|
|
|
|
$this->arguments = $arguments;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-03-04 14:26:00 +00:00
|
|
|
public function setProperties(array $properties)
|
|
|
|
{
|
|
|
|
$this->properties = $properties;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProperties()
|
|
|
|
{
|
|
|
|
return $this->properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setProperty($name, $value)
|
|
|
|
{
|
|
|
|
$this->properties[$name] = $value;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
2010-07-05 08:47:14 +01:00
|
|
|
* Adds an argument to pass to the service constructor/factory method.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param mixed $argument An argument
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function addArgument($argument)
|
|
|
|
{
|
|
|
|
$this->arguments[] = $argument;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-18 17:53:11 +00:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Sets a specific argument.
|
2011-01-18 17:53:11 +00:00
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param int $index
|
|
|
|
* @param mixed $argument
|
2011-01-18 17:53:11 +00:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2011-07-20 09:50:27 +01:00
|
|
|
*
|
2012-12-16 12:02:54 +00:00
|
|
|
* @throws OutOfBoundsException When the replaced argument does not exist
|
2011-01-18 17:53:11 +00:00
|
|
|
*/
|
2011-04-19 22:29:10 +01:00
|
|
|
public function replaceArgument($index, $argument)
|
2011-01-18 17:53:11 +00:00
|
|
|
{
|
|
|
|
if ($index < 0 || $index > count($this->arguments) - 1) {
|
2011-12-04 23:51:22 +00:00
|
|
|
throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
|
2011-01-18 17:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->arguments[$index] = $argument;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
2010-07-05 08:47:14 +01:00
|
|
|
* Gets the arguments to pass to the service constructor/factory method.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @return array The array of arguments
|
|
|
|
*/
|
|
|
|
public function getArguments()
|
|
|
|
{
|
|
|
|
return $this->arguments;
|
|
|
|
}
|
|
|
|
|
2011-04-28 10:26:10 +01:00
|
|
|
/**
|
|
|
|
* Gets an argument to pass to the service constructor/factory method.
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param int $index
|
2011-04-28 10:26:10 +01:00
|
|
|
*
|
|
|
|
* @return mixed The argument value
|
2011-07-20 09:50:27 +01:00
|
|
|
*
|
2012-12-16 12:02:54 +00:00
|
|
|
* @throws OutOfBoundsException When the argument does not exist
|
2011-04-28 10:26:10 +01:00
|
|
|
*/
|
|
|
|
public function getArgument($index)
|
|
|
|
{
|
|
|
|
if ($index < 0 || $index > count($this->arguments) - 1) {
|
2011-12-04 23:51:22 +00:00
|
|
|
throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
|
2011-04-28 10:26:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->arguments[$index];
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Sets the methods to call after service initialization.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param array $calls An array of method calls
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setMethodCalls(array $calls = array())
|
|
|
|
{
|
|
|
|
$this->calls = array();
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($calls as $call) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->addMethodCall($call[0], $call[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a method to call after service initialization.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $method The method name to call
|
|
|
|
* @param array $arguments An array of arguments to pass to the method call
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2011-07-20 09:50:27 +01:00
|
|
|
*
|
2011-11-30 13:11:00 +00:00
|
|
|
* @throws InvalidArgumentException on empty $method param
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function addMethodCall($method, array $arguments = array())
|
|
|
|
{
|
2011-11-30 13:11:00 +00:00
|
|
|
if (empty($method)) {
|
|
|
|
throw new InvalidArgumentException(sprintf('Method name cannot be empty.'));
|
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->calls[] = array($method, $arguments);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2010-08-30 12:51:19 +01:00
|
|
|
/**
|
|
|
|
* Removes a method to call after service initialization.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $method The method name to remove
|
2010-08-30 12:51:19 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-08-30 12:51:19 +01:00
|
|
|
*/
|
|
|
|
public function removeMethodCall($method)
|
|
|
|
{
|
|
|
|
foreach ($this->calls as $i => $call) {
|
|
|
|
if ($call[0] === $method) {
|
|
|
|
unset($this->calls[$i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the current definition has a given method to call after service initialization.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $method The method name to search for
|
2010-08-30 12:51:19 +01:00
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2010-08-30 12:51:19 +01:00
|
|
|
*/
|
|
|
|
public function hasMethodCall($method)
|
|
|
|
{
|
2011-02-04 18:10:13 +00:00
|
|
|
foreach ($this->calls as $call) {
|
2010-08-30 12:51:19 +01:00
|
|
|
if ($call[0] === $method) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Gets the methods to call after service initialization.
|
|
|
|
*
|
2012-11-01 15:08:59 +00:00
|
|
|
* @return array An array of method calls
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getMethodCalls()
|
|
|
|
{
|
|
|
|
return $this->calls;
|
|
|
|
}
|
|
|
|
|
2011-01-26 23:14:31 +00:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Sets tags for this definition.
|
2011-01-26 23:14:31 +00:00
|
|
|
*
|
|
|
|
* @param array $tags
|
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2011-01-26 23:14:31 +00:00
|
|
|
*/
|
|
|
|
public function setTags(array $tags)
|
|
|
|
{
|
|
|
|
$this->tags = $tags;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
2010-08-05 06:34:53 +01:00
|
|
|
* Returns all tags.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2010-08-05 06:34:53 +01:00
|
|
|
* @return array An array of tags
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2010-08-05 06:34:53 +01:00
|
|
|
public function getTags()
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2010-08-05 06:34:53 +01:00
|
|
|
return $this->tags;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-08-05 06:34:53 +01:00
|
|
|
* Gets a tag by name.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $name The tag name
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @return array An array of attributes
|
|
|
|
*/
|
2010-08-05 06:34:53 +01:00
|
|
|
public function getTag($name)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2011-01-05 13:42:38 +00:00
|
|
|
return isset($this->tags[$name]) ? $this->tags[$name] : array();
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-08-05 06:34:53 +01:00
|
|
|
* Adds a tag for this definition.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $name The tag name
|
|
|
|
* @param array $attributes An array of attributes
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2010-08-05 06:34:53 +01:00
|
|
|
public function addTag($name, array $attributes = array())
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2010-08-05 06:34:53 +01:00
|
|
|
$this->tags[$name][] = $attributes;
|
2010-05-06 12:25:53 +01:00
|
|
|
|
|
|
|
return $this;
|
2010-02-09 08:45:23 +00:00
|
|
|
}
|
|
|
|
|
2011-01-24 08:23:15 +00:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Whether this definition has a tag with the given name.
|
2011-01-24 08:23:15 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2011-01-24 08:23:15 +00:00
|
|
|
*/
|
|
|
|
public function hasTag($name)
|
|
|
|
{
|
|
|
|
return isset($this->tags[$name]);
|
|
|
|
}
|
|
|
|
|
2012-04-14 07:11:21 +01:00
|
|
|
/**
|
|
|
|
* Clears all tags for a given name.
|
|
|
|
*
|
|
|
|
* @param string $name The tag name
|
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2012-04-14 07:11:21 +01:00
|
|
|
*/
|
|
|
|
public function clearTag($name)
|
|
|
|
{
|
2015-11-26 17:53:25 +00:00
|
|
|
unset($this->tags[$name]);
|
2012-04-14 07:11:21 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2010-06-15 22:22:54 +01:00
|
|
|
/**
|
2010-08-05 06:34:53 +01:00
|
|
|
* Clears the tags for this definition.
|
2010-06-15 22:22:54 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-06-15 22:22:54 +01:00
|
|
|
*/
|
2010-08-05 06:34:53 +01:00
|
|
|
public function clearTags()
|
2010-06-15 22:22:54 +01:00
|
|
|
{
|
2010-08-05 06:34:53 +01:00
|
|
|
$this->tags = array();
|
2010-06-15 22:22:54 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Sets a file to require before creating the service.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $file A full pathname to include
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setFile($file)
|
2010-02-09 08:45:23 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->file = $file;
|
|
|
|
|
|
|
|
return $this;
|
2010-02-09 08:45:23 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Gets the file to require before creating the service.
|
|
|
|
*
|
2013-11-10 17:06:47 +00:00
|
|
|
* @return string|null The full pathname to include
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getFile()
|
|
|
|
{
|
|
|
|
return $this->file;
|
|
|
|
}
|
|
|
|
|
2015-06-15 03:41:59 +01:00
|
|
|
/**
|
|
|
|
* Sets if the service must be shared or not.
|
|
|
|
*
|
|
|
|
* @param bool $shared Whether the service must be shared or not
|
|
|
|
*
|
2016-12-29 21:47:05 +00:00
|
|
|
* @return $this
|
2015-06-15 03:41:59 +01:00
|
|
|
*/
|
|
|
|
public function setShared($shared)
|
|
|
|
{
|
|
|
|
$this->shared = (bool) $shared;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this service is shared.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isShared()
|
|
|
|
{
|
|
|
|
return $this->shared;
|
|
|
|
}
|
|
|
|
|
2010-12-29 19:12:24 +00:00
|
|
|
/**
|
|
|
|
* Sets the visibility of this service.
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param bool $boolean
|
2011-12-13 07:50:54 +00:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-12-29 19:12:24 +00:00
|
|
|
*/
|
|
|
|
public function setPublic($boolean)
|
|
|
|
{
|
2014-04-12 18:44:00 +01:00
|
|
|
$this->public = (bool) $boolean;
|
2010-12-29 19:12:24 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Whether this service is public facing.
|
2010-12-29 19:12:24 +00:00
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2010-12-29 19:12:24 +00:00
|
|
|
*/
|
|
|
|
public function isPublic()
|
|
|
|
{
|
|
|
|
return $this->public;
|
|
|
|
}
|
|
|
|
|
2013-03-29 23:21:12 +00:00
|
|
|
/**
|
|
|
|
* Sets the lazy flag of this service.
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param bool $lazy
|
2013-03-29 23:21:12 +00:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2013-03-29 23:21:12 +00:00
|
|
|
*/
|
|
|
|
public function setLazy($lazy)
|
|
|
|
{
|
2014-04-12 18:44:00 +01:00
|
|
|
$this->lazy = (bool) $lazy;
|
2013-03-29 23:21:12 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this service is lazy.
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2013-03-29 23:21:12 +00:00
|
|
|
*/
|
|
|
|
public function isLazy()
|
|
|
|
{
|
|
|
|
return $this->lazy;
|
|
|
|
}
|
|
|
|
|
2011-01-23 11:06:23 +00:00
|
|
|
/**
|
|
|
|
* Sets whether this definition is synthetic, that is not constructed by the
|
|
|
|
* container, but dynamically injected.
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param bool $boolean
|
2011-01-23 11:06:23 +00:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2011-01-23 11:06:23 +00:00
|
|
|
*/
|
|
|
|
public function setSynthetic($boolean)
|
|
|
|
{
|
2014-04-12 18:44:00 +01:00
|
|
|
$this->synthetic = (bool) $boolean;
|
2011-01-23 11:06:23 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this definition is synthetic, that is not constructed by the
|
|
|
|
* container, but dynamically injected.
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2011-01-23 11:06:23 +00:00
|
|
|
*/
|
|
|
|
public function isSynthetic()
|
|
|
|
{
|
|
|
|
return $this->synthetic;
|
|
|
|
}
|
|
|
|
|
2011-01-26 23:14:31 +00:00
|
|
|
/**
|
|
|
|
* Whether this definition is abstract, that means it merely serves as a
|
|
|
|
* template for other definitions.
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param bool $boolean
|
2011-01-26 23:14:31 +00:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2011-01-26 23:14:31 +00:00
|
|
|
*/
|
|
|
|
public function setAbstract($boolean)
|
|
|
|
{
|
2014-04-12 18:44:00 +01:00
|
|
|
$this->abstract = (bool) $boolean;
|
2011-01-26 23:14:31 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this definition is abstract, that means it merely serves as a
|
|
|
|
* template for other definitions.
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2011-01-26 23:14:31 +00:00
|
|
|
*/
|
|
|
|
public function isAbstract()
|
|
|
|
{
|
|
|
|
return $this->abstract;
|
|
|
|
}
|
|
|
|
|
2015-08-07 16:07:23 +01:00
|
|
|
/**
|
|
|
|
* Whether this definition is deprecated, that means it should not be called
|
|
|
|
* anymore.
|
|
|
|
*
|
2015-08-10 13:35:12 +01:00
|
|
|
* @param bool $status
|
|
|
|
* @param string $template Template message to use if the definition is deprecated
|
2015-08-07 16:07:23 +01:00
|
|
|
*
|
2016-12-29 21:47:05 +00:00
|
|
|
* @return $this
|
2015-08-07 16:07:23 +01:00
|
|
|
*
|
2015-08-10 13:35:12 +01:00
|
|
|
* @throws InvalidArgumentException When the message template is invalid.
|
2015-08-07 16:07:23 +01:00
|
|
|
*/
|
2015-08-10 13:35:12 +01:00
|
|
|
public function setDeprecated($status = true, $template = null)
|
2015-08-07 16:07:23 +01:00
|
|
|
{
|
2015-08-10 13:35:12 +01:00
|
|
|
if (null !== $template) {
|
|
|
|
if (preg_match('#[\r\n]|\*/#', $template)) {
|
|
|
|
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false === strpos($template, '%service_id%')) {
|
|
|
|
throw new InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->deprecationTemplate = $template;
|
|
|
|
}
|
|
|
|
|
2015-08-07 16:07:23 +01:00
|
|
|
$this->deprecated = (bool) $status;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this definition is deprecated, that means it should not be called
|
|
|
|
* anymore.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isDeprecated()
|
|
|
|
{
|
|
|
|
return $this->deprecated;
|
|
|
|
}
|
|
|
|
|
2015-08-10 13:35:12 +01:00
|
|
|
/**
|
|
|
|
* Message to use if this definition is deprecated.
|
|
|
|
*
|
|
|
|
* @param string $id Service id relying on this definition
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDeprecationMessage($id)
|
|
|
|
{
|
|
|
|
return str_replace('%service_id%', $id, $this->deprecationTemplate);
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Sets a configurator to call after the service is fully initialized.
|
|
|
|
*
|
2016-06-26 20:09:06 +01:00
|
|
|
* @param string|array $configurator A PHP callable
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2016-12-26 07:50:27 +00:00
|
|
|
* @return $this
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2016-06-26 20:09:06 +01:00
|
|
|
public function setConfigurator($configurator)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2016-06-26 20:09:06 +01:00
|
|
|
if (is_string($configurator) && strpos($configurator, '::') !== false) {
|
|
|
|
$configurator = explode('::', $configurator, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->configurator = $configurator;
|
2010-05-06 12:25:53 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the configurator to call after the service is fully initialized.
|
|
|
|
*
|
2013-11-10 17:06:47 +00:00
|
|
|
* @return callable|null The PHP callable to call
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getConfigurator()
|
|
|
|
{
|
|
|
|
return $this->configurator;
|
|
|
|
}
|
2015-08-24 02:36:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets types that will default to this definition.
|
|
|
|
*
|
|
|
|
* @param string[] $types
|
|
|
|
*
|
2016-12-29 21:47:05 +00:00
|
|
|
* @return $this
|
2015-08-24 02:36:41 +01:00
|
|
|
*/
|
|
|
|
public function setAutowiringTypes(array $types)
|
|
|
|
{
|
|
|
|
$this->autowiringTypes = array();
|
|
|
|
|
|
|
|
foreach ($types as $type) {
|
|
|
|
$this->autowiringTypes[$type] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the definition autowired?
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isAutowired()
|
|
|
|
{
|
2016-10-05 21:46:29 +01:00
|
|
|
return !empty($this->autowiredMethods);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets autowired methods.
|
|
|
|
*
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getAutowiredMethods()
|
|
|
|
{
|
|
|
|
return $this->autowiredMethods;
|
2015-08-24 02:36:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets autowired.
|
|
|
|
*
|
2016-10-05 21:46:29 +01:00
|
|
|
* Allowed values:
|
|
|
|
* - true: constructor autowiring, same as $this->setAutowiredMethods(array('__construct'))
|
|
|
|
* - false: no autowiring, same as $this->setAutowiredMethods(array())
|
|
|
|
*
|
2016-10-05 21:47:52 +01:00
|
|
|
* @param bool $autowired
|
2015-08-24 02:36:41 +01:00
|
|
|
*
|
2016-12-29 21:47:05 +00:00
|
|
|
* @return $this
|
2015-08-24 02:36:41 +01:00
|
|
|
*/
|
|
|
|
public function setAutowired($autowired)
|
|
|
|
{
|
2016-10-05 21:46:29 +01:00
|
|
|
$this->autowiredMethods = $autowired ? array('__construct') : array();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets autowired methods.
|
|
|
|
*
|
|
|
|
* Example of allowed value:
|
|
|
|
* - array('__construct', 'set*', 'initialize'): autowire whitelisted methods only
|
|
|
|
*
|
|
|
|
* @param string[] $autowiredMethods
|
|
|
|
*
|
|
|
|
* @return Definition The current instance
|
|
|
|
*/
|
|
|
|
public function setAutowiredMethods(array $autowiredMethods)
|
|
|
|
{
|
|
|
|
$this->autowiredMethods = $autowiredMethods;
|
2015-08-24 02:36:41 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets autowiring types that will default to this definition.
|
|
|
|
*
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getAutowiringTypes()
|
|
|
|
{
|
|
|
|
return array_keys($this->autowiringTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a type that will default to this definition.
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
2016-12-29 21:47:05 +00:00
|
|
|
* @return $this
|
2015-08-24 02:36:41 +01:00
|
|
|
*/
|
|
|
|
public function addAutowiringType($type)
|
|
|
|
{
|
|
|
|
$this->autowiringTypes[$type] = true;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a type.
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
2016-12-29 21:47:05 +00:00
|
|
|
* @return $this
|
2015-08-24 02:36:41 +01:00
|
|
|
*/
|
|
|
|
public function removeAutowiringType($type)
|
|
|
|
{
|
|
|
|
unset($this->autowiringTypes[$type]);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will this definition default for the given type?
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasAutowiringType($type)
|
|
|
|
{
|
|
|
|
return isset($this->autowiringTypes[$type]);
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
}
|