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 ;
2011-03-11 13:50:46 +00:00
private $factoryClass ;
private $factoryMethod ;
private $factoryService ;
2015-06-15 03:41:59 +01:00
private $shared = true ;
2015-08-10 13:35:12 +01:00
private $deprecated = false ;
2017-05-04 18:21:54 +01:00
private $deprecationTemplate ;
2013-11-10 17:06:47 +00:00
private $scope = ContainerInterface :: SCOPE_CONTAINER ;
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 $synchronized = false ;
private $lazy = false ;
2013-09-12 11:15:48 +01:00
private $decoratedService ;
2015-08-24 02:36:41 +01:00
private $autowired = false ;
private $autowiringTypes = array ();
2011-03-11 13:50:46 +00:00
2017-05-04 18:21:54 +01:00
private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.' ;
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 ;
}
2011-02-02 17:22:27 +00:00
/**
* Sets the name of the class that acts as a factory using the factory method ,
* which will be invoked statically .
*
2012-05-15 21:19:31 +01:00
* @ param string $factoryClass The factory class name
2011-02-02 17:22:27 +00:00
*
2016-12-26 07:50:27 +00:00
* @ return $this
2011-07-20 09:50:27 +01:00
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.6 , to be removed in 3.0 .
2011-02-02 17:22:27 +00:00
*/
public function setFactoryClass ( $factoryClass )
{
2015-06-07 07:33:05 +01:00
@ trigger_error ( sprintf ( '%s(%s) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.' , __METHOD__ , $factoryClass ), E_USER_DEPRECATED );
2014-11-29 13:23:27 +00:00
2011-02-02 17:22:27 +00:00
$this -> factoryClass = $factoryClass ;
return $this ;
}
/**
* Gets the factory class .
*
2013-11-10 17:06:47 +00:00
* @ return string | null The factory class name
2011-07-20 09:50:27 +01:00
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.6 , to be removed in 3.0 .
2011-02-02 17:22:27 +00:00
*/
2015-01-06 18:57:38 +00:00
public function getFactoryClass ( $triggerDeprecationError = true )
2011-02-02 17:22:27 +00:00
{
2015-01-06 18:57:38 +00:00
if ( $triggerDeprecationError ) {
2015-06-07 07:33:05 +01:00
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.6 and will be removed in 3.0.' , E_USER_DEPRECATED );
2015-01-06 18:57:38 +00:00
}
2014-12-21 11:39:54 +00:00
2011-02-02 17:22:27 +00:00
return $this -> factoryClass ;
}
2010-05-06 12:25:53 +01:00
/**
2010-07-05 08:47:14 +01:00
* Sets the factory method able to create an instance of this class .
2010-05-06 12:25:53 +01:00
*
2012-05-15 21:19:31 +01:00
* @ param string $factoryMethod The factory method name
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
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.6 , to be removed in 3.0 .
2010-05-06 12:25:53 +01:00
*/
2011-02-02 17:22:27 +00:00
public function setFactoryMethod ( $factoryMethod )
2010-02-09 08:45:23 +00:00
{
2015-06-07 07:33:05 +01:00
@ trigger_error ( sprintf ( '%s(%s) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.' , __METHOD__ , $factoryMethod ), E_USER_DEPRECATED );
2014-11-29 13:23:27 +00:00
2011-02-02 17:22:27 +00:00
$this -> factoryMethod = $factoryMethod ;
2010-05-06 12:25:53 +01:00
return $this ;
}
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 ) {
2014-03-31 16:58:40 +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
}
/**
2017-01-21 16:37:56 +00:00
* Gets the service that this service is decorating .
2013-09-12 11:15:48 +01:00
*
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
/**
2010-07-05 08:47:14 +01:00
* Gets the factory method .
2010-05-06 12:25:53 +01:00
*
2013-11-10 17:06:47 +00:00
* @ return string | null The factory method name
2011-07-20 09:50:27 +01:00
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.6 , to be removed in 3.0 .
2010-05-06 12:25:53 +01:00
*/
2015-01-06 18:57:38 +00:00
public function getFactoryMethod ( $triggerDeprecationError = true )
2010-05-06 12:25:53 +01:00
{
2015-01-06 18:57:38 +00:00
if ( $triggerDeprecationError ) {
2015-06-07 07:33:05 +01:00
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.6 and will be removed in 3.0.' , E_USER_DEPRECATED );
2015-01-06 18:57:38 +00:00
}
2014-12-21 11:39:54 +00:00
2010-07-05 08:47:14 +01:00
return $this -> factoryMethod ;
2010-05-06 12:25:53 +01:00
}
2010-07-03 23:35:39 +01:00
/**
2011-02-02 17:22:27 +00:00
* Sets the name of the service that acts as a factory using the factory method .
2010-07-03 23:35:39 +01:00
*
2010-07-04 17:56:48 +01:00
* @ param string $factoryService The factory service id
*
2016-12-26 07:50:27 +00:00
* @ return $this
2011-07-20 09:50:27 +01:00
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.6 , to be removed in 3.0 .
2010-07-03 23:35:39 +01:00
*/
2016-01-27 11:46:36 +00:00
public function setFactoryService ( $factoryService , $triggerDeprecationError = true )
2010-07-03 23:35:39 +01:00
{
2016-01-27 11:46:36 +00:00
if ( $triggerDeprecationError ) {
@ trigger_error ( sprintf ( '%s(%s) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.' , __METHOD__ , $factoryService ), E_USER_DEPRECATED );
}
2014-11-29 13:23:27 +00:00
2010-07-03 23:35:39 +01:00
$this -> factoryService = $factoryService ;
return $this ;
}
/**
2010-07-04 17:56:48 +01:00
* Gets the factory service id .
2010-07-03 23:35:39 +01:00
*
2013-11-10 17:06:47 +00:00
* @ return string | null The factory service id
2011-07-20 09:50:27 +01:00
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.6 , to be removed in 3.0 .
2010-07-03 23:35:39 +01:00
*/
2015-01-06 18:57:38 +00:00
public function getFactoryService ( $triggerDeprecationError = true )
2010-07-03 23:35:39 +01:00
{
2015-01-06 18:57:38 +00:00
if ( $triggerDeprecationError ) {
2015-06-07 07:33:05 +01:00
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.6 and will be removed in 3.0.' , E_USER_DEPRECATED );
2015-01-06 18:57:38 +00:00
}
2014-12-21 11:39:54 +00:00
2010-07-04 17:56:48 +01:00
return $this -> factoryService ;
2010-07-03 23:35:39 +01:00
}
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 ;
}
2017-08-08 18:11:20 +01:00
/**
* Sets the properties to define when creating the service .
*
* @ param array $properties
*
* @ return $this
*/
2011-03-04 14:26:00 +00:00
public function setProperties ( array $properties )
{
$this -> properties = $properties ;
return $this ;
}
2017-08-08 18:11:20 +01:00
/**
* Gets the properties to define when creating the service .
*
* @ return array
*/
2011-03-04 14:26:00 +00:00
public function getProperties ()
{
return $this -> properties ;
}
2017-08-08 18:11:20 +01:00
/**
* Sets a specific property .
*
* @ param string $name
* @ param mixed $value
*
* @ return $this
*/
2011-03-04 14:26:00 +00:00
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
/**
2017-08-08 18:11:20 +01:00
* Replaces 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
{
2017-01-26 10:48:39 +00:00
if ( 0 === count ( $this -> arguments )) {
throw new OutOfBoundsException ( 'Cannot replace arguments if none have been configured yet.' );
}
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 )) {
2017-04-04 19:32:29 +01:00
throw new InvalidArgumentException ( 'Method name cannot be empty.' );
2011-11-30 13:11:00 +00:00
}
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-05-06 12:25:53 +01:00
/**
2014-12-21 17:00:50 +00:00
* Sets the scope of the service .
2010-05-06 12:25:53 +01:00
*
2012-05-15 21:19:31 +01:00
* @ param string $scope Whether the service must be shared or not
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
*
2015-06-15 03:41:59 +01:00
* @ deprecated since version 2.8 , to be removed in 3.0 .
2010-05-06 12:25:53 +01:00
*/
2015-06-15 03:41:59 +01:00
public function setScope ( $scope , $triggerDeprecationError = true )
2010-05-06 12:25:53 +01:00
{
2015-06-15 03:41:59 +01:00
if ( $triggerDeprecationError ) {
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.' , E_USER_DEPRECATED );
}
2015-06-24 20:50:08 +01:00
if ( ContainerInterface :: SCOPE_PROTOTYPE === $scope ) {
$this -> setShared ( false );
}
2011-01-17 22:28:59 +00:00
$this -> scope = $scope ;
2010-05-06 12:25:53 +01:00
return $this ;
}
/**
2014-12-21 17:00:50 +00:00
* Returns the scope of the service .
2010-05-06 12:25:53 +01:00
*
2011-01-17 22:28:59 +00:00
* @ return string
2011-07-20 09:50:27 +01:00
*
2015-06-15 03:41:59 +01:00
* @ deprecated since version 2.8 , to be removed in 3.0 .
2010-05-06 12:25:53 +01:00
*/
2015-06-15 03:41:59 +01:00
public function getScope ( $triggerDeprecationError = true )
2010-05-06 12:25:53 +01:00
{
2015-06-15 03:41:59 +01:00
if ( $triggerDeprecationError ) {
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.' , E_USER_DEPRECATED );
}
2011-01-17 22:28:59 +00:00
return $this -> scope ;
2010-05-06 12:25:53 +01:00
}
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-02-06 20:42:01 +00:00
/**
* Sets the synchronized flag of this service .
*
2014-11-30 13:33:44 +00:00
* @ param bool $boolean
2013-02-06 20:42:01 +00:00
*
2016-12-26 07:50:27 +00:00
* @ return $this
2013-02-06 20:42:01 +00:00
*
2015-01-06 16:17:37 +00:00
* @ deprecated since version 2.7 , will be removed in 3.0 .
2013-02-06 20:42:01 +00:00
*/
2015-01-06 16:17:37 +00:00
public function setSynchronized ( $boolean , $triggerDeprecationError = true )
2013-02-06 20:42:01 +00:00
{
2015-01-06 16:17:37 +00:00
if ( $triggerDeprecationError ) {
2015-06-07 07:33:05 +01:00
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.7 and will be removed in 3.0.' , E_USER_DEPRECATED );
2015-01-06 16:17:37 +00:00
}
2014-04-12 18:44:00 +01:00
$this -> synchronized = ( bool ) $boolean ;
2013-02-06 20:42:01 +00:00
return $this ;
}
/**
* Whether this service is synchronized .
*
2014-04-16 11:30:19 +01:00
* @ return bool
2013-02-06 20:42:01 +00:00
*
2015-01-06 16:17:37 +00:00
* @ deprecated since version 2.7 , will be removed in 3.0 .
2013-02-06 20:42:01 +00:00
*/
2015-01-06 16:17:37 +00:00
public function isSynchronized ( $triggerDeprecationError = true )
2013-02-06 20:42:01 +00:00
{
2015-01-06 16:17:37 +00:00
if ( $triggerDeprecationError ) {
2015-06-07 07:33:05 +01:00
@ trigger_error ( 'The ' . __METHOD__ . ' method is deprecated since version 2.7 and will be removed in 3.0.' , E_USER_DEPRECATED );
2015-01-06 16:17:37 +00:00
}
2013-02-06 20:42:01 +00:00
return $this -> synchronized ;
}
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 )
{
2017-05-04 18:21:54 +01:00
return str_replace ( '%service_id%' , $id , $this -> deprecationTemplate ? : self :: $defaultDeprecationTemplate );
2015-08-10 13:35:12 +01:00
}
2010-05-06 12:25:53 +01:00
/**
* Sets a configurator to call after the service is fully initialized .
*
2012-09-07 23:56:45 +01:00
* @ param callable $callable 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
*/
public function setConfigurator ( $callable )
{
$this -> configurator = $callable ;
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 ()
{
return $this -> autowired ;
}
/**
2017-08-08 22:33:02 +01:00
* Enables / disables autowiring .
2015-08-24 02:36:41 +01:00
*
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 )
{
$this -> autowired = $autowired ;
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
}