[DependencyInjection] Add ability to clear tags by name.
This commit is contained in:
parent
d2fd9ce7b9
commit
80f96b7a1b
@ -451,6 +451,22 @@ class Definition
|
||||
return isset($this->tags[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all tags for a given name.
|
||||
*
|
||||
* @param string $name The tag name
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
public function clearTag($name)
|
||||
{
|
||||
if (isset($this->tags[$name])) {
|
||||
unset($this->tags[$name]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the tags for this definition.
|
||||
*
|
||||
|
@ -187,6 +187,25 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::clearTags
|
||||
*/
|
||||
public function testClearTag()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface');
|
||||
$def->addTag('1foo1', array('foo1' => 'bar1'));
|
||||
$def->addTag('2foo2', array('foo2' => 'bar2'));
|
||||
$def->addTag('3foo3', array('foo3' => 'bar3'));
|
||||
$def->clearTag('2foo2');
|
||||
$this->assertTrue($def->hasTag('1foo1'));
|
||||
$this->assertFalse($def->hasTag('2foo2'));
|
||||
$this->assertTrue($def->hasTag('3foo3'));
|
||||
$def->clearTag('1foo1');
|
||||
$this->assertFalse($def->hasTag('1foo1'));
|
||||
$this->assertTrue($def->hasTag('3foo3'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::addTag
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::getTag
|
||||
|
Reference in New Issue
Block a user