Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
0a382f4e
Commit
0a382f4e
authored
Jun 18, 2016
by
Jérôme Tamarelle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix PHP7 type hint on controllers
parent
7e5910f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
1 deletion
+38
-1
src/Silex/AppArgumentValueResolver.php
src/Silex/AppArgumentValueResolver.php
+1
-1
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+15
-0
tests/Silex/Tests/Fixtures/Php7Controller.php
tests/Silex/Tests/Fixtures/Php7Controller.php
+22
-0
No files found.
src/Silex/AppArgumentValueResolver.php
View file @
0a382f4e
...
...
@@ -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
));
}
/**
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
0a382f4e
...
...
@@ -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
();
...
...
tests/Silex/Tests/Fixtures/Php7Controller.php
0 → 100644
View file @
0a382f4e
<?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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment