8000 merged branch Tobion/redirectcontroller (PR #5368) · symfony/symfony@e080f5a · GitHub
[go: up one dir, main page]

Skip to content

Commit e080f5a

Browse files
committed
merged branch Tobion/redirectcontroller (PR #5368)
Commits ------- 3f8127c fixed '0' problem 7bec460 fixed phpdoc 4c5bfab [FrameworkBundle] non-permanent redirect should be status code 404 according to spec Discussion ---------- [FrameworkBundle] non-permanent redirect to unknown location with 404 according to spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html see 410 Gone bc break: tiny when omitting 2 parameter (I can avoid this with `func_num_args` but i think its not necessary and makes the code strange and inconsistent)
2 parents 0881bde + 3f8127c commit e080f5a

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
class RedirectController extends ContainerAware
2424
{
2525
/**
26-
* Redirects to another route.
26+
* Redirects to another route with the given name.
2727
*
28-
* It expects a route path parameter.
29-
* By default, the response status code is 301.
28+
* The response status code is 301 if the permanent parameter is false (default),
29+
* and 302 if the redirection is permanent.
3030
*
31-
* If the route is empty, the status code will be 410.
32-
* If the permanent path parameter is set, the status code will be 302.
31+
* In case the route name is empty, the status code will be 404 when permanent is false
32+
* and 410 otherwise.
3333
*
34-
* @param string $route The route pattern to redirect to
35-
* @param Boolean $permanent Whether the redirect is permanent or not
34+
* @param string $route The route name to redirect to
35+
* @param Boolean $permanent Whether the redirection is permanent
3636
*
3737
* @return Response A Response instance
3838
*/
3939
public function redirectAction($route, $permanent = false)
4040
{
41-
if (!$route) {
42-
return new Response(null, 410);
41+
if ('' == $route) {
42+
return new Response(null, $permanent ? 410 : 404);
4343
}
4444

4545
$attributes = $this->container->get('request')->attributes->get('_route_params');
@@ -51,13 +51,14 @@ public function redirectAction($route, $permanent = false)
5151
/**
5252
* Redirects to a URL.
5353
*
54-
* By default, the response status code is 301.
54+
* The response status code is 301 if the permanent parameter is false (default),
55+
* and 302 if the redirection is permanent.
5556
*
56-
* If the path is empty, the status code will be 410.
57-
* If the permanent flag is set, the status code will be 302.
57+
* In case the path is empty, the status code will be 404 when permanent is false
58+
* and 410 otherwise.
5859
*
59-
* @param string $path The path to redirect to
60-
* @param Boolean $permanent Whether the redirect is permanent or not
60+
* @param string $path The absolute path or URL to redirect to
61+
* @param Boolean $permanent Whether the redirection is permanent
6162
* @param Boolean $scheme The URL scheme (null to keep the current one)
6263
* @param integer $httpPort The HTTP port
6364
* @param integer $httpsPort The HTTPS port
@@ -66,8 +67,8 @@ public function redirectAction($route, $permanent = false)
6667
*/
6768
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
6869
{
69-
if (!$path) {
70-
return new Response(null, 410);
70+
if ('' == $path) {
71+
return new Response(null, $permanent ? 410 : 404);
7172
}
7273

7374
$statusCode = $permanent ? 301 : 302;

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ public function testEmptyRoute()
2929
$controller = new RedirectController();
3030
$controller->setContainer($container);
3131

32-
$returnResponse = $controller->redirectAction('');
33-
32+
$returnResponse = $controller->redirectAction('', true);
3433
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
35-
3634
$this->assertEquals(410, $returnResponse->getStatusCode());
35+
36+
$returnResponse = $controller->redirectAction('', false);
37+
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
38+
$this->assertEquals(404, $returnResponse->getStatusCode());
3739
}
3840

3941
/**
@@ -102,11 +104,14 @@ public function provider()
102104
public function testEmptyPath()
103105
{
104106
$controller = new RedirectController();
105-
$returnResponse = $controller->urlRedirectAction('');
106107

108+
$returnResponse = $controller->urlRedirectAction('', true);
107109
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
108-
109110
$this->assertEquals(410, $returnResponse->getStatusCode());
111+
112+
$returnResponse = $controller->urlRedirectAction('', false);
113+
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
114+
$this->assertEquals(404, $returnResponse->getStatusCode());
110115
}
111116

112117
public function testFullURL()

0 commit comments

Comments
 (0)
0