Adding possibilty to name resource

This commit is contained in:
Florent DUBOST 2013-10-11 15:44:31 +02:00
parent 7317c7aa81
commit 56fdd4e64c
2 changed files with 18 additions and 6 deletions

View File

@ -78,7 +78,7 @@ class ApiDoc
/** /**
* @var Boolean * @var Boolean
*/ */
private $isResource = false; private $resource = false;
/** /**
* @var string * @var string
@ -132,7 +132,7 @@ class ApiDoc
public function __construct(array $data) public function __construct(array $data)
{ {
$this->isResource = isset($data['resource']) && $data['resource']; $this->resource = !empty($data['resource']) ? $data['resource'] : false;
if (isset($data['description'])) { if (isset($data['description'])) {
$this->description = $data['description']; $this->description = $data['description'];
@ -292,7 +292,15 @@ class ApiDoc
*/ */
public function isResource() public function isResource()
{ {
return $this->isResource; return (bool) $this->resource;
}
/**
* @return mixed
*/
public function getResource()
{
return $this->resource && is_string($this->resource) ? $this->resource : false;
} }
/** /**

View File

@ -108,8 +108,12 @@ class ApiDocExtractor
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()) {
// remove format from routes used for resource grouping if (!($resource = $annotation->getResource())) {
$resources[] = str_replace('.{_format}', '', $route->getPattern()); // remove format from routes used for resource grouping
$resources[] = str_replace('.{_format}', '', $route->getPattern());
} else {
$resources[] = $resource;
}
} }
$array[] = array('annotation' => $this->extractData($annotation, $route, $method)); $array[] = array('annotation' => $this->extractData($annotation, $route, $method));
@ -123,7 +127,7 @@ class ApiDocExtractor
$pattern = $element['annotation']->getRoute()->getPattern(); $pattern = $element['annotation']->getRoute()->getPattern();
foreach ($resources as $resource) { foreach ($resources as $resource) {
if (0 === strpos($pattern, $resource)) { if (0 === strpos($pattern, $resource) || $resource === $element['annotation']->getResource()) {
$array[$index]['resource'] = $resource; $array[$index]['resource'] = $resource;
$hasResource = true; $hasResource = true;