minor #31938 [FrameworkBundle] fix FC with HttpKernel v5 (nicolas-grekas)
This PR was merged into the 4.4 branch.
Discussion
----------
[FrameworkBundle] fix FC with HttpKernel v5
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
This class is deprecated and is thus not enough a reason to conflict with http-kernel v5
Should unlock #31918
Commits
-------
6c109c71a9
[FrameworkBundle] fix FC with HttpKernel v5
This commit is contained in:
commit
02a792a313
|
@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\EventListener;
|
|||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +21,8 @@ use Symfony\Component\HttpKernel\KernelEvents;
|
|||
*
|
||||
* @author Ryan Weaver <ryan@knpuniversity.com>
|
||||
*
|
||||
* @method onKernelRequest(RequestEvent $event)
|
||||
*
|
||||
* @deprecated since Symfony 4.1
|
||||
*/
|
||||
class ResolveControllerNameSubscriber implements EventSubscriberInterface
|
||||
|
@ -36,8 +38,22 @@ class ResolveControllerNameSubscriber implements EventSubscriberInterface
|
|||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
public function onKernelRequest(GetResponseEvent $event)
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function resolveControllerName(...$args)
|
||||
{
|
||||
$this->onKernelRequest(...$args);
|
||||
}
|
||||
|
||||
public function __call(string $method, array $args)
|
||||
{
|
||||
if ('onKernelRequest' !== $method && 'onKernelRequest' !== strtolower($method)) {
|
||||
throw new \Error(sprintf('Error: Call to undefined method %s::%s()', \get_class($this), $method));
|
||||
}
|
||||
|
||||
$event = $args[0];
|
||||
|
||||
$controller = $event->getRequest()->attributes->get('_controller');
|
||||
if (\is_string($controller) && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
|
||||
// controller in the a:b:c notation then
|
||||
|
@ -50,7 +66,7 @@ class ResolveControllerNameSubscriber implements EventSubscriberInterface
|
|||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
KernelEvents::REQUEST => ['onKernelRequest', 24],
|
||||
KernelEvents::REQUEST => ['resolveControllerName', 24],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
|
|||
use Symfony\Bundle\FrameworkBundle\EventListener\ResolveControllerNameSubscriber;
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
|
@ -23,9 +24,6 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|||
*/
|
||||
class ResolveControllerNameSubscriberTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testReplacesControllerAttribute()
|
||||
{
|
||||
$parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock();
|
||||
|
@ -41,6 +39,10 @@ class ResolveControllerNameSubscriberTest extends TestCase
|
|||
$subscriber = new ResolveControllerNameSubscriber($parser);
|
||||
$subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
$this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller'));
|
||||
|
||||
$subscriber = new ChildResolveControllerNameSubscriber($parser);
|
||||
$subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
$this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,3 +69,11 @@ class ResolveControllerNameSubscriberTest extends TestCase
|
|||
yield [function () {}];
|
||||
}
|
||||
}
|
||||
|
||||
class ChildResolveControllerNameSubscriber extends ResolveControllerNameSubscriber
|
||||
{
|
||||
public function onKernelRequest(GetResponseEvent $event)
|
||||
{
|
||||
parent::onKernelRequest($event);
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue