mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Fix for #163. Makes Reflection on Route-objects more robust.
This commit is contained in:
parent
905ac99eb5
commit
8d771a925f
@ -16,7 +16,6 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|||||||
use Nelmio\ApiDocBundle\Parser\ParserInterface;
|
use Nelmio\ApiDocBundle\Parser\ParserInterface;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
use Symfony\Component\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
use Symfony\Component\Routing\RouteCollection;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Nelmio\ApiDocBundle\Util\DocCommentExtractor;
|
use Nelmio\ApiDocBundle\Util\DocCommentExtractor;
|
||||||
@ -73,7 +72,7 @@ class ApiDocExtractor
|
|||||||
*/
|
*/
|
||||||
public function getRoutes()
|
public function getRoutes()
|
||||||
{
|
{
|
||||||
return $this->router->getRouteCollection()->getIterator();
|
return $this->router->getRouteCollection()->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,7 +90,9 @@ class ApiDocExtractor
|
|||||||
* - annotation
|
* - annotation
|
||||||
* - resource
|
* - 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
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -101,9 +102,11 @@ class ApiDocExtractor
|
|||||||
$resources = array();
|
$resources = array();
|
||||||
|
|
||||||
foreach ($routes as $route) {
|
foreach ($routes as $route) {
|
||||||
if ($route instanceof RouteCollection) {
|
if (!($route instanceof RouterInterface)) {
|
||||||
$array = array_merge($array, $this->extractAnnotations($route->getIterator()));
|
throw new \InvalidArgumentException(sprintf('All elements of $routes have to implement RouteInterface. "%s" given', gettype($route)));
|
||||||
} elseif ($method = $this->getReflectionMethod($route->getDefault('_controller'))) {
|
}
|
||||||
|
|
||||||
|
if ($method = $this->getReflectionMethod($route->getDefault('_controller'))) {
|
||||||
if ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS)) {
|
if ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS)) {
|
||||||
if ($annotation->isResource()) {
|
if ($annotation->isResource()) {
|
||||||
// remove format from routes used for resource grouping
|
// remove format from routes used for resource grouping
|
||||||
|
Loading…
x
Reference in New Issue
Block a user