diff --git a/Util/ControllerReflector.php b/Util/ControllerReflector.php index 568da23..7eba46e 100644 --- a/Util/ControllerReflector.php +++ b/Util/ControllerReflector.php @@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Util; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpKernel\Kernel; /** * @internal @@ -85,10 +86,20 @@ class ControllerReflector if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) { $class = $matches[1]; $method = $matches[2]; + // Since symfony 4.1 routes are defined like service_id::method_name + if (Kernel::VERSION_ID >= 40100 && !class_exists($class)) { + if ($this->container->has($class)) { + $class = get_class($this->container->get($class)); + if (class_exists(ClassUtils::class)) { + $class = ClassUtils::getRealClass($class); + } + } + } } elseif (class_exists($controller)) { $class = $controller; $method = '__invoke'; } else { + // Has to be removed when dropping support of symfony < 4.1 if (preg_match('#(.+):([\w]+)#', $controller, $matches)) { $controller = $matches[1]; $method = $matches[2];