From 8d771a925fd07f3e81d639701d5179002c5211bc Mon Sep 17 00:00:00 2001 From: Benjamin Bender Date: Wed, 27 Mar 2013 19:36:42 +0100 Subject: [PATCH 1/4] Fix for #163. Makes Reflection on Route-objects more robust. --- Extractor/ApiDocExtractor.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 5a7dffc..142717c 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -16,7 +16,6 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Nelmio\ApiDocBundle\Parser\ParserInterface; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\Routing\RouteCollection; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Nelmio\ApiDocBundle\Util\DocCommentExtractor; @@ -73,7 +72,7 @@ class ApiDocExtractor */ public function getRoutes() { - return $this->router->getRouteCollection()->getIterator(); + return $this->router->getRouteCollection()->all(); } /** @@ -91,7 +90,9 @@ class ApiDocExtractor * - annotation * - resource * - * @param \Traversable $routes The routes for which the annotations should be extracted + * @param \Traversable $routes \Traverseable of Route-objects for which the annotations should be extracted + * + * @throws \InvalidArgumentException if one element of \Traversable does not implement RouteInterface * * @return array */ @@ -101,9 +102,11 @@ class ApiDocExtractor $resources = array(); foreach ($routes as $route) { - if ($route instanceof RouteCollection) { - $array = array_merge($array, $this->extractAnnotations($route->getIterator())); - } elseif ($method = $this->getReflectionMethod($route->getDefault('_controller'))) { + if (!($route instanceof RouterInterface)) { + throw new \InvalidArgumentException(sprintf('All elements of $routes have to implement RouteInterface. "%s" given', gettype($route))); + } + + if ($method = $this->getReflectionMethod($route->getDefault('_controller'))) { if ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS)) { if ($annotation->isResource()) { // remove format from routes used for resource grouping From 28b7fa7d0ee1d448051155e1edae361bde521497 Mon Sep 17 00:00:00 2001 From: Benjamin Bender Date: Wed, 27 Mar 2013 22:28:26 +0100 Subject: [PATCH 2/4] Fixes typehint for Route --- Extractor/ApiDocExtractor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 142717c..7974ae6 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -92,7 +92,7 @@ class ApiDocExtractor * * @param \Traversable $routes \Traverseable of Route-objects for which the annotations should be extracted * - * @throws \InvalidArgumentException if one element of \Traversable does not implement RouteInterface + * @throws \InvalidArgumentException if one element of \Traversable does not implement Route * * @return array */ @@ -102,8 +102,8 @@ class ApiDocExtractor $resources = array(); foreach ($routes as $route) { - if (!($route instanceof RouterInterface)) { - throw new \InvalidArgumentException(sprintf('All elements of $routes have to implement RouteInterface. "%s" given', gettype($route))); + if (!($route instanceof Route)) { + throw new \InvalidArgumentException(sprintf('All elements of $routes must be instances of Route. "%s" given', gettype($route))); } if ($method = $this->getReflectionMethod($route->getDefault('_controller'))) { From fd17706118852d29513379358b7c9d7b8abb9e0d Mon Sep 17 00:00:00 2001 From: Benjamin Bender Date: Wed, 27 Mar 2013 23:19:16 +0100 Subject: [PATCH 3/4] Cleanup docbook --- Extractor/ApiDocExtractor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 7974ae6..32de0d4 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -90,13 +90,13 @@ class ApiDocExtractor * - annotation * - resource * - * @param \Traversable $routes \Traverseable of Route-objects for which the annotations should be extracted + * @param array $routes array of Route-objects for which the annotations should be extracted * - * @throws \InvalidArgumentException if one element of \Traversable does not implement Route + * @throws \InvalidArgumentException if one element of the input isnt an instance of Route * * @return array */ - public function extractAnnotations(\Traversable $routes) + public function extractAnnotations(array $routes) { $array = array(); $resources = array(); From 11a56251a42d3fd3a08cb2f3379f85348b12c458 Mon Sep 17 00:00:00 2001 From: Benjamin Bender Date: Wed, 27 Mar 2013 23:21:04 +0100 Subject: [PATCH 4/4] Remove extra braces --- Extractor/ApiDocExtractor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 32de0d4..690d8d5 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -102,7 +102,7 @@ class ApiDocExtractor $resources = array(); foreach ($routes as $route) { - if (!($route instanceof Route)) { + if (!$route instanceof Route) { throw new \InvalidArgumentException(sprintf('All elements of $routes must be instances of Route. "%s" given', gettype($route))); }