Skip to content

Commit

Permalink
moved RequestStack to HttpFoundation and removed RequestContext
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 8, 2013
1 parent 93e60ea commit b1a062d
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 128 deletions.
Expand Up @@ -15,8 +15,8 @@
use Symfony\Bridge\Twig\Tests\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\HttpKernel\RequestContext;

class HttpKernelExtensionTest extends TestCase
{
Expand All @@ -41,7 +41,7 @@ public function testRenderFragment()

public function testUnknownFragmentRenderer()
{
$context = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\RequestContext')
$context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
->disableOriginalConstructor()
->getMock()
;
Expand All @@ -57,7 +57,7 @@ protected function getFragmentHandler($return)
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
$strategy->expects($this->once())->method('render')->will($return);

$context = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\RequestContext')
$context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
->disableOriginalConstructor()
->getMock()
;
Expand Down
Expand Up @@ -17,7 +17,7 @@
<service id="fragment.handler" class="%fragment.handler.class%">
<argument type="collection" />
<argument>%kernel.debug%</argument>
<argument type="service" id="request_context" />
<argument type="service" id="request_stack" />
</service>

<service id="fragment.renderer.inline" class="%fragment.renderer.inline.class%">
Expand Down
Expand Up @@ -94,7 +94,7 @@
<argument type="service" id="router" />
<argument type="service" id="router.request_context" on-invalid="ignore" />
<argument type="service" id="logger" on-invalid="ignore" />
<argument type="service" id="request_context" />
<argument type="service" id="request_stack" />
</service>
</services>
</container>
10 changes: 2 additions & 8 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
Expand Up @@ -12,8 +12,7 @@
<parameter key="cache_clearer.class">Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer</parameter>
<parameter key="file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
<parameter key="uri_signer.class">Symfony\Component\HttpKernel\UriSigner</parameter>
<parameter key="request_stack.class">Symfony\Component\HttpKernel\RequestStack</parameter>
<parameter key="request_context.class">Symfony\Component\HttpKernel\RequestContext</parameter>
<parameter key="request_stack.class">Symfony\Component\HttpFoundation\RequestStack</parameter>
</parameters>

<services>
Expand All @@ -28,12 +27,7 @@
<argument type="service" id="request_stack" />
</service>

<service id="request_stack" class="%request_stack.class%" public="false">
</service>

<service id="request_context" class="%request_context.class%">
<argument type="service" id="request_stack" />
</service>
<service id="request_stack" class="%request_stack.class%" />

<service id="cache_warmer" class="%cache_warmer.class%">
<argument type="collection" />
Expand Down
Expand Up @@ -38,7 +38,7 @@
<tag name="kernel.event_subscriber" />
<argument>%kernel.default_locale%</argument>
<argument type="service" id="router" on-invalid="ignore" />
<argument type="service" id="request_context" />
<argument type="service" id="request_stack" />
</service>
</services>
</container>
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
2.4.0
-----

* added RequestStack
* added Request::getEncodings()
* added accessors methods to session handlers

Expand Down
Expand Up @@ -9,9 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel;

use Symfony\Component\HttpFoundation\Request;
namespace Symfony\Component\HttpFoundation;

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

/**
* Pushes a Request on the stack.
*
* This method should generally not be called directly as the stack
* management should be taken care of by the application itself.
*/
public function push(Request $request)
{
$this->requests[] = $request;
Expand All @@ -35,6 +39,9 @@ public function push(Request $request)
*
* This operation lets the current request go out of scope.
*
* This method should generally not be called directly as the stack
* management should be taken care of by the application itself.
*
* @return Request
*/
public function pop()
Expand All @@ -55,6 +62,12 @@ public function getCurrentRequest()
}

/**
* Gets the master Request.
*
* Be warned that making your code aware of the master request
* might make it un-compatible with other features of your framework
* like ESI support.
*
* @return Request|null
*/
public function getMasterRequest()
Expand All @@ -69,6 +82,10 @@ public function getMasterRequest()
/**
* Returns the parent request of the current.
*
* Be warned that making your code aware of the parent request
* might make it un-compatible with other features of your framework
* like ESI support.
*
* If current Request is the master request, it returns null.
*
* @return Request|null
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.4.0
-----

* added the KernelEvents::FINISH_REQUEST event

2.3.0
-----

Expand Down
Expand Up @@ -12,9 +12,9 @@
namespace Symfony\Component\HttpKernel\DependencyInjection;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\RequestStack;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -29,7 +29,6 @@
class ContainerAwareHttpKernel extends HttpKernel
{
protected $container;
protected $requestStack;

/**
* Constructor.
Expand Down
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\RequestContext;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContextAwareInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand All @@ -25,23 +25,23 @@
* This listener works in 2 modes:
*
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
* * 2.4+ mode where you must pass a RequestContext instance in the constructor.
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class LocaleListener implements EventSubscriberInterface
{
private $router;
private $defaultLocale;
private $requestContext;
private $requestStack;

/**
* RequestContext will become required in 3.0.
* RequestStack will become required in 3.0.
*/
public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null, RequestContext $requestContext = null)
public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null, RequestStack $requestStack = null)
{
$this->defaultLocale = $defaultLocale;
$this->requestContext = $requestContext;
$this->requestStack = $requestStack;
$this->router = $router;
}

