8000 Merge branch '4.3' into 4.4 · symfony/symfony@8c91e7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c91e7e

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [HttpKernel] fixed class having a leading \ in a route controller [HttpKernel] trim the leading backslash in the controller init
2 parents 1964016 + 1ff2ab3 commit 8c91e7e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Symfony/Component/HttpKernel/Controller/ContainerControllerResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ protected function createController($controller)
4747
*/
4848
protected function instantiateController($class)
4949
{
50+
$class = ltrim($class, '\\');
51+
5052
if ($this->container->has($class)) {
5153
return $this->container->get($class);
5254
}

src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,36 @@ public function testGetControllerInvokableServiceWithClassNameAsName()
119119
$this->assertSame($service, $controller);
120120
}
121121

122+
/**
123+
* @dataProvider getControllers
124+
*/
125+
public function testInstantiateControllerWhenControllerStartsWithABackslash($controller)
126+
{
127+
$service = new ControllerTestService('foo');
128+
$class = ControllerTestService::class;
129+
130+
$container = $this->createMockContainer();
131+
$container->expects($this->once())->method('has')->with($class)->willReturn(true);
132+
$container->expects($this->once())->method('get')->with($class)->willReturn($service);
133+
134+
$resolver = $this->createControllerResolver(null, $container);
135+
$request = Request::create('/');
136+
$request->attributes->set('_controller', $controller);
137+
138+
$controller = $resolver->getController($request);
139+
140+
$this->assertInstanceOf(ControllerTestService::class, $controller[0]);
141+
$this->assertSame('action', $controller[1]);
142+
}
143+
144+
public function getControllers()
145+
{
146+
return [
147+
['\\'.ControllerTestService::class.'::action'],
148+
['\\'.ControllerTestService::class.':action'],
149+
];
150+
}
151+
122152
public function testExceptionWhenUsingRemovedControllerServiceWithClassNameAsName()
123153
{
124154
$this->expectException('InvalidArgumentException');

0 commit comments

Comments
 (0)
0