8000 minor #31938 [FrameworkBundle] fix FC with HttpKernel v5 (nicolas-gre… · symfony/symfony@02a792a · GitHub
[go: up one dir, main page]

Skip to content

Commit 02a792a

Browse files
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 ------- 6c109c7 [FrameworkBundle] fix FC with HttpKernel v5
2 parents 3bef037 + 6c109c7 commit 02a792a

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
1515
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\RequestEvent;
1717
use Symfony\Component\HttpKernel\KernelEvents;
1818

1919
/**
2020
* Guarantees that the _controller key is parsed into its final format.
2121
*
2222
* @author Ryan Weaver <ryan@knpuniversity.com>
2323
*
24+
* @method onKernelRequest(RequestEvent $event)
25+
*
2426
* @deprecated since Symfony 4.1
2527
*/
2628
class ResolveControllerNameSubscriber implements EventSubscriberInterface
@@ -36,8 +38,22 @@ public function __construct(ControllerNameParser $parser, bool $triggerDeprecati
3638
$this->parser = $parser;
3739
}
3840

39-
public function onKernelRequest(GetResponseEvent $event)
41+
/**
42+
* @internal
43+
*/
44+
public function resolveControllerName(...$args)
45+
{
46+
$this->onKernelRequest(...$args);
47+
}
48+
49+
public function __call(string $method, array $args)
4050
{
51+
if ('onKernelRequest' !== $method && 'onKernelRequest' !== strtolower($method)) {
52+
throw new \Error(sprintf('Error: Call to undefined method %s::%s()', \get_class($this), $method));
53+
}
54+
55+
$event = $args[0];
56+
4157
$controller = $event->getRequest()->attributes->get('_controller');
4258
if (\is_string($controller) && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
4359
// controller in the a:b:c notation then
@@ -50,7 +66,7 @@ public function onKernelRequest(GetResponseEvent $event)
5066
public static function getSubscribedEvents()
5167
{
5268
return [
53-
KernelEvents::REQUEST => ['onKernelRequest', 24],
69+
KernelEvents::REQUEST => ['resolveControllerName', 24],
5470
];
5571
}
5672
}

src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\EventListener\ResolveControllerNameSubscriber;
1616
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1717
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1819
use Symfony\Component\HttpKernel\Event\RequestEvent;
1920
use Symfony\Component\HttpKernel\HttpKernelInterface;
2021

@@ -23,9 +24,6 @@
2324
*/
2425
class ResolveControllerNameSubscriberTest extends TestCase
2526
{
26-
/**
27-
* @group legacy
28-
*/
2927
public function testReplacesControllerAttribute()
3028
{
3129
$parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock();
@@ -41,6 +39,10 @@ public function testReplacesControllerAttribute()
4139
$subscriber = new ResolveControllerNameSubscriber($parser);
4240
$subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
4341
$this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller'));
42+
43+
$subscriber = new ChildResolveControllerNameSubscriber($parser);
44+
$subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
45+
$this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller'));
4446
}
4547

4648
/**
@@ -67,3 +69,11 @@ public function provideSkippedControllers()
6769
yield [function () {}];
6870
}
6971
}
72+
73+
class ChildResolveControllerNameSubscriber extends ResolveControllerNameSubscriber
74+
{
75+
public function onKernelRequest(GetResponseEvent $event)
76+
{
77+
parent::onKernelRequest($event);
78+
}
79+
}

0 commit comments

Comments
 (0)
0