moved RequestStack to HttpFoundation and removed RequestContext
This commit is contained in:
parent
93e60eaeab
commit
b1a062d232
@ -15,8 +15,8 @@ use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
|
|||||||
use Symfony\Bridge\Twig\Tests\TestCase;
|
use Symfony\Bridge\Twig\Tests\TestCase;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||||
use Symfony\Component\HttpKernel\RequestContext;
|
|
||||||
|
|
||||||
class HttpKernelExtensionTest extends TestCase
|
class HttpKernelExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ class HttpKernelExtensionTest extends TestCase
|
|||||||
|
|
||||||
public function testUnknownFragmentRenderer()
|
public function testUnknownFragmentRenderer()
|
||||||
{
|
{
|
||||||
$context = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\RequestContext')
|
$context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock()
|
->getMock()
|
||||||
;
|
;
|
||||||
@ -57,7 +57,7 @@ class HttpKernelExtensionTest extends TestCase
|
|||||||
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
|
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
|
||||||
$strategy->expects($this->once())->method('render')->will($return);
|
$strategy->expects($this->once())->method('render')->will($return);
|
||||||
|
|
||||||
$context = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\RequestContext')
|
$context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock()
|
->getMock()
|
||||||
;
|
;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<service id="fragment.handler" class="%fragment.handler.class%">
|
<service id="fragment.handler" class="%fragment.handler.class%">
|
||||||
<argument type="collection" />
|
<argument type="collection" />
|
||||||
<argument>%kernel.debug%</argument>
|
<argument>%kernel.debug%</argument>
|
||||||
<argument type="service" id="request_context" />
|
<argument type="service" id="request_stack" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="fragment.renderer.inline" class="%fragment.renderer.inline.class%">
|
<service id="fragment.renderer.inline" class="%fragment.renderer.inline.class%">
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
<argument type="service" id="router" />
|
<argument type="service" id="router" />
|
||||||
<argument type="service" id="router.request_context" on-invalid="ignore" />
|
<argument type="service" id="router.request_context" on-invalid="ignore" />
|
||||||
<argument type="service" id="logger" on-invalid="ignore" />
|
<argument type="service" id="logger" on-invalid="ignore" />
|
||||||
<argument type="service" id="request_context" />
|
<argument type="service" id="request_stack" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -12,8 +12,7 @@
|
|||||||
<parameter key="cache_clearer.class">Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer</parameter>
|
<parameter key="cache_clearer.class">Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer</parameter>
|
||||||
<parameter key="file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
|
<parameter key="file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
|
||||||
<parameter key="uri_signer.class">Symfony\Component\HttpKernel\UriSigner</parameter>
|
<parameter key="uri_signer.class">Symfony\Component\HttpKernel\UriSigner</parameter>
|
||||||
<parameter key="request_stack.class">Symfony\Component\HttpKernel\RequestStack</parameter>
|
<parameter key="request_stack.class">Symfony\Component\HttpFoundation\RequestStack</parameter>
|
||||||
<parameter key="request_context.class">Symfony\Component\HttpKernel\RequestContext</parameter>
|
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
@ -28,12 +27,7 @@
|
|||||||
<argument type="service" id="request_stack" />
|
<argument type="service" id="request_stack" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="request_stack" class="%request_stack.class%" public="false">
|
<service id="request_stack" class="%request_stack.class%" />
|
||||||
</service>
|
|
||||||
|
|
||||||
<service id="request_context" class="%request_context.class%">
|
|
||||||
<argument type="service" id="request_stack" />
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<service id="cache_warmer" class="%cache_warmer.class%">
|
<service id="cache_warmer" class="%cache_warmer.class%">
|
||||||
<argument type="collection" />
|
<argument type="collection" />
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
<tag name="kernel.event_subscriber" />
|
<tag name="kernel.event_subscriber" />
|
||||||
<argument>%kernel.default_locale%</argument>
|
<argument>%kernel.default_locale%</argument>
|
||||||
<argument type="service" id="router" on-invalid="ignore" />
|
<argument type="service" id="router" on-invalid="ignore" />
|
||||||
<argument type="service" id="request_context" />
|
<argument type="service" id="request_stack" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -4,6 +4,7 @@ CHANGELOG
|
|||||||
2.4.0
|
2.4.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
* added RequestStack
|
||||||
* added Request::getEncodings()
|
* added Request::getEncodings()
|
||||||
* added accessors methods to session handlers
|
* added accessors methods to session handlers
|
||||||
|
|
||||||
|
@ -9,9 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpKernel;
|
namespace Symfony\Component\HttpFoundation;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request stack that controls the lifecycle of requests.
|
* Request stack that controls the lifecycle of requests.
|
||||||
@ -25,6 +23,12 @@ class RequestStack
|
|||||||
*/
|
*/
|
||||||
private $requests = array();
|
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)
|
public function push(Request $request)
|
||||||
{
|
{
|
||||||
$this->requests[] = $request;
|
$this->requests[] = $request;
|
||||||
@ -35,6 +39,9 @@ class RequestStack
|
|||||||
*
|
*
|
||||||
* This operation lets the current request go out of scope.
|
* 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
|
* @return Request
|
||||||
*/
|
*/
|
||||||
public function pop()
|
public function pop()
|
||||||
@ -55,6 +62,12 @@ class RequestStack
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 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
|
* @return Request|null
|
||||||
*/
|
*/
|
||||||
public function getMasterRequest()
|
public function getMasterRequest()
|
||||||
@ -69,6 +82,10 @@ class RequestStack
|
|||||||
/**
|
/**
|
||||||
* Returns the parent request of the current.
|
* 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.
|
* If current Request is the master request, it returns null.
|
||||||
*
|
*
|
||||||
* @return Request|null
|
* @return Request|null
|
@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
2.4.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* added the KernelEvents::FINISH_REQUEST event
|
||||||
|
|
||||||
2.3.0
|
2.3.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
use Symfony\Component\HttpKernel\HttpKernel;
|
use Symfony\Component\HttpKernel\HttpKernel;
|
||||||
use Symfony\Component\HttpKernel\RequestStack;
|
|
||||||
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
|
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
@ -29,7 +29,6 @@ use Symfony\Component\DependencyInjection\Scope;
|
|||||||
class ContainerAwareHttpKernel extends HttpKernel
|
class ContainerAwareHttpKernel extends HttpKernel
|
||||||
{
|
{
|
||||||
protected $container;
|
protected $container;
|
||||||
protected $requestStack;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -14,7 +14,7 @@ namespace Symfony\Component\HttpKernel\EventListener;
|
|||||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
|
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\HttpKernel\RequestContext;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Routing\RequestContextAwareInterface;
|
use Symfony\Component\Routing\RequestContextAwareInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
@ -25,7 +25,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|||||||
* This listener works in 2 modes:
|
* This listener works in 2 modes:
|
||||||
*
|
*
|
||||||
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
|
* * 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>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
@ -33,15 +33,15 @@ class LocaleListener implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
private $router;
|
private $router;
|
||||||
private $defaultLocale;
|
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->defaultLocale = $defaultLocale;
|
||||||
$this->requestContext = $requestContext;
|
$this->requestStack = $requestStack;
|
||||||
$this->router = $router;
|
$this->router = $router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +77,11 @@ class LocaleListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
public function onKernelFinishRequest(FinishRequestEvent $event)
|
public function onKernelFinishRequest(FinishRequestEvent $event)
|
||||||
{
|
{
|
||||||
if (null === $this->requestContext) {
|
if (null === $this->requestStack) {
|
||||||
throw new \LogicException('You must pass a RequestContext.');
|
throw new \LogicException('You must pass a RequestStack.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $parentRequest = $this->requestContext->getParentRequest()) {
|
if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
|
||||||
$this->setRouterContext($parentRequest);
|
$this->setRouterContext($parentRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
|
|||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
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\MethodNotAllowedException;
|
||||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||||
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
|
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
|
||||||
@ -33,7 +33,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
* This listener works in 2 modes:
|
* This listener works in 2 modes:
|
||||||
*
|
*
|
||||||
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
|
* * 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>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
@ -43,12 +43,12 @@ class RouterListener implements EventSubscriberInterface
|
|||||||
private $context;
|
private $context;
|
||||||
private $logger;
|
private $logger;
|
||||||
private $request;
|
private $request;
|
||||||
private $kernelContext;
|
private $requestStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* 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 UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
|
||||||
* @param RequestContext|null $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
|
* @param RequestContext|null $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
|
||||||
@ -56,7 +56,7 @@ class RouterListener implements EventSubscriberInterface
|
|||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @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) {
|
if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
|
||||||
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
|
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
|
||||||
@ -68,7 +68,7 @@ class RouterListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
$this->matcher = $matcher;
|
$this->matcher = $matcher;
|
||||||
$this->context = $context ?: $matcher->getContext();
|
$this->context = $context ?: $matcher->getContext();
|
||||||
$this->kernelContext = $kernelContext;
|
$this->requestStack = $requestStack;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,11 +93,11 @@ class RouterListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
public function onKernelFinishRequest(FinishRequestEvent $event)
|
public function onKernelFinishRequest(FinishRequestEvent $event)
|
||||||
{
|
{
|
||||||
if (null === $this->kernelContext) {
|
if (null === $this->requestStack) {
|
||||||
throw new \LogicException('You must pass a RequestContext.');
|
throw new \LogicException('You must pass a RequestStack.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setRequest($this->kernelContext->getParentRequest());
|
$this->setRequest($this->requestStack->getParentRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onKernelRequest(GetResponseEvent $event)
|
public function onKernelRequest(GetResponseEvent $event)
|
||||||
@ -107,8 +107,8 @@ class RouterListener implements EventSubscriberInterface
|
|||||||
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
|
// 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
|
// 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
|
// with frameworks which do not use the Symfony service container
|
||||||
// when we have a RequestContext, no need to do it
|
// when we have a RequestStack, no need to do it
|
||||||
if (null !== $this->kernelContext) {
|
if (null !== $this->requestStack) {
|
||||||
$this->setRequest($request);
|
$this->setRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ namespace Symfony\Component\HttpKernel\Fragment;
|
|||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||||
use Symfony\Component\HttpKernel\RequestContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a URI that represents a resource fragment.
|
* Renders a URI that represents a resource fragment.
|
||||||
@ -26,7 +26,7 @@ use Symfony\Component\HttpKernel\RequestContext;
|
|||||||
* This listener works in 2 modes:
|
* This listener works in 2 modes:
|
||||||
*
|
*
|
||||||
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
|
* * 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>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*
|
*
|
||||||
@ -37,19 +37,19 @@ class FragmentHandler
|
|||||||
private $debug;
|
private $debug;
|
||||||
private $renderers;
|
private $renderers;
|
||||||
private $request;
|
private $request;
|
||||||
private $context;
|
private $requestStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* RequestContext will become required in 3.0.
|
* RequestStack will become required in 3.0.
|
||||||
*
|
*
|
||||||
* @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
|
* @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
|
||||||
* @param Boolean $debug Whether the debug mode is enabled or not
|
* @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();
|
$this->renderers = array();
|
||||||
foreach ($renderers as $renderer) {
|
foreach ($renderers as $renderer) {
|
||||||
$this->addRenderer($renderer);
|
$this->addRenderer($renderer);
|
||||||
@ -143,6 +143,6 @@ class FragmentHandler
|
|||||||
|
|
||||||
private function getRequest()
|
private function getRequest()
|
||||||
{
|
{
|
||||||
return $this->context ? $this->context->getCurrentRequest() : $this->request;
|
return $this->requestStack ? $this->requestStack->getCurrentRequest() : $this->request;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
|||||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||||
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
|
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\HttpKernel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registry for Requests.
|
|
||||||
*
|
|
||||||
* Facade for RequestStack that prevents modification of the stack,
|
|
||||||
* so that users don't accidentally push()/pop() from the stack and
|
|
||||||
* mess up the request cycle.
|
|
||||||
*
|
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
||||||
*/
|
|
||||||
class RequestContext
|
|
||||||
{
|
|
||||||
private $stack;
|
|
||||||
|
|
||||||
public function __construct(RequestStack $stack)
|
|
||||||
{
|
|
||||||
$this->stack = $stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Request|null
|
|
||||||
*/
|
|
||||||
public function getCurrentRequest()
|
|
||||||
{
|
|
||||||
return $this->stack->getCurrentRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Request|null
|
|
||||||
*/
|
|
||||||
public function getMasterRequest()
|
|
||||||
{
|
|
||||||
return $this->stack->getMasterRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Request|null
|
|
||||||
*/
|
|
||||||
public function getParentRequest()
|
|
||||||
{
|
|
||||||
return $this->stack->getParentRequest();
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,7 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel;
|
use Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel;
|
||||||
use Symfony\Component\HttpKernel\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
@ -60,7 +60,7 @@ class ContainerAwareHttpKernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
return $expected;
|
return $expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
$stack = $this->getMock('Symfony\Component\HttpKernel\RequestStack', array('push', 'pop'));
|
$stack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack', array('push', 'pop'));
|
||||||
$stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
|
$stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
|
||||||
$stack->expects($this->at(1))->method('pop');
|
$stack->expects($this->at(1))->method('pop');
|
||||||
|
|
||||||
|
@ -11,24 +11,24 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpKernel\RequestContext;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
|
|
||||||
class LocaleListenerTest extends \PHPUnit_Framework_TestCase
|
class LocaleListenerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $context;
|
private $requestStack;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->context = $this->getMock('Symfony\Component\HttpKernel\RequestContext', array(), array(), '', false);
|
$this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack', array(), array(), '', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultLocaleWithoutSession()
|
public function testDefaultLocaleWithoutSession()
|
||||||
{
|
{
|
||||||
$listener = new LocaleListener('fr', null, $this->context);
|
$listener = new LocaleListener('fr', null, $this->requestStack);
|
||||||
$event = $this->getEvent($request = Request::create('/'));
|
$event = $this->getEvent($request = Request::create('/'));
|
||||||
|
|
||||||
$listener->onKernelRequest($event);
|
$listener->onKernelRequest($event);
|
||||||
@ -42,7 +42,7 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$request->cookies->set('foo', 'value');
|
$request->cookies->set('foo', 'value');
|
||||||
|
|
||||||
$request->attributes->set('_locale', 'es');
|
$request->attributes->set('_locale', 'es');
|
||||||
$listener = new LocaleListener('fr', null, $this->context);
|
$listener = new LocaleListener('fr', null, $this->requestStack);
|
||||||
$event = $this->getEvent($request);
|
$event = $this->getEvent($request);
|
||||||
|
|
||||||
$listener->onKernelRequest($event);
|
$listener->onKernelRequest($event);
|
||||||
@ -61,7 +61,7 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
|
|
||||||
$request->attributes->set('_locale', 'es');
|
$request->attributes->set('_locale', 'es');
|
||||||
$listener = new LocaleListener('fr', $router, $this->context);
|
$listener = new LocaleListener('fr', $router, $this->requestStack);
|
||||||
$listener->onKernelRequest($this->getEvent($request));
|
$listener->onKernelRequest($this->getEvent($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +81,11 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$parentRequest = Request::create('/');
|
$parentRequest = Request::create('/');
|
||||||
$parentRequest->setLocale('es');
|
$parentRequest->setLocale('es');
|
||||||
|
|
||||||
$this->context->expects($this->once())->method('getParentRequest')->will($this->returnValue($parentRequest));
|
$this->requestStack->expects($this->once())->method('getParentRequest')->will($this->returnValue($parentRequest));
|
||||||
|
|
||||||
$event = $this->getMock('Symfony\Component\HttpKernel\Event\FinishRequestEvent', array(), array(), '', false);
|
$event = $this->getMock('Symfony\Component\HttpKernel\Event\FinishRequestEvent', array(), array(), '', false);
|
||||||
|
|
||||||
$listener = new LocaleListener('fr', $router, $this->context);
|
$listener = new LocaleListener('fr', $router, $this->requestStack);
|
||||||
$listener->onKernelFinishRequest($event);
|
$listener->onKernelFinishRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
$request->setLocale('de');
|
$request->setLocale('de');
|
||||||
$listener = new LocaleListener('fr', null, $this->context);
|
$listener = new LocaleListener('fr', null, $this->requestStack);
|
||||||
$event = $this->getEvent($request);
|
$event = $this->getEvent($request);
|
||||||
|
|
||||||
$listener->onKernelRequest($event);
|
$listener->onKernelRequest($event);
|
||||||
|
@ -11,20 +11,20 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\EventListener\RouterListener;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpKernel\RequestContext as KernelRequestContext;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpKernel\EventListener\RouterListener;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
use Symfony\Component\Routing\RequestContext;
|
use Symfony\Component\Routing\RequestContext;
|
||||||
|
|
||||||
class RouterListenerTest extends \PHPUnit_Framework_TestCase
|
class RouterListenerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $kernelContext;
|
private $requestStack;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->kernelContext = $this->getMock('Symfony\Component\HttpKernel\RequestContext', array(), array(), '', false);
|
$this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack', array(), array(), '', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +42,7 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method('getContext')
|
->method('getContext')
|
||||||
->will($this->returnValue($context));
|
->will($this->returnValue($context));
|
||||||
|
|
||||||
$listener = new RouterListener($urlMatcher, null, null, $this->kernelContext);
|
$listener = new RouterListener($urlMatcher, null, null, $this->requestStack);
|
||||||
$event = $this->createGetResponseEventForUri($uri);
|
$event = $this->createGetResponseEventForUri($uri);
|
||||||
$listener->onKernelRequest($event);
|
$listener->onKernelRequest($event);
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidMatcher()
|
public function testInvalidMatcher()
|
||||||
{
|
{
|
||||||
new RouterListener(new \stdClass(), null, null, $this->kernelContext);
|
new RouterListener(new \stdClass(), null, null, $this->requestStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequestMatcher()
|
public function testRequestMatcher()
|
||||||
@ -95,7 +95,7 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
|
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->kernelContext);
|
$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack);
|
||||||
$listener->onKernelRequest($event);
|
$listener->onKernelRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class RouterListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method('getContext')
|
->method('getContext')
|
||||||
->will($this->returnValue($context));
|
->will($this->returnValue($context));
|
||||||
|
|
||||||
$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->kernelContext);
|
$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack);
|
||||||
$listener->onKernelRequest($event);
|
$listener->onKernelRequest($event);
|
||||||
|
|
||||||
// sub-request with another HTTP method
|
// sub-request with another HTTP method
|
||||||
|
@ -17,15 +17,15 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
|
|
||||||
class FragmentHandlerTest extends \PHPUnit_Framework_TestCase
|
class FragmentHandlerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $context;
|
private $requestStack;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->context = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\RequestContext')
|
$this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock()
|
->getMock()
|
||||||
;
|
;
|
||||||
$this->context
|
$this->requestStack
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('getCurrentRequest')
|
->method('getCurrentRequest')
|
||||||
->will($this->returnValue(Request::create('/')))
|
->will($this->returnValue(Request::create('/')))
|
||||||
@ -37,7 +37,7 @@ class FragmentHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRenderWhenRendererDoesNotExist()
|
public function testRenderWhenRendererDoesNotExist()
|
||||||
{
|
{
|
||||||
$handler = new FragmentHandler(array(), null, $this->context);
|
$handler = new FragmentHandler(array(), null, $this->requestStack);
|
||||||
$handler->render('/', 'foo');
|
$handler->render('/', 'foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class FragmentHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
call_user_func_array(array($e, 'with'), $arguments);
|
call_user_func_array(array($e, 'with'), $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
$handler = new FragmentHandler(array(), null, $this->context);
|
$handler = new FragmentHandler(array(), null, $this->requestStack);
|
||||||
$handler->addRenderer($renderer);
|
$handler->addRenderer($renderer);
|
||||||
|
|
||||||
return $handler;
|
return $handler;
|
||||||
|
@ -242,7 +242,7 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
|
|
||||||
$stack = $this->getMock('Symfony\Component\HttpKernel\RequestStack', array('push', 'pop'));
|
$stack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack', array('push', 'pop'));
|
||||||
$stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
|
$stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
|
||||||
$stack->expects($this->at(1))->method('pop');
|
$stack->expects($this->at(1))->method('pop');
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.3",
|
"php": ">=5.3.3",
|
||||||
"symfony/event-dispatcher": "~2.1",
|
"symfony/event-dispatcher": "~2.1",
|
||||||
"symfony/http-foundation": "~2.2",
|
"symfony/http-foundation": "~2.4",
|
||||||
"symfony/debug": "~2.3",
|
"symfony/debug": "~2.3",
|
||||||
"psr/log": "~1.0"
|
"psr/log": "~1.0"
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user