Skip to content

Commit 8c44768

Browse files
committed
[HttpKernel] allowed any callable to be returned by ControllerResolver::createController
1 parent 1552a16 commit 8c44768

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public function getController(Request $request)
7676
}
7777
}
7878

79-
list($controller, $method) = $this->createController($controller);
79+
$callable = $this->createController($controller);
8080

81-
if (!method_exists($controller, $method)) {
82-
throw new \InvalidArgumentException(sprintf('Method "%s::%s" does not exist.', get_class($controller), $method));
81+
if (!is_callable($callable)) {
82+
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable.', $request->getPathInfo()));
8383
}
8484

85-
return array($controller, $method);
85+
return $callable;
8686
}
8787

8888
/**

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

+10
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public function testGetArguments()
150150
$this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
151151
}
152152

153+
public function testCreateControllerCanReturnAnyCallable()
154+
{
155+
$mock = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolver', array('createController'));
156+
$mock->expects($this->once())->method('createController')->will($this->returnValue('Symfony\Component\HttpKernel\Tests\some_controller_function'));
157+
158+
$request = Request::create('/');
159+
$request->attributes->set('_controller', 'foobar');
160+
$mock->getController($request);
161+
}
162+
153163
public function __invoke($foo, $bar = null)
154164
{
155165
}

0 commit comments

Comments
 (0)