diff --git a/EventListener/RouteAnnotationEventListener.php b/EventListener/RouteAnnotationEventListener.php index f8136ca2..5e5f2d02 100644 --- a/EventListener/RouteAnnotationEventListener.php +++ b/EventListener/RouteAnnotationEventListener.php @@ -131,8 +131,23 @@ public function getOptions($name, Route $route) } } - if (!filter_var($option, FILTER_VALIDATE_BOOLEAN) && !is_array($option)) { - throw new \InvalidArgumentException('the sitemap option must be "true" or an array of parameters'); + if (!is_array($option) && !is_bool($option)) { + $bool = filter_var($option, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + + if (null === $bool) { + throw new \InvalidArgumentException( + sprintf( + 'The sitemap option must be of type "boolean" or "array", got "%s"', + $option + ) + ); + } + + $option = $bool; + } + + if (!$option) { + return null; } $options = $this->defaults; diff --git a/Tests/EventListener/RouteAnnotationEventListenerTest.php b/Tests/EventListener/RouteAnnotationEventListenerTest.php index 40168ead..fb21db7e 100644 --- a/Tests/EventListener/RouteAnnotationEventListenerTest.php +++ b/Tests/EventListener/RouteAnnotationEventListenerTest.php @@ -30,21 +30,20 @@ public function testNoAnnotation() } /** - * test "sitemap"=false annotation + * test "sitemap"="anything" annotation */ - public function testInvalidSitemapFalse() + public function testInvalidSitemapArbitrary() { $this->setExpectedException('InvalidArgumentException'); - $this->assertEquals(-1, $this->getListener()->getOptions('route1', $this->getRoute(false)), 'sitemap = false throws an exception'); + $this->assertEquals(-1, $this->getListener()->getOptions('route1', $this->getRoute('anything')), 'sitemap = "anything" throws an exception'); } /** - * test "sitemap"="anything" annotation + * test "sitemap"=false annotation */ - public function testInvalidSitemapArbitrary() + public function testSitemapFalse() { - $this->setExpectedException('InvalidArgumentException'); - $this->assertEquals(-1, $this->getListener()->getOptions('route1', $this->getRoute('anything')), 'sitemap = "anything" throws an exception'); + $this->assertNull($this->getListener()->getOptions('route1', $this->getRoute(false)), 'sitemap = false returns null'); } /**