feature #9546 [FrameworkBundle] use the new request_stack service in the GlobalVariables object (hhamon)

This PR was merged into the master branch.

Discussion
----------

[FrameworkBundle] use the new request_stack service in the GlobalVariables object

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Commits
-------

9c2ce49 [FrameworkBundle] use the new request_stack object in the GlobalVariables object
This commit is contained in:
Fabien Potencier 2013-11-22 17:52:08 +01:00
commit 8d8b3db758
2 changed files with 9 additions and 6 deletions

View File

@ -78,8 +78,8 @@ class GlobalVariables
*/
public function getRequest()
{
if ($this->container->has('request') && $request = $this->container->get('request')) {
return $request;
if ($this->container->has('request_stack')) {
return $this->container->get('request_stack')->getCurrentRequest();
}
}

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
use Symfony\Bundle\FrameworkBundle\Templating\PhpEngine;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Templating\TemplateNameParser;
@ -37,7 +38,7 @@ class PhpEngineTest extends TestCase
$loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
$engine = new PhpEngine(new TemplateNameParser(), $container, $loader, new GlobalVariables($container));
$container->set('request', null);
$container->set('request_stack', null);
$globals = $engine->getGlobals();
$this->assertEmpty($globals['app']->getRequest());
@ -63,11 +64,13 @@ class PhpEngineTest extends TestCase
protected function getContainer()
{
$container = new Container();
$request = new Request();
$session = new Session(new MockArraySessionStorage());
$session = new Session(new MockArraySessionStorage());
$request = new Request();
$stack = new RequestStack();
$stack->push($request);
$request->setSession($session);
$container->set('request', $request);
$container->set('request_stack', $stack);
return $container;
}