Expand Down Expand Up @@ -77,11 +77,11 @@ public function onKernelRequest(GetResponseEvent $event)

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

if (null !== $parentRequest = $this->requestContext->getParentRequest()) {
if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
$this->setRouterContext($parentRequest);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\RequestContext as KernelRequestContext;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
Expand All @@ -33,7 +33,7 @@
* This listener works in 2 modes:
*
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
* * 2.4+ mode where you must pass a RequestContext instance in the constructor.
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
Expand All @@ -43,20 +43,20 @@ class RouterListener implements EventSubscriberInterface
private $context;
private $logger;
private $request;
private $kernelContext;
private $requestStack;

/**
* Constructor.
*
* RequestContext will become required in 3.0.
* RequestStack will become required in 3.0.
*
* @param UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
* @param RequestContext|null $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
* @param LoggerInterface|null $logger The logger
*
* @throws \InvalidArgumentException
*/
public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null, KernelRequestContext $kernelContext = null)
public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null, RequestStack $requestStack = null)
{
if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
Expand All @@ -68,7 +68,7 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte

$this->matcher = $matcher;
$this->context = $context ?: $matcher->getContext();
$this->kernelContext = $kernelContext;
$this->requestStack = $requestStack;
$this->logger = $logger;
}

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

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

$this->setRequest($this->kernelContext->getParentRequest());
$this->setRequest($this->requestStack->getParentRequest());
}

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

Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php
Expand Up @@ -14,8 +14,8 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\RequestContext;

/**
* Renders a URI that represents a resource fragment.
Expand All @@ -26,7 +26,7 @@
* This listener works in 2 modes:
*
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
* * 2.4+ mode where you must pass a RequestContext instance in the constructor.
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
*
* @author Fabien Potencier <fabien@symfony.com>
*
Expand All @@ -37,19 +37,19 @@ class FragmentHandler
private $debug;
private $renderers;
private $request;
private $context;
private $requestStack;

/**
* Constructor.
*
* RequestContext will become required in 3.0.
* RequestStack will become required in 3.0.
*
* @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
* @param Boolean $debug Whether the debug mode is enabled or not
*/
public function __construct(array $renderers = array(), $debug = false, RequestContext $context = null)
public function __construct(array $renderers = array(), $debug = false, RequestStack $requestStack = null)
{
$this->context = $context;
$this->requestStack = $requestStack;
$this->renderers = array();
foreach ($renderers as $renderer) {
$this->addRenderer($renderer);
Expand Down Expand Up @@ -143,6 +143,6 @@ protected function deliver(Response $response)

private function getRequest()
{
return $this->context ? $this->context->getCurrentRequest() : $this->request;
return $this->requestStack ? $this->requestStack->getCurrentRequest() : $this->request;
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/HttpKernel.php
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand Down

0 comments on commit b1a062d

Please sign in to comment.