@ 2015-01-21T18:34:08Z <?php
namespace SourceTest\Framework;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\HttpFoundation\Request,
Auryn\Provider as Injector;
/**
* Class AurynControllerResolver
*
* Controller resolver decorating the default controller resolver to use the Auryn DiC
*
* Case: 'ClassName:methodName' - Use Auryn Injector
* Case: 'ClassName::methodName' - Use original controller resolver (pimple)
*
* @package SourceTest\Framework
*/
class AurynControllerResolver implements ControllerResolverInterface
{
/**
* @var string The pattern for resolver delegation
*/
const SERVICE_PATTERN = "/[A-Za-z0-9\._\-]+:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/";
/**
* @var ControllerResolverInterface
*/
protected $resolver;
/**
* @var Injector
*/
protected $injector;
/**
* @var Application
*/
protected $application;
/**
* @var Request
*/
protected $request;
/**
* @var array
*/
protected $config;
/**
* @constructor
*
* @param ControllerResolverInterface $resolver Controller resolver to decorate
* @param Injector $injector Auryn provider to use instead
* @param Application $app The Silex Application for pimple
* @param Request $request The Silex Application Request object
* @param array $config Application configuration values (mainly for DiC)
*/
public function __construct(ControllerResolverInterface $resolver, Injector $injector, Application $app, Request $request, array $config)
{
$this->resolver = $resolver;
$this->injector = $injector;
$this->application = $app;
$this->request = $request;
$this->config = $config;
}
/**
* Executes the controller / action with either Auryn or default resolver
*
* @param Request $request Request object
*
* @return Response Response object
*/
public function getController(Request $request)
{
$controllerAction = $request->attributes->get('_controller', null);
/** Fall back to Symfony controller resolver **/
if (!is_string($controllerAction) || !preg_match(static::SERVICE_PATTERN, $controllerAction))
{
return $this->resolver->getController($request);
}
list($controller, $action) = explode(':', sprintf('%s', $controllerAction), 2);
foreach ($this->config['delay'] as $share)
{
$this->injector->share($this->{$share});
}
$this->injector->share($this->application['security']);
$params = !empty($this->request->attributes->all()['_route_params']) ? $this->request->attributes->all()['_route_params'] : [];
$args = [];
array_walk($params, function($value, $key) use (&$args) {
$args[sprintf(':%s', $key)] = $value;
});
/** Executed by the HTTP Kernel **/
return function () use ($controller, $action, $args) {
return $this->injector->execute([$this->injector->make($controller), $action], $args);
};
}
/**
* Original resolver delegation
*
* {@inheritDoc}
*/
public function getArguments(Request $request, $controller)
{
return $this->resolver->getArguments($request, $controller);
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.19 , 8.3.0 - 8.3.7 Fatal error: Uncaught Error: Interface "Symfony\Component\HttpKernel\Controller\ControllerResolverInterface" not found in /in/tshZN:20
Stack trace:
#0 {main}
thrown in /in/tshZN on line 20
Process exited with code 255 . Output for 7.4.0 - 7.4.33 Fatal error: Uncaught Error: Interface 'Symfony\Component\HttpKernel\Controller\ControllerResolverInterface' not found in /in/tshZN:20
Stack trace:
#0 {main}
thrown in /in/tshZN on line 20
Process exited with code 255 . Output for 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 Fatal error: Interface 'Symfony\Component\HttpKernel\Controller\ControllerResolverInterface' not found in /in/tshZN on line 20
Process exited with code 255 . Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 Fatal error: Interface 'Symfony\Component\HttpKernel\Controller\ControllerResolverInterface' not found in /in/tshZN on line 21
Process exited with code 255 . Output for 5.3.0 - 5.3.29 Parse error: syntax error, unexpected '[', expecting ')' in /in/tshZN on line 96
Process exited with code 255 . Output for 4.4.2 - 4.4.9 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Parse error: syntax error, unexpected T_STRING in /in/tshZN on line 3
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 , 5.0.0 - 5.0.5 Parse error: parse error, unexpected T_STRING in /in/tshZN on line 3
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/tshZN on line 3
Process exited with code 255 . preferences:dark mode live preview
211 ms | 401 KiB | 460 Q