This repository has been archived by the owner on Jul 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a way to get the Application in a Controller without using 'use…
…' (that also allows the usage of class methods as controllers)
- Loading branch information
Showing
6 changed files
with
135 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Silex framework. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Silex; | ||
|
||
use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseControllerResolver; | ||
use Symfony\Component\HttpKernel\Log\LoggerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* ControllerResolver. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class ControllerResolver extends BaseControllerResolver | ||
{ | ||
protected $app; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Application $app An Application instance | ||
* @param LoggerInterface $logger A LoggerInterface instance | ||
*/ | ||
public function __construct(Application $app, LoggerInterface $logger = null) | ||
{ | ||
$this->app = $app; | ||
|
||
parent::__construct($logger); | ||
} | ||
|
||
protected function doGetArguments(Request $request, $controller, array $parameters) | ||
{ | ||
foreach ($parameters as $param) { | ||
if ($param->getClass() && $param->getClass()->isInstance($this->app)) { | ||
$request->attributes->set($param->getName(), $this->app); | ||
|
||
break; | ||
} | ||
} | ||
|
||
return parent::doGetArguments($request, $controller, $parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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; | ||
|
||
use Silex\ControllerResolver; | ||
use Silex\Application; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* ControllerResolver test cases. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class ControllerResolverTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGetArguments() | ||
{ | ||
$app = new Application(); | ||
$resolver = new ControllerResolver($app); | ||
|
||
$controller = function (Application $app) {}; | ||
|
||
$args = $resolver->getArguments(Request::create('/'), $controller); | ||
$this->assertSame($app, $args[0]); | ||
} | ||
} |
Submodule HttpKernel
updated
from 86041b to c1810c
We need to be consistent about
Silex\\Application
vsApplication
vsuse ($app)
.