Skip to content

Commit 6269866

Browse files
committed
Merge pull request #190 from FriendsOfSymfony/tag-handler-hastags
Adding TagHandler::hasTags method
2 parents 93803c6 + 0703555 commit 6269866

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Handler/TagHandler.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,19 @@ public function getTagsHeaderValue()
7777
}
7878

7979
/**
80-
* Add tags to be sent.
80+
* Check whether the tag handler has any tags to set on the response.
8181
*
82-
* This must be called before any response is sent to the client.
82+
* @return bool True if this handler will set at least one tag.
83+
*/
84+
public function hasTags()
85+
{
86+
return 0 < count($this->tags);
87+
}
88+
89+
/**
90+
* Add tags to be set on the response.
91+
*
92+
* This must be called before any HTTP response is sent to the client.
8393
*
8494
* @param array $tags List of tags to add.
8595
*

tests/Unit/Handler/TagHandlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ public function testTagResponse()
9090
->getMock();
9191

9292
$tagHandler = new TagHandler($cacheInvalidator);
93+
$this->assertFalse($tagHandler->hasTags());
9394
$tagHandler->addTags(array('post-1', 'test,post'));
95+
$this->assertTrue($tagHandler->hasTags());
9496
$this->assertEquals('post-1,test_post', $tagHandler->getTagsHeaderValue());
9597
}
9698
}

0 commit comments

Comments
 (0)