Created
March 18, 2015 19:52
-
-
Save mkoert/839e34aa408c8c173cb2 to your computer and use it in GitHub Desktop.
Modified ServiceControllerResolver from Silex
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
<?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; | |
namespace App\Component\HttpKernel\Controller; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; | |
use App\Component\CallbackResolver; | |
/** | |
* Enables name_of_service:method_name syntax for declaring controllers. | |
* | |
* @link http://silex.sensiolabs.org/doc/providers/service_controller.html | |
*/ | |
class ServiceControllerResolver implements ControllerResolverInterface | |
{ | |
protected $controllerResolver; | |
protected $callbackResolver; | |
/** | |
* Constructor. | |
* | |
* @param ControllerResolverInterface $controllerResolver A ControllerResolverInterface instance to delegate to | |
* @param CallbackResolver $callbackResolver A service resolver instance | |
*/ | |
public function __construct(ControllerResolverInterface $controllerResolver, CallbackResolver $callbackResolver) | |
{ | |
$this->controllerResolver = $controllerResolver; | |
$this->callbackResolver = $callbackResolver; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getController(Request $request) | |
{ | |
$controller = $request->attributes->get('_controller', null); | |
if (!$this->callbackResolver->isValid($controller)) { | |
return $this->controllerResolver->getController($request); | |
} | |
return $this->callbackResolver->convertCallback($controller); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getArguments(Request $request, $controller) | |
{ | |
return $this->controllerResolver->getArguments($request, $controller); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment