[WebBundle] made the request instance explicit in the controller base class (useful if you inject the request for testing purpose)
This commit is contained in:
parent
a9d8f39382
commit
8fe25d343b
@ -3,6 +3,7 @@
|
|||||||
namespace Symfony\Framework\WebBundle;
|
namespace Symfony\Framework\WebBundle;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Components\RequestHandler\Request;
|
||||||
use Symfony\Components\RequestHandler\Response;
|
use Symfony\Components\RequestHandler\Response;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -24,6 +25,7 @@ use Symfony\Components\RequestHandler\Response;
|
|||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
protected $container;
|
protected $container;
|
||||||
|
protected $request;
|
||||||
|
|
||||||
function __construct(ContainerInterface $container)
|
function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -32,7 +34,17 @@ class Controller
|
|||||||
|
|
||||||
public function getRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return $this->container->getRequestService();
|
if (null === $this->request)
|
||||||
|
{
|
||||||
|
$this->request = $this->container->getRequestService();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRequest(Request $request)
|
||||||
|
{
|
||||||
|
return $this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUser()
|
public function getUser()
|
||||||
|
@ -69,6 +69,7 @@ class ControllerLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
$controller = $this->findController($bundle, $controller, $action);
|
$controller = $this->findController($bundle, $controller, $action);
|
||||||
|
$controller[0]->setRequest($request);
|
||||||
|
|
||||||
$r = new \ReflectionObject($controller[0]);
|
$r = new \ReflectionObject($controller[0]);
|
||||||
$arguments = $this->getMethodArguments($r->getMethod($controller[1]), $event->getParameter('request')->path->all(), sprintf('%s::%s()', get_class($controller[0]), $controller[1]));
|
$arguments = $this->getMethodArguments($r->getMethod($controller[1]), $event->getParameter('request')->path->all(), sprintf('%s::%s()', get_class($controller[0]), $controller[1]));
|
||||||
|
Reference in New Issue
Block a user