Explorar el Código

adds hasTag() to Definition

Johannes M. Schmitt hace 14 años
padre
commit
e55f150fb7

+ 12 - 0
src/Symfony/Component/DependencyInjection/Definition.php

@@ -296,6 +296,18 @@ class Definition
         return $this;
     }
 
+    /**
+     * Whether this definition has a tag with the given name
+     *
+     * @param string $name
+     *
+     * @return Boolean
+     */
+    public function hasTag($name)
+    {
+        return isset($this->tags[$name]);
+    }
+
     /**
      * Clears the tags for this definition.
      *

+ 3 - 0
tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php

@@ -164,12 +164,15 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
      * @covers Symfony\Component\DependencyInjection\Definition::addTag
      * @covers Symfony\Component\DependencyInjection\Definition::getTag
      * @covers Symfony\Component\DependencyInjection\Definition::getTags
+     * @covers Symfony\Component\DependencyInjection\Definition::hasTag
      */
     public function testTags()
     {
         $def = new Definition('stdClass');
         $this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined');
+        $this->assertFalse($def->hasTag('foo'));
         $this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface');
+        $this->assertTrue($def->hasTag('foo'));
         $this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name');
         $def->addTag('foo', array('foo' => 'bar'));
         $this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times');