[DI] Add a deprecated status to definitions
This commit is contained in:
parent
5f2acfd4c7
commit
4b6fab0b2c
@ -38,6 +38,7 @@ class Definition
|
||||
private $public = true;
|
||||
private $synthetic = false;
|
||||
private $abstract = false;
|
||||
private $deprecated = false;
|
||||
private $synchronized = false;
|
||||
private $lazy = false;
|
||||
private $decoratedService;
|
||||
@ -829,6 +830,36 @@ class Definition
|
||||
return $this->abstract;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this definition is deprecated, that means it should not be called
|
||||
* anymore.
|
||||
*
|
||||
* @param bool $status
|
||||
*
|
||||
* @return Definition the current instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDeprecated($status = true)
|
||||
{
|
||||
$this->deprecated = (bool) $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this definition is deprecated, that means it should not be called
|
||||
* anymore.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function isDeprecated()
|
||||
{
|
||||
return $this->deprecated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a configurator to call after the service is fully initialized.
|
||||
*
|
||||
|
@ -233,6 +233,18 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($def->isAbstract(), '->isAbstract() returns true if the instance must not be public.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::setDeprecated
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::isDeprecated
|
||||
*/
|
||||
public function testSetIsDeprecated()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertFalse($def->isDeprecated(), '->isDeprecated() returns false by default');
|
||||
$this->assertSame($def, $def->setDeprecated(true), '->setDeprecated() implements a fluent interface');
|
||||
$this->assertTrue($def->isDeprecated(), '->isDeprecated() returns true if the instance should not be used anymore.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::setConfigurator
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::getConfigurator
|
||||
|
Reference in New Issue
Block a user