Merge branch '2.3' into 2.7
* 2.3: fix debug toolbar rendering by removing inadvertently added links simplified code Allow variadic controller parameters to be resolved.
This commit is contained in:
commit
c6b68924a0
@ -1,4 +1,4 @@
|
|||||||
{% if link|default(true) %}
|
{% if link is not defined or link %}
|
||||||
{% set icon %}
|
{% set icon %}
|
||||||
<a href="{{ path('_profiler', { 'token': token, 'panel': name }) }}">{{ icon }}</a>
|
<a href="{{ path('_profiler', { 'token': token, 'panel': name }) }}">{{ icon }}</a>
|
||||||
{% endset %}
|
{% endset %}
|
||||||
|
@ -105,7 +105,11 @@ class ControllerResolver implements ControllerResolverInterface
|
|||||||
$arguments = array();
|
$arguments = array();
|
||||||
foreach ($parameters as $param) {
|
foreach ($parameters as $param) {
|
||||||
if (array_key_exists($param->name, $attributes)) {
|
if (array_key_exists($param->name, $attributes)) {
|
||||||
$arguments[] = $attributes[$param->name];
|
if (PHP_VERSION_ID >= 50600 && $param->isVariadic() && is_array($attributes[$param->name])) {
|
||||||
|
$arguments = array_merge($arguments, array_values($attributes[$param->name]));
|
||||||
|
} else {
|
||||||
|
$arguments[] = $attributes[$param->name];
|
||||||
|
}
|
||||||
} elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
|
} elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
|
||||||
$arguments[] = $request;
|
$arguments[] = $request;
|
||||||
} elseif ($param->isDefaultValueAvailable()) {
|
} elseif ($param->isDefaultValueAvailable()) {
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\Controller;
|
|||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||||
|
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class ControllerResolverTest extends \PHPUnit_Framework_TestCase
|
class ControllerResolverTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -197,6 +198,20 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
|
$this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 5.6
|
||||||
|
*/
|
||||||
|
public function testGetVariadicArguments()
|
||||||
|
{
|
||||||
|
$resolver = new ControllerResolver();
|
||||||
|
|
||||||
|
$request = Request::create('/');
|
||||||
|
$request->attributes->set('foo', 'foo');
|
||||||
|
$request->attributes->set('bar', array('foo', 'bar'));
|
||||||
|
$controller = array(new VariadicController(), 'action');
|
||||||
|
$this->assertEquals(array('foo', 'foo', 'bar'), $resolver->getArguments($request, $controller));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreateControllerCanReturnAnyCallable()
|
public function testCreateControllerCanReturnAnyCallable()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolver', array('createController'));
|
$mock = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolver', array('createController'));
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;
|
||||||
|
|
||||||
|
class VariadicController
|
||||||
|
{
|
||||||
|
public function action($foo, ...$bar)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user