8000 [DependencyInjection] Add ability to clear tags by name. · cbaudoux/symfony@80f96b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80f96b7

Browse files
author
Drak
committed
[DependencyInjection] Add ability to clear tags by name.
1 parent d2fd9ce commit 80f96b7

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,22 @@ public function hasTag($name)
451451
return isset($this->tags[$name]);
452452
}
453453

454+
/**
455+
* Clears all tags for a given name.
456+
*
457+
* @param string $name The tag name
458+
*
459+
* @return Definition
460+
*/
461+
public function clearTag($name)
462+
{
463+
if (isset($this->tags[$name])) {
464+
unset($this->tags[$name]);
465+
}
466+
467+
return $this;
468+
}
469+
454470
/**
455471
* Clears the tags for this definition.
456472
*

src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ public function testClearTags()
187187
$this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags');
188188
}
189189

190+
/**
191+
* @covers Symfony\Component\DependencyInjection\Definition::clearTags
192+
*/
193+
public function testClearTag()
194+
{
195+
$def = new Definition('stdClass');
196+
$this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface');
197+
$def->addTag('1foo1', array('foo1' => 'bar1'));
198+
$def->addTag('2foo2', array('foo2' => 'bar2'));
199+
$def->addTag('3foo3', array('foo3' => 'bar3'));
200+
$def->clearTag('2foo2');
201+
$this->assertTrue($def->hasTag('1foo1'));
202+
$this->assertFalse($def->hasTag('2foo2'));
203+
$this->assertTrue($def->hasTag('3foo3'));
204+
$def->clearTag('1foo1');
205+
$this->assertFalse($def->hasTag('1foo1'));
206+
$this->assertTrue($def->hasTag('3foo3'));
207+
}
208+
190209
/**
191210
* @covers Symfony\Component\DependencyInjection\Definition::addTag
192211
* @covers Symfony\Component\DependencyInjection\Definition::getTag

0 commit comments

Comments
 (0)
0