From 64b54dc587981971c17d8a1a45fe35fdbe3426a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Flode=CC=81n?= Date: Mon, 19 Nov 2012 20:08:12 +0100 Subject: [PATCH] Use better default ports in urlRedirectAction --- .../Controller/RedirectController.php | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php index 10d0a90a70..ea76b19e7e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php @@ -64,7 +64,7 @@ class RedirectController extends ContainerAware * * @return Response A Response instance */ - public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443) + public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = null, $httpsPort = null) { if (!$path) { return new Response(null, 410); @@ -88,10 +88,28 @@ class RedirectController extends ContainerAware } $port = ''; - if ('http' === $scheme && 80 != $httpPort) { - $port = ':'.$httpPort; - } elseif ('https' === $scheme && 443 != $httpsPort) { - $port = ':'.$httpsPort; + if ('http' === $scheme) { + if ($httpPort == null) { + if ('http' === $request->getScheme()) { + $httpPort = $request->getPort(); + } else { + $httpPort = $this->container->getParameter('request_listener.http_port'); + } + } + if ($httpPort != null && $httpPort != 80) { + $port = ":$httpPort"; + } + } else if ('https' === $scheme) { + if ($httpsPort == null) { + if ('https' === $request->getScheme()) { + $httpsPort = $request->getPort(); + } else { + $httpsPort = $this->container->getParameter('request_listener.https_port'); + } + } + if ($httpsPort != null && $httpsPort != 443) { + $port = ":$httpsPort"; + } } $url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;