Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed as many usage of the request service as possible without brea…

…king BC
  • Loading branch information...
commit d638369e2ac9bf051908c0398550ed73f56082c7 1 parent 7baeaa2
@fabpot fabpot authored
View
2  src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
@@ -62,7 +62,7 @@ public function generateUrl($route, $parameters = array(), $referenceType = UrlG
public function forward($controller, array $path = array(), array $query = array())
{
$path['_controller'] = $controller;
- $subRequest = $this->container->get('request')->duplicate($query, null, $path);
+ $subRequest = $this->container->get('request_stack')->getCurrentRequest()->duplicate($query, null, $path);
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
View
6 src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php
@@ -14,6 +14,7 @@
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
class ControllerTest extends TestCase
@@ -24,13 +25,16 @@ public function testForward()
$request->setLocale('fr');
$request->setRequestFormat('xml');
+ $requestStack = new RequestStack();
+ $requestStack->push($request);
+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
return new Response($request->getRequestFormat().'--'.$request->getLocale());
}));
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
- $container->expects($this->at(0))->method('get')->will($this->returnValue($request));
+ $container->expects($this->at(0))->method('get')->will($this->returnValue($requestStack));
$container->expects($this->at(1))->method('get')->will($this->returnValue($kernel));
$controller = new Controller();
View
14 ...undle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php
@@ -11,15 +11,15 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\DependencyInjection\ContainerAware;
class SessionController extends ContainerAware
{
- public function welcomeAction($name=null)
+ public function welcomeAction(Request $request, $name=null)
{
- $request = $this->container->get('request');
$session = $request->getSession();
// new session case
@@ -40,25 +40,23 @@ public function welcomeAction($name=null)
return new Response(sprintf('Welcome back %s, nice to meet you.', $name));
}
- public function logoutAction()
+ public function logoutAction(Request $request)
{
- $request = $this->container->get('request')->getSession('session')->invalidate();
+ $request->getSession('session')->invalidate();
return new Response('Session cleared.');
}
- public function setFlashAction($message)
+ public function setFlashAction(Request $request, $message)
{
- $request = $this->container->get('request');
$session = $request->getSession();
$session->getFlashBag()->set('notice', $message);
return new RedirectResponse($this->container->get('router')->generate('session_showflash'));
}
- public function showFlashAction()
+ public function showFlashAction(Request $request)
{
- $request = $this->container->get('request');
$session = $request->getSession();
if ($session->getFlashBag()->has('notice')) {
View
58 src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php
@@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
+use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Translation\MessageSelector;
@@ -86,43 +87,46 @@ public function testTransWithCaching()
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
}
- public function testGetLocale()
+ /**
+ * @dataProvider getGetLocaleData
+ */
+ public function testGetLocale($inRequestScope)
{
- $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
-
- $request
- ->expects($this->once())
- ->method('getLocale')
- ->will($this->returnValue('en'))
- ;
+ $requestStack = new RequestStack();
+ if ($inRequestScope) {
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $request
+ ->expects($this->once())
+ ->method('getLocale')
+ ->will($this->returnValue('en'))
+ ;
+
+ $requestStack->push($request);
+ }
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
-
- $container
- ->expects($this->exactly(2))
- ->method('isScopeActive')
- ->with('request')
- ->will($this->onConsecutiveCalls(false, true))
- ;
-
- $container
- ->expects($this->once())
- ->method('has')
- ->with('request')
- ->will($this->returnValue(true))
- ;
-
$container
->expects($this->once())
->method('get')
- ->with('request')
- ->will($this->returnValue($request))
+ ->with('request_stack')
+ ->will($this->returnValue($requestStack))
;
$translator = new Translator($container, new MessageSelector());
- $this->assertNull($translator->getLocale());
- $this->assertSame('en', $translator->getLocale());
+ if ($inRequestScope) {
+ $this->assertSame('en', $translator->getLocale());
+ } else {
+ $this->assertNull($translator->getLocale());
+ }
+ }
+
+ public function getGetLocaleData()
+ {
+ return array(
+ array(false),
+ array(true),
+ );
}
protected function getCatalogue($locale, $messages)
View
4 src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
@@ -65,8 +65,8 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
*/
public function getLocale()
{
- if (null === $this->locale && $this->container->isScopeActive('request') && $this->container->has('request')) {
- $this->locale = $this->container->get('request')->getLocale();
+ if (null === $this->locale && $request = $this->container->get('request_stack')->getCurrentRequest()) {
+ $this->locale = $request->getLocale();
}
return $this->locale;
View
2  src/Symfony/Bundle/SecurityBundle/Templating/Helper/LogoutUrlHelper.php
@@ -106,7 +106,7 @@ private function generateLogoutUrl($key, $referenceType)
$parameters = null !== $csrfTokenManager ? array($csrfParameter => (string) $csrfTokenManager->getToken($csrfTokenId)) : array();
if ('/' === $logoutPath[0]) {
- $request = $this->container->get('request');
+ $request = $this->container->get('request_stack')->getCurrentRequest();
$url = UrlGeneratorInterface::ABSOLUTE_URL === $referenceType ? $request->getUriForPath($logoutPath) : $request->getBasePath().$logoutPath;
View
11 ...SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LocalizedController.php
@@ -12,23 +12,24 @@
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
use Symfony\Component\Security\Core\SecurityContext;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerAware;
class LocalizedController extends ContainerAware
{
- public function loginAction()
+ public function loginAction(Request $request)
{
// get the login error if there is one
- if ($this->container->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
- $error = $this->container->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
+ if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
+ $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
- $error = $this->container->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
+ $error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->container->get('templating')->renderResponse('FormLoginBundle:Localized:login.html.twig', array(
// last username entered by the user
- 'last_username' => $this->container->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
+ 'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
View
11 ...dle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LoginController.php
@@ -12,24 +12,25 @@
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\DependencyInjection\ContainerAware;
class LoginController extends ContainerAware
{
- public function loginAction()
+ public function loginAction(Request $request)
{
// get the login error if there is one
- if ($this->container->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
- $error = $this->container->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
+ if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
+ $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
- $error = $this->container->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
+ $error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->container->get('templating')->renderResponse('FormLoginBundle:Login:login.html.twig', array(
// last username entered by the user
- 'last_username' => $this->container->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
+ 'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
Please sign in to comment.
Something went wrong with that request. Please try again.