Commit 0a382f4e authored by Jérôme Tamarelle's avatar Jérôme Tamarelle

Fix PHP7 type hint on controllers

parent 7e5910f4
......@@ -34,7 +34,7 @@ class AppArgumentValueResolver implements ArgumentValueResolverInterface
*/
public function supports(Request $request, ArgumentMetadata $argument)
{
return $argument->getType() === Application::class || (null !== $argument->getType() && in_array(Application::class, class_parents($argument->getType()), true));
return null !== $argument->getType() && ($argument->getType() === Application::class || is_subclass_of($argument->getType(), Application::class));
}
/**
......
......@@ -177,6 +177,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testControllersAsMethods()
{
$app = new Application();
unset($app['exception_handler']);
$app->get('/{name}', 'Silex\Tests\FooController::barAction');
......@@ -186,12 +187,26 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testApplicationTypeHintWorks()
{
$app = new SpecialApplication();
unset($app['exception_handler']);
$app->get('/{name}', 'Silex\Tests\FooController::barSpecialAction');
$this->assertEquals('Hello Fabien in Silex\Tests\SpecialApplication', $app->handle(Request::create('/Fabien'))->getContent());
}
/**
* @requires PHP 7.0
*/
public function testPhp7TypeHintWorks()
{
$app = new SpecialApplication();
unset($app['exception_handler']);
$app->get('/{name}', 'Silex\Tests\Fixtures\Php7Controller::typehintedAction');
$this->assertEquals('Hello Fabien in Silex\Tests\SpecialApplication', $app->handle(Request::create('/Fabien'))->getContent());
}
public function testHttpSpec()
{
$app = new Application();
......
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests\Fixtures;
use Silex\Application;
class Php7Controller
{
public function typehintedAction(Application $application, string $name)
{
return 'Hello '.$application->escape($name).' in '.get_class($application);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment