8000 moved RequestStack to HttpFoundation and removed RequestContext · symfony/symfony@b1a062d · GitHub
[go: up one dir, main page]

Skip to content

Commit b1a062d

Browse files
committed
moved RequestStack to HttpFoundation and removed RequestContext
1 parent 93e60ea commit b1a062d

File tree

20 files changed

+90
-128
lines changed

20 files changed

+90
-128
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use Symfony\Bridge\Twig\Tests\TestCase;
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
18+
use Symfony\Component\HttpFoundation\RequestStack;
1819
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
19-
use Symfony\Component\HttpKernel\RequestContext;
2020

2121
class HttpKernelExtensionTest extends TestCase
2222
{
@@ -41,7 +41,7 @@ public function testRenderFragment()
4141

4242
public function testUnknownFragmentRenderer()
4343
{
44-
$context = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\RequestContext')
44+
$context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
4545
->disableOriginalConstructor()
4646
->getMock()
4747
;
@@ -57,7 +57,7 @@ protected function getFragmentHandler($return)
5757
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
5858
$strategy->expects($this->once())->method('render')->will($return);
5959

60-
$context = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\RequestContext')
60+
$context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
6161
->disableOriginalConstructor()
6262
->getMock()
6363
;

src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<service id="fragment.handler" class="%fragment.handler.class%">
1818
<argument type="collection" />
1919
<argument>%kernel.debug%</argument>
20-
<argument type="service" id="request_context" />
20+
<argument type="service" id="request_stack" />
2121
</service>
2222

2323
<service id="fragment.renderer.inline" class="%fragment.renderer.inline.class%">

src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<argument type="service" id="router" />
9595
<argument type="service" id="router.request_context" on-invalid="ignore" />
9696
<argument type="service" id="logger" on-invalid="ignore" />
97-
<argument type="service" id="request_context" />
97+
<argument type="service" id="request_stack" />
9898
</service>
9999
</services>
100100
</container>

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<parameter key="cache_clearer.class">Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer</parameter>
1313
<parameter key="file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
1414
<parameter key="uri_signer.class">Symfony\Component\HttpKernel\UriSigner</parameter>
15-
<parameter key="request_stack.class">Symfony\Component\HttpKernel\RequestStack</parameter>
16-
<parameter key="request_context.class">Symfony\Component\HttpKernel\RequestContext</parameter>
15+
<parameter key="request_stack.class">Symfony\Component\HttpFoundation\RequestStack</parameter>
1716
</parameters>
1817

1918
<services>
@@ -28,12 +27,7 @@
2827
<argument type="service" id="request_stack" />
2928
</service>
3029

31-
<service id="request_stack" class="%request_stack.class%" public="false">
32-
</service>
33-
34-
<service id="request_context" class="%request_context.class%">
35-
<argument type="service" id="request_stack" />
36-
</service>
30+
<service id="request_stack" class="%request_stack.class%" />
3731

3832
<service id="cache_warmer" class="%cache_warmer.class%">
3933
<argument type="collection" />

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<tag name="kernel.event_subscriber" />
3939
<argument>%kernel.default_locale%</argument>
4040
<argument type="service" id="router" on-invalid="ignore" />
41-
<argument type="service" id="request_context" />
41+
<argument type="service" id="request_stack" />
4242
</service>
4343
</services>
4444
</container>

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
2.4.0
55
-----
66

7+
* added RequestStack
78
* added Request::getEncodings()
89
* added accessors methods to session handlers
910

src/Symfony/Component/HttpKernel/RequestStack.php renamed to src/Symfony/Component/HttpFoundation/RequestStack.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
* file that was distributed with this source code.
1010
*/ F987
1111

12-
namespace Symfony\Component\HttpKernel;
13-
14-
use Symfony\Component\HttpFoundation\Request;
12+
namespace Symfony\Component\HttpFoundation;
1513

1614
/**
1715
* Request stack that controls the lifecycle of requests.
@@ -25,6 +23,12 @@ class RequestStack
2523
*/
2624
private $requests = array();
2725

26+
/**
27+
* Pushes a Request on the stack.
28+
*
29+
* This method should generally not be called directly as the stack
30+
* management should be taken care of by the application itself.
31+
*/
2832
public function push(Request $request)
2933
{
3034
$this->requests[] = $request;
@@ -35,6 +39,9 @@ public function push(Request $request)
3539
*
3640
* This operation lets the current request go out of scope.
3741
*
42+
* This method should generally not be called directly as the stack
43+
* management should be taken care of by the application itself.
44+
*
3845
* @return Request
3946
*/
4047
public function pop()
@@ -55,6 +62,12 @@ public function getCurrentRequest()
5562
}
5663

5764
/**
65+
* Gets the master Request.
66+
*
67+
* Be warned that making your code aware of the master request
68+
* might make it un-compatible with other features of your framework
69+
* like ESI support.
70+
*
5871
* @return Request|null
5972
*/
6073
public function getMasterRequest()
@@ -69,6 +82,10 @@ public function getMasterRequest()
6982
/**
7083
* Returns the parent request of the current.
7184
*
85+
* Be warned that making your code aware of the parent request
< F438 code>86+
* might make it un-compatible with other features of your framework
87+
* like ESI support.
88+
*
7289
* If current Request is the master request, it returns null.
7390
*
7491
* @return Request|null

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.4.0
5+
-----
6+
7+
* added the KernelEvents::FINISH_REQUEST event
8+
49
2.3.0
510
-----
611

src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\HttpKernel\DependencyInjection;
1313

1414
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\RequestStack;
1516
use Symfony\Component\HttpKernel\HttpKernelInterface;
1617
use Symfony\Component\HttpKernel\HttpKernel;
17-
use Symfony\Component\HttpKernel\RequestStack;
1818
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
1919
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2020
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -29,7 +29,6 @@
2929
class ContainerAwareHttpKernel extends HttpKernel
3030
{
3131
protected $container;
32-
protected $requestStack;
3332

3433
/**
3534
* Constructor.

src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1515
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1616
use Symfony\Component\HttpKernel\KernelEvents;
17-
use Symfony\Component\HttpKernel\RequestContext;
17+
use Symfony\Component\HttpFoundation\RequestStack;
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\Routing\RequestContextAwareInterface;
2020
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -25,23 +25,23 @@
2525
* This listener works in 2 modes:
2626
*
2727
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
28-
* * 2.4+ mode where you must pass a RequestContext instance in the constructor.
28+
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
2929
*
3030
* @author Fabien Potencier <fabien@symfony.com>
3131
*/
3232
class LocaleListener implements EventSubscriberInterface
3333
{
3434
private $router;
3535
private $defaultLocale;
36-
private $requestContext;
36+
private $requestStack;
3737

3838
/**
39-
* RequestContext will become required in 3.0.
39+
* RequestStack will become required in 3.0.
4040
*/
41-
public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null, RequestContext $requestContext = null)
41+
public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null, RequestStack $requestStack = null)
4242
{
4343
$this->defaultLocale = $defaultLocale;
44-
$this->requestContext = $requestContext;
44+
$this->requestStack = $requestStack;
4545
$this->router = $router;
4646
}
4747

@@ -77,11 +77,11 @@ public function onKernelRequest(GetResponseEvent $event)
7777

7878
public function onKernelFinishRequest(FinishRequestEvent $event)
7979
{
80-
if (null === $this->requestContext) {
81-
throw new \LogicException('You must pass a RequestContext.');
80+
if (null === $this->requestStack) {
81+
throw new \LogicException('You must pass a RequestStack.');
8282
}
8383

84-
if (null !== $parentRequest = $this->requestContext->getParentRequest()) {
84+
if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
8585
$this->setRouterContext($parentRequest);
8686
}
8787
}

src/Symfony/Component/HttpKernel/EventListener/RouterListener.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\HttpKernel\KernelEvents;
1818
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
1919
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
20-
use Symfony\Component\HttpKernel\RequestContext as KernelRequestContext;
20+
use Symfony\Component\HttpFoundation\RequestStack;
2121
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
2222
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
2323
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
@@ -33,7 +33,7 @@
3333
* This listener works in 2 modes:
3434
*
3535
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
36-
* * 2.4+ mode where you must pass a RequestContext instance in the constructor.
36+
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
3737
*
3838
* @author Fabien Potencier <fabien@symfony.com>
3939
*/
@@ -43,20 +43,20 @@ class RouterListener implements EventSubscriberInterface
4343
private $context;
4444
private $logger;
4545
private $request;
46-
private $kernelContext;
46+
pri 10000 vate $requestStack;
4747

4848
/**
4949
* Constructor.
5050
*
51-
* RequestContext will become required in 3.0.
51+
* RequestStack will become required in 3.0.
5252
*
5353
* @param UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
5454
* @param RequestContext|null $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
5555
* @param LoggerInterface|null $logger The logger
5656
*
5757
* @throws \InvalidArgumentException
5858
*/
59-
public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null, KernelRequestContext $kernelContext = null)
59+
public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null, RequestStack $requestStack = null)
6060
{
6161
if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
6262
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
@@ -68,7 +68,7 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
6868

6969
$this->matcher = $matcher;
7070
$this->context = $context ?: $matcher->getContext();
71-
$this->kernelContext = $kernelContext;
71+
$this->requestStack = $requestStack;
7272
$this->logger = $logger;
7373
}
7474

