merged branch fabpot/callable (PR #7739)
This PR was merged into the master branch.
Discussion
----------
[HttpKernel] allowed any callable to be returned by ControllerResolver::createController
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Commits
-------
8c44768
[HttpKernel] allowed any callable to be returned by ControllerResolver::createController
This commit is contained in:
commit
898185e870
|
@ -76,13 +76,13 @@ class ControllerResolver implements ControllerResolverInterface
|
|||
}
|
||||
}
|
||||
|
||||
list($controller, $method) = $this->createController($controller);
|
||||
$callable = $this->createController($controller);
|
||||
|
||||
if (!method_exists($controller, $method)) {
|
||||
throw new \InvalidArgumentException(sprintf('Method "%s::%s" does not exist.', get_class($controller), $method));
|
||||
if (!is_callable($callable)) {
|
||||
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable.', $request->getPathInfo()));
|
||||
}
|
||||
|
||||
return array($controller, $method);
|
||||
return $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -150,6 +150,16 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
|
||||
}
|
||||
|
||||
public function testCreateControllerCanReturnAnyCallable()
|
||||
{
|
||||
$mock = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolver', array('createController'));
|
||||
$mock->expects($this->once())->method('createController')->will($this->returnValue('Symfony\Component\HttpKernel\Tests\some_controller_function'));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'foobar');
|
||||
$mock->getController($request);
|
||||
}
|
||||
|
||||
public function __invoke($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
|
|
Reference in New Issue