mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
also support services as controller in ApiDocExtractor::get()
This commit is contained in:
parent
6940174586
commit
f0e84a96d7
@ -56,19 +56,7 @@ class ApiDocExtractor
|
|||||||
$resources = array();
|
$resources = array();
|
||||||
|
|
||||||
foreach ($this->router->getRouteCollection()->all() as $route) {
|
foreach ($this->router->getRouteCollection()->all() as $route) {
|
||||||
$method = false;
|
$method = $this->getReflectionMethod($route->getDefault('_controller'));
|
||||||
if (preg_match('#(.+)::([\w]+)#', $route->getDefault('_controller'), $matches)) {
|
|
||||||
$method = new \ReflectionMethod($matches[1], $matches[2]);
|
|
||||||
} elseif (preg_match('#(.+):([\w]+)#', $route->getDefault('_controller'), $matches)) {
|
|
||||||
$controller = $matches[1];
|
|
||||||
if ($this->container->has($controller)) {
|
|
||||||
$this->container->enterScope('request');
|
|
||||||
$this->container->set('request', new Request);
|
|
||||||
$class = get_class($this->container->get($controller));
|
|
||||||
$this->container->leaveScope('request');
|
|
||||||
$method = new \ReflectionMethod($class, $matches[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($method) {
|
if ($method) {
|
||||||
$annot = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS);
|
$annot = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS);
|
||||||
@ -125,6 +113,38 @@ class ApiDocExtractor
|
|||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ReflectionMethod for the given controller string
|
||||||
|
*
|
||||||
|
* @param string $controller
|
||||||
|
* @return ReflectionMethod|null
|
||||||
|
*/
|
||||||
|
public function getReflectionMethod($controller)
|
||||||
|
{
|
||||||
|
if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) {
|
||||||
|
$class = $matches[1];
|
||||||
|
$method = $matches[2];
|
||||||
|
} elseif (preg_match('#(.+):([\w]+)#', $controller, $matches)) {
|
||||||
|
$controller = $matches[1];
|
||||||
|
$method = $matches[2];
|
||||||
|
if ($this->container->has($controller)) {
|
||||||
|
$this->container->enterScope('request');
|
||||||
|
$this->container->set('request', new Request);
|
||||||
|
$class = get_class($this->container->get($controller));
|
||||||
|
$this->container->leaveScope('request');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($class) && isset($method)) {
|
||||||
|
try {
|
||||||
|
return new \ReflectionMethod($class, $method);
|
||||||
|
} catch (\ReflectionException $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing two values with the following keys:
|
* Returns an array containing two values with the following keys:
|
||||||
* - annotation
|
* - annotation
|
||||||
@ -136,13 +156,8 @@ class ApiDocExtractor
|
|||||||
*/
|
*/
|
||||||
public function get($controller, $route)
|
public function get($controller, $route)
|
||||||
{
|
{
|
||||||
if (!preg_match('#(.+)::([\w]+)#', $controller, $matches)) {
|
$method = $this->getReflectionMethod($controller);
|
||||||
return null;
|
if (!$method) {
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$method = new \ReflectionMethod($matches[1], $matches[2]);
|
|
||||||
} catch (\ReflectionException $e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user