@@ -93,11 +93,11 @@ public function setRequest(Request $request = null)
9393

9494
public function onKernelFinishRequest(FinishRequestEvent $event)
9595
{
96-
if (null === $this->kernelContext) {
97-
throw new \LogicException('You must pass a RequestContext.');
96+
if (null === $this->requestStack) {
97+
throw new \LogicException('You must pass a RequestStack.');
9898
}
9999

100-
$this->setRequest($this->kernelContext->getParentRequest());
100+
$this->setRequest($this->requestStack->getParentRequest());
101101
}
102102

103103
public function onKernelRequest(GetResponseEvent $event)
@@ -107,8 +107,8 @@ public function onKernelRequest(GetResponseEvent $event)
107107
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
108108
// we call setRequest even if most of the time, it has already been done to keep compatibility
109109
// with frameworks which do not use the Symfony service container
110-
// when we have a RequestContext, no need to do it
111-
if (null !== $this->kernelContext) {
110+
// when we have a RequestStack, no need to do it
111+
if (null !== $this->requestStack) {
112112
$this->setRequest($request);
113113
}
114114

src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\HttpFoundation\StreamedResponse;
17+
use Symfony\Component\HttpFoundation\RequestStack;
1718
use Symfony\Component\HttpKernel\Controller\ControllerReference;
18-
use Symfony\Component\HttpKernel\RequestContext;
1919

2020
/**
2121
* Renders a URI that represents a resource fragment.
@@ -26,7 +26,7 @@
2626
* This listener works in 2 modes:
2727
*
2828
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
29-
* * 2.4+ mode where you must pass a RequestContext instance in the constructor.
29+
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
3030
*
3131
* @author Fabien Potencier <fabien@symfony.com>
3232
*
@@ -37,19 +37,19 @@ class FragmentHandler
3737
private $debug;
3838
private $renderers;
3939
private $request;
40-
private $context;
40+
private $requestStack;
4141

4242
/**
4343
* Constructor.
4444
*
45-
* RequestContext will become required in 3.0.
45+
* RequestStack will become required in 3.0.
4646
*
4747
* @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
4848
* @param Boolean $debug Whether the debug mode is enabled or not
4949
*/
50-
public function __construct(array $renderers = array(), $debug = false, RequestContext $context = null)
50+
public function __construct(array $renderers = array(), $debug = false, RequestStack $requestStack = null)
5151
{
52-
$this->context = $context;
52+
$this->requestStack = $requestStack;
5353
$this->renderers = array();
5454
foreach ($renderers as $renderer) {
5555
$this->addRenderer($renderer);
@@ -143,6 +143,6 @@ protected function deliver(Response $response)
143143

144144
private function getRequest()
145145
{
146-
return $this->context ? $this->context->getCurrentRequest() : $this->request;
146+
return $this->requestStack ? $this->requestStack->getCurrentRequest() : $this->request;
147147
}
148148
}

src/Symfony/Component/HttpKernel/HttpKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
2323
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
2424
use Symfony\Component\HttpFoundation\Request;
25+
use Symfony\Component\HttpFoundation\RequestStack;
2526
use Symfony\Component\HttpFoundation\Response;
2627
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2728

0 commit comments

Comments
 (0)
0