Skip to content
This repository
Browse code

merged branch Seldaek/route_redirect (PR #3074)

Commits
-------

af32590 [FrameworkBundle] Use only _route_params to generate redirect routes

Discussion
----------

[FrameworkBundle] Use only _route_params to generate redirect routes

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

Routes in RedirectController are generated using all request attributes, which is inconvenient since I abuse request attributes to store other things (device types and such) relevant to the app. It renders the RedirectController useless since it adds unrelated query parameters to URLs it creates.
  • Loading branch information...
commit 009e6d739e5d133848b61563de50a5fbc774ccfb 2 parents a3ddc8e + af32590
Fabien Potencier fabpot authored
4 src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
@@ -42,8 +42,8 @@ public function redirectAction($route, $permanent = false)
42 42 return new Response(null, 410);
43 43 }
44 44
45   - $attributes = $this->container->get('request')->attributes->all();
46   - unset($attributes['_route'], $attributes['route'], $attributes['permanent'] );
  45 + $attributes = $this->container->get('request')->attributes->get('_route_params');
  46 + unset($attributes['route'], $attributes['permanent']);
47 47
48 48 return new RedirectResponse($this->container->get('router')->generate($route, $attributes), $permanent ? 301 : 302);
49 49 }
12 src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php
@@ -46,8 +46,18 @@ public function testRoute($permanent, $expectedCode)
46 46 $route = 'new-route';
47 47 $url = '/redirect-url';
48 48 $params = array('additional-parameter' => 'value');
  49 + $attributes = array(
  50 + 'route' => $route,
  51 + 'permanent' => $permanent,
  52 + '_route' => 'current-route',
  53 + '_route_params' => array(
  54 + 'route' => $route,
  55 + 'permanent' => $permanent,
  56 + ),
  57 + );
  58 + $attributes['_route_params'] = $attributes['_route_params'] + $params;
49 59
50   - $request->attributes = new ParameterBag(array('route' => $route, '_route' => 'current-route', 'permanent' => $permanent) + $params);
  60 + $request->attributes = new ParameterBag($attributes);
51 61
52 62 $router = $this->getMock('Symfony\Component\Routing\RouterInterface');
53 63 $router

0 comments on commit 009e6d7

Please sign in to comment.
Something went wrong with that request. Please try again.