Add a little bit more flexibility to ApiDocExtractor

This commit is contained in:
Benjamin Bender 2013-03-22 14:05:14 +01:00
parent 5daf8ac5f6
commit 89aec4bfd3

View File

@ -68,11 +68,21 @@ class ApiDocExtractor
* You can extend this method if you don't want all the routes * You can extend this method if you don't want all the routes
* to be included. * to be included.
* *
* @return array of Route * @return \Traverseable Iterator for a RouteCollection
*/ */
public function getRoutes() public function getRoutes()
{ {
return $this->router->getRouteCollection()->all(); return $this->router->getRouteCollection()->getIterator();
}
/**
* Extracts annotations from all known routes
*
* @return array
*/
public function all()
{
return $this->extractAnnotations($this->getRoutes());
} }
/** /**
@ -80,14 +90,16 @@ class ApiDocExtractor
* - annotation * - annotation
* - resource * - resource
* *
* @param \Traversable $routes The routes for which the annotations should be extracted
*
* @return array * @return array
*/ */
public function all() public function extractAnnotations(\Traversable $routes)
{ {
$array = array(); $array = array();
$resources = array(); $resources = array();
foreach ($this->getRoutes() as $route) { foreach ($routes as $route) {
if ($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()) {