Permalink
Browse files

[DependencyInjection] Add ability to clear tags by name.

  • Loading branch information...
1 parent d2fd9ce commit 80f96b7a1b5cc8986ba640fa25b6ec96a35a5528 Drak committed Apr 14, 2012
@@ -452,6 +452,22 @@ public function hasTag($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.
*
* @return Definition The current instance
@@ -188,6 +188,25 @@ public function testClearTags()
}
/**
+ * @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
* @covers Symfony\Component\DependencyInjection\Definition::getTags

0 comments on commit 80f96b7

Please sign in to comment.