diff --git a/EventListener/ControllerListener.php b/EventListener/ControllerListener.php index e6cca840..aa69e923 100644 --- a/EventListener/ControllerListener.php +++ b/EventListener/ControllerListener.php @@ -12,11 +12,11 @@ namespace Sensio\Bundle\FrameworkExtraBundle\EventListener; use Doctrine\Common\Annotations\Reader; +use Doctrine\Common\Persistence\Proxy; use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface; -use Doctrine\Common\Util\ClassUtils; /** * The ControllerListener class parses annotation blocks located in @@ -53,7 +53,7 @@ public function onKernelController(FilterControllerEvent $event) return; } - $className = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($controller[0]) : \get_class($controller[0]); + $className = $this->getRealClass(\get_class($controller[0])); $object = new \ReflectionClass($className); $method = $object->getMethod($controller[1]); @@ -112,4 +112,13 @@ public static function getSubscribedEvents() KernelEvents::CONTROLLER => 'onKernelController', ]; } + + private static function getRealClass(string $class): string + { + if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) { + return $class; + } + + return substr($class, $pos + Proxy::MARKER_LENGTH + 2); + } } diff --git a/Templating/TemplateGuesser.php b/Templating/TemplateGuesser.php index 37f10680..64fca3fe 100644 --- a/Templating/TemplateGuesser.php +++ b/Templating/TemplateGuesser.php @@ -11,10 +11,10 @@ namespace Sensio\Bundle\FrameworkExtraBundle\Templating; +use Doctrine\Common\Persistence\Proxy; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpFoundation\Request; -use Doctrine\Common\Util\ClassUtils; /** * The TemplateGuesser class handles the guessing of template name based on controller. @@ -62,7 +62,7 @@ public function guessTemplateName($controller, Request $request) throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, \gettype($controller))); } - $className = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($controller[0]) : \get_class($controller[0]); + $className = $this->getRealClass(\get_class($controller[0])); $matchController = null; foreach ($this->controllerPatterns as $pattern) { @@ -113,4 +113,13 @@ private function getBundleForClass($class) $reflectionClass = $reflectionClass->getParentClass(); } while ($reflectionClass); } + + private static function getRealClass(string $class): string + { + if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) { + return $class; + } + + return substr($class, $pos + Proxy::MARKER_LENGTH + 2); + } } diff --git a/composer.json b/composer.json index 661e9227..bc8ac9be 100644 --- a/composer.json +++ b/composer.json @@ -12,23 +12,24 @@ ], "require": { "php": ">=7.1.3", - "symfony/config": "^3.3|^4.0", - "symfony/framework-bundle": "^3.4|^4.0", - "symfony/dependency-injection": "^3.3|^4.0", - "symfony/http-kernel": "^3.3|^4.0", - "doctrine/common": "^2.2" + "symfony/config": "^3.4|^4.2", + "symfony/framework-bundle": "^3.4|^4.2", + "symfony/dependency-injection": "^3.4|^4.2", + "symfony/http-kernel": "^3.4|^4.2", + "doctrine/annotations": "^1.0", + "doctrine/persistence": "^1.0" }, "require-dev": { - "symfony/expression-language": "^3.3|^4.0", - "symfony/finder": "^3.3|^4.0", + "symfony/expression-language": "^3.4|^4.2", + "symfony/finder": "^3.4|^4.2", "symfony/psr-http-message-bridge": "^1.1", - "symfony/security-bundle": "^3.3|^4.0", - "symfony/yaml": "^3.3|^4.0", - "symfony/twig-bundle": "^3.3|^4.0", + "symfony/security-bundle": "^3.4|^4.2", + "symfony/yaml": "^3.4|^4.2", + "symfony/twig-bundle": "^3.4|^4.2", "twig/twig": "~1.12|~2.0", - "symfony/browser-kit": "^3.3|^4.0", + "symfony/browser-kit": "^3.4|^4.2", "symfony/phpunit-bridge": "^3.4.19|^4.1.8", - "symfony/dom-crawler": "^3.3|^4.0", + "symfony/dom-crawler": "^3.4|^4.2", "doctrine/doctrine-bundle": "^1.6", "doctrine/orm": "^2.5", "symfony/monolog-bundle": "^3.2",