Skip to content

Commit

Permalink
[DI] Add a deprecated status to definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Taluu committed Sep 24, 2015
1 parent 5f2acfd commit 4b6fab0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -829,6 +830,36 @@ public function isAbstract()
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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ public function testSetIsAbstract()
$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
Expand Down

0 comments on commit 4b6fab0

Please sign in to comment.