8000 [WebBundle] made the request instance explicit in the controller base… · Arief57/symfony@8fe25d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8fe25d3

Browse files
committed
[WebBundle] made the request instance explicit in the controller base class (useful if you inject the request for testing purpose)
1 parent a9d8f39 commit 8fe25d3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Framework/WebBundle/Controller.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Framework\WebBundle;
44

55
use Symfony\Components\DependencyInjection\ContainerInterface;
6+
use Symfony\Components\RequestHandler\Request;
67
use Symfony\Components\RequestHandler\Response;
78

89
/*
@@ -24,6 +25,7 @@
2425
class Controller
2526
{
2627
protected $container;
28+
protected $request;
2729

2830
function __construct(ContainerInterface $container)
2931
{
@@ -32,7 +34,17 @@ function __construct(ContainerInterface $container)
3234

3335
public function getRequest()
3436
{
35-
return $this->container->getRequestService();
37+
if (null === $this->request)
38+
{
39+
$this->request = $this->container->getRequestService();
40+
}
41+
42+
return $this->request;
43+
}
44+
45+
public function setRequest(Request $request)
46+
{
47+
return $this->request = $request;
3648
}
3749

3850
public function getUser()

src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function resolve(Event $event)
6969
}
7070

7171
$controller = $this->findController($bundle, $controller, $action);
72+
$controller[0]->setRequest($request);
7273

7374
$r = new \ReflectionObject($controller[0]);
7475
$arguments = $this->getMethodArguments($r->getMethod($controller[1]), $event->getParameter('request')->path->all(), sprintf('%s::%s()', get_class($controller[0]), $controller[1]));

0 commit comments

Comments
 (0)
0