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();
|
||||
|
||||
foreach ($this->router->getRouteCollection()->all() as $route) {
|
||||
$method = false;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
$method = $this->getReflectionMethod($route->getDefault('_controller'));
|
||||
|
||||
if ($method) {
|
||||
$annot = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS);
|
||||
@ -125,6 +113,38 @@ class ApiDocExtractor
|
||||
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:
|
||||
* - annotation
|
||||
@ -136,13 +156,8 @@ class ApiDocExtractor
|
||||
*/
|
||||
public function get($controller, $route)
|
||||
{
|
||||
if (!preg_match('#(.+)::([\w]+)#', $controller, $matches)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$method = new \ReflectionMethod($matches[1], $matches[2]);
|
||||
} catch (\ReflectionException $e) {
|
||||
$method = $this->getReflectionMethod($controller);
|
||||
if (!$method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user