From 21eafabe25feb19f0338a5ca4719660c1ac1fd14 Mon Sep 17 00:00:00 2001 From: cchandon Date: Sun, 25 Jan 2015 20:23:25 -0500 Subject: [PATCH 01/13] Add HTTP non standard port support for route with specific host (cherry picked from commit 665dc6e) --- Command/DumpCommand.php | 1 + Controller/Controller.php | 1 + Extractor/ExposedRoutesExtractor.php | 17 ++++++++++++--- Extractor/ExposedRoutesExtractorInterface.php | 7 +++++++ Resources/js/router.js | 21 +++++++++++++++++-- Response/RoutesResponse.php | 21 ++++++++++++------- .../Normalizer/RoutesResponseNormalizer.php | 11 +++++----- Tests/Controller/ControllerTest.php | 10 ++++----- .../RoutesResponseNormalizerTest.php | 1 + 9 files changed, 68 insertions(+), 22 deletions(-) diff --git a/Command/DumpCommand.php b/Command/DumpCommand.php index 88929bba..dddfe305 100644 --- a/Command/DumpCommand.php +++ b/Command/DumpCommand.php @@ -167,6 +167,7 @@ private function doDump(InputInterface $input, OutputInterface $output) $extractor->getRoutes(), $extractor->getPrefix($input->getOption('locale')), $extractor->getHost(), + $extractor->getPortExtension(), $extractor->getScheme() ), 'json', diff --git a/Controller/Controller.php b/Controller/Controller.php index aea785f0..4bd56588 100644 --- a/Controller/Controller.php +++ b/Controller/Controller.php @@ -96,6 +96,7 @@ public function indexAction(Request $request, $_format) $exposedRoutes, $this->exposedRoutesExtractor->getPrefix($request->getLocale()), $this->exposedRoutesExtractor->getHost(), + $this->exposedRoutesExtractor->getPortExtension(), $this->exposedRoutesExtractor->getScheme(), $request->getLocale() ); diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index 15933617..eaba3d29 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -104,14 +104,25 @@ public function getHost() { $requestContext = $this->router->getContext(); - $host = $requestContext->getHost(); + $host = $requestContext->getHost().$this->getPortExtension(); + return $host; + } + + /** + * {@inheritDoc} + */ + public function getPortExtension() + { + $requestContext = $this->router->getContext(); + + $port=""; if ($this->usesNonStandardPort()) { $method = sprintf('get%sPort', ucfirst($requestContext->getScheme())); - $host .= ':' . $requestContext->$method(); + $port = ':' . $requestContext->$method(); } - return $host; + return $port; } /** diff --git a/Extractor/ExposedRoutesExtractorInterface.php b/Extractor/ExposedRoutesExtractorInterface.php index 2db32f63..562ea655 100644 --- a/Extractor/ExposedRoutesExtractorInterface.php +++ b/Extractor/ExposedRoutesExtractorInterface.php @@ -49,6 +49,13 @@ public function getPrefix($locale); */ public function getHost(); + /** + * Get the port extension from RequestContext, only if non standard port (Eg: ":8080") + * + * @return string + */ + public function getPortExtension(); + /** * Get the scheme from RequestContext * diff --git a/Resources/js/router.js b/Resources/js/router.js index 4e594bb8..9ee4f7e6 100644 --- a/Resources/js/router.js +++ b/Resources/js/router.js @@ -19,7 +19,7 @@ class Router { * @param {Object.=} routes */ constructor(context, routes) { - this.context_ = context || {base_url: '', prefix: '', host: '', scheme: ''}; + this.context_ = context || {base_url: '', prefix: '', host: '', portextension: '', scheme: ''}; this.setRoutes(routes || {}); } @@ -120,6 +120,20 @@ class Router { return this.context_.host; } + /** + * @param {string} portextension + */ + setPortExtension(portextension) { + this.context_.portextension = portextension; + } + + /** + * @return {string} + */ + getPortExtension() { + return this.context_.portextension; + }; + /** * Builds query string params added to a URL. * Port of jQuery's $.param() function, so credit is due there. @@ -184,7 +198,8 @@ class Router { unusedParams = Object.assign({}, params), url = '', optional = true, - host = ''; + host = '', + portextension = this.getPortExtension(); route.tokens.forEach((token) => { if ('text' === token[0]) { @@ -263,6 +278,8 @@ class Router { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; + } else if (host && this.getHost() !== host + portextension) { + url = this.getScheme() + "://" + host + portextension + url; } else if (host && this.getHost() !== host) { url = this.getScheme() + "://" + host + url; } else if (absolute === true) { diff --git a/Response/RoutesResponse.php b/Response/RoutesResponse.php index 14116e3e..f2b61c8f 100644 --- a/Response/RoutesResponse.php +++ b/Response/RoutesResponse.php @@ -19,17 +19,19 @@ class RoutesResponse private $routes; private $prefix; private $host; + private $portextension; private $scheme; private $locale; - public function __construct($baseUrl, RouteCollection $routes = null, $prefix = null, $host = null, $scheme = null, $locale = null) + public function __construct($baseUrl, RouteCollection $routes = null, $prefix = null, $host = null, $portextension = null, $scheme = null, $locale = null) { - $this->baseUrl = $baseUrl; - $this->routes = $routes ?: new RouteCollection(); - $this->prefix = $prefix; - $this->host = $host; - $this->scheme = $scheme; - $this->locale = $locale; + $this->baseUrl = $baseUrl; + $this->routes = $routes ?: new RouteCollection(); + $this->prefix = $prefix; + $this->host = $host; + $this->portextension = $portextension; + $this->scheme = $scheme; + $this->locale = $locale; } public function getBaseUrl() @@ -74,6 +76,11 @@ public function getHost() return $this->host; } + public function getPortExtension() + { + return $this->portextension; + } + public function getScheme() { return $this->scheme; diff --git a/Serializer/Normalizer/RoutesResponseNormalizer.php b/Serializer/Normalizer/RoutesResponseNormalizer.php index ca659d19..3020bd1e 100644 --- a/Serializer/Normalizer/RoutesResponseNormalizer.php +++ b/Serializer/Normalizer/RoutesResponseNormalizer.php @@ -25,11 +25,12 @@ class RoutesResponseNormalizer implements NormalizerInterface public function normalize($data, $format = null, array $context = array()) { return array( - 'base_url' => $data->getBaseUrl(), - 'routes' => $data->getRoutes(), - 'prefix' => $data->getPrefix(), - 'host' => $data->getHost(), - 'scheme' => $data->getScheme(), + 'base_url' => $data->getBaseUrl(), + 'routes' => $data->getRoutes(), + 'prefix' => $data->getPrefix(), + 'host' => $data->getHost(), + 'portextension' => $data->getPortExtension(), + 'scheme' => $data->getScheme(), ); } diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index 6d4a2500..fd55cbe3 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -49,7 +49,7 @@ public function testIndexAction() $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); } public function testIndexActionWithLocalizedRoutes() @@ -65,7 +65,7 @@ public function testIndexActionWithLocalizedRoutes() $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","_locale"],["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":{"_locale":"en"},"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","_locale"],["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":{"_locale":"en"},"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); } public function testConfigCache() @@ -79,11 +79,11 @@ public function testConfigCache() ); $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); // second call should serve the cached content $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); } /** @@ -95,7 +95,7 @@ public function testGenerateWithCallback($callback) $response = $controller->indexAction($this->getRequest('/', 'GET', array('callback' => $callback)), 'json'); $this->assertEquals( - sprintf('/**/%s({"base_url":"","routes":[],"prefix":"","host":"","scheme":""});', $callback), + sprintf('/**/%s({"base_url":"","routes":[],"prefix":"","host":"","portextension":null,"scheme":""});', $callback), $response->getContent() ); } diff --git a/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php b/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php index f8ce397b..280d248f 100644 --- a/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php +++ b/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php @@ -60,6 +60,7 @@ public function testNormalize() 'routes' => array(), 'prefix' => 'prefix', 'host' => 'host', + 'portextension' => null, 'scheme' => 'scheme', ); From 13708a0532eab14956aec0df3ad1068ab6b169e8 Mon Sep 17 00:00:00 2001 From: DSanchez Date: Thu, 26 Apr 2018 18:54:47 -0400 Subject: [PATCH 02/13] Gulp sources --- Resources/public/js/router.js | 33 ++++++++++++++++++++++++++----- Resources/public/js/router.min.js | 2 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Resources/public/js/router.js b/Resources/public/js/router.js index a5447d51..d613522a 100644 --- a/Resources/public/js/router.js +++ b/Resources/public/js/router.js @@ -48,7 +48,7 @@ var Router = function () { function Router(context, routes) { _classCallCheck(this, Router); - this.context_ = context || { base_url: '', prefix: '', host: '', scheme: '' }; + this.context_ = context || { base_url: '', prefix: '', host: '', portextension: '', scheme: '' }; this.setRoutes(routes || {}); } @@ -168,6 +168,29 @@ var Router = function () { return this.context_.host; } + /** + * @param {string} portextension + */ + + }, { + key: 'setPortExtension', + value: function setPortExtension(portextension) { + this.context_.portextension = portextension; + } + + /** + * @return {string} + */ + + }, { + key: 'getPortExtension', + value: function getPortExtension() { + return this.context_.portextension; + } + }, { + key: 'buildQueryParams', + + /** * Builds query string params added to a URL. * Port of jQuery's $.param() function, so credit is due there. @@ -176,9 +199,6 @@ var Router = function () { * @param {Array|Object|string} params * @param {Function} add */ - - }, { - key: 'buildQueryParams', value: function buildQueryParams(prefix, params, add) { var _this = this; @@ -243,7 +263,8 @@ var Router = function () { unusedParams = _extends({}, params), url = '', optional = true, - host = ''; + host = '', + portextension = this.getPortExtension(); route.tokens.forEach(function (token) { if ('text' === token[0]) { @@ -322,6 +343,8 @@ var Router = function () { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; + } else if (host && this.getHost() !== host + portextension) { + url = this.getScheme() + "://" + host + portextension + url; } else if (host && this.getHost() !== host) { url = this.getScheme() + "://" + host + url; } else if (absolute === true) { diff --git a/Resources/public/js/router.min.js b/Resources/public/js/router.min.js index 77ceaea9..f9f84851 100644 --- a/Resources/public/js/router.min.js +++ b/Resources/public/js/router.min.js @@ -1 +1 @@ -!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t0){var c=void 0,l=[],h=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(c in s)this.buildQueryParams(c,s[c],h);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file +!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file From f61c519f080d1f433213dc20c5369e2f357e9751 Mon Sep 17 00:00:00 2001 From: DSanchez Date: Thu, 26 Apr 2018 19:33:04 -0400 Subject: [PATCH 03/13] Fixing JS, missing call to `setPortExtension()` --- Resources/js/router.js | 3 +++ Resources/public/js/router.js | 3 +++ Resources/public/js/router.min.js | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Resources/js/router.js b/Resources/js/router.js index 9ee4f7e6..e91b4b61 100644 --- a/Resources/js/router.js +++ b/Resources/js/router.js @@ -52,6 +52,9 @@ class Router { if ('prefix' in data) { this.setPrefix(data['prefix']); } + if ('portextension' in data) { + this.setPortExtension(data['portextension']); + } this.setHost(data['host']); this.setScheme(data['scheme']); diff --git a/Resources/public/js/router.js b/Resources/public/js/router.js index d613522a..f269cd78 100644 --- a/Resources/public/js/router.js +++ b/Resources/public/js/router.js @@ -73,6 +73,9 @@ var Router = function () { if ('prefix' in data) { this.setPrefix(data['prefix']); } + if ('portextension' in data) { + this.setPortExtension(data['portextension']); + } this.setHost(data['host']); this.setScheme(data['scheme']); diff --git a/Resources/public/js/router.min.js b/Resources/public/js/router.min.js index f9f84851..5fb72df7 100644 --- a/Resources/public/js/router.min.js +++ b/Resources/public/js/router.min.js @@ -1 +1 @@ -!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file +!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file From 254f896ddbe23785a772efd2ec4051bf17415895 Mon Sep 17 00:00:00 2001 From: DSanchez Date: Thu, 26 Apr 2018 20:02:54 -0400 Subject: [PATCH 04/13] Fixing test failure --- Tests/Controller/ControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index fd55cbe3..3f7ecb60 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -122,7 +122,7 @@ public function testIndexActionWithoutRoutes() $controller = new Controller($this->getSerializer(), $this->getExtractor(), array(), sys_get_temp_dir()); $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":[],"prefix":"","host":"","scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":[],"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); From 80ff420abe1cb4a247cd7672d66b1f550cfc7ea6 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Wed, 20 Jun 2018 16:22:42 -0400 Subject: [PATCH 05/13] Update code to undefined `portextension` --- Resources/js/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/js/router.js b/Resources/js/router.js index b0bc1bbf..efdf0e9d 100644 --- a/Resources/js/router.js +++ b/Resources/js/router.js @@ -281,7 +281,7 @@ class Router { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && this.getHost() !== host + portextension) { + } else if (host && "undefined" !== typeof portextension && this.getHost() !== host + portextension) { url = this.getScheme() + "://" + host + portextension + url; } else if (host && this.getHost() !== host) { url = this.getScheme() + "://" + host + url; From 793bcdd324d074f8a5c073c5cf4f57a4c1ce4c93 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Wed, 20 Jun 2018 16:30:16 -0400 Subject: [PATCH 06/13] Fixing code, adding missing colon separator --- Resources/js/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/js/router.js b/Resources/js/router.js index efdf0e9d..43cc40bd 100644 --- a/Resources/js/router.js +++ b/Resources/js/router.js @@ -282,7 +282,7 @@ class Router { } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; } else if (host && "undefined" !== typeof portextension && this.getHost() !== host + portextension) { - url = this.getScheme() + "://" + host + portextension + url; + url = this.getScheme() + "://" + host + ":" + portextension + url; } else if (host && this.getHost() !== host) { url = this.getScheme() + "://" + host + url; } else if (absolute === true) { From 9677c2f1fd88b010321e80ccac621b3570737ff5 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Wed, 20 Jun 2018 16:30:48 -0400 Subject: [PATCH 07/13] Adding `portextension` tests --- Resources/js/router.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Resources/js/router.test.js b/Resources/js/router.test.js index 611b09b7..1656d40f 100644 --- a/Resources/js/router.test.js +++ b/Resources/js/router.test.js @@ -406,3 +406,19 @@ function testGenerateWithNullValue() { assertEquals('/blog-post//10', router.generate('posts', { page: null, id: 10 })); } + +function testGenerateWithPortExtension() { + var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http", portextension: 443}, { + homepage: { + tokens: [['text', '/bar']], + defaults: {subdomain: 'api'}, + requirements: {}, + hosttokens: [ + ['text', '.localhost'], + ['variable', '', '', 'subdomain'] + ] + } + }); + + assertEquals('http://api.localhost:443/foo/bar', router.generate('homepage')); +} From 42fd6a7234aea6782a94f5eb5328940006347150 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Wed, 20 Jun 2018 16:31:08 -0400 Subject: [PATCH 08/13] Update sources and gulped version --- Resources/public/js/router.js | 4 ++-- Resources/public/js/router.min.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/public/js/router.js b/Resources/public/js/router.js index 72424cfe..1342798e 100644 --- a/Resources/public/js/router.js +++ b/Resources/public/js/router.js @@ -348,8 +348,8 @@ var Router = function () { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && this.getHost() !== host + portextension) { - url = this.getScheme() + "://" + host + portextension + url; + } else if (host && "undefined" !== typeof portextension && this.getHost() !== host + portextension) { + url = this.getScheme() + "://" + host + ":" + portextension + url; } else if (host && this.getHost() !== host) { url = this.getScheme() + "://" + host + url; } else if (absolute === true) { diff --git a/Resources/public/js/router.min.js b/Resources/public/js/router.min.js index 5fb72df7..2aedd118 100644 --- a/Resources/public/js/router.min.js +++ b/Resources/public/js/router.min.js @@ -1 +1 @@ -!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file +!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],i=this.getRoute(e),r=n||{},s=t({},r),u="",f=!0,a="",c=this.getPortExtension();if(i.tokens.forEach(function(t){if("text"===t[0])return u=t[1]+u,void(f=!1);{if("variable"!==t[0])throw new Error('The token type "'+t[0]+'" is not supported.');var n=i.defaults&&t[3]in i.defaults;if(!1===f||!n||t[3]in r&&r[t[3]]!=i.defaults[t[3]]){var o=void 0;if(t[3]in r)o=r[t[3]],delete s[t[3]];else{if(!n){if(f)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=i.defaults[t[3]]}var a=!0===o||!1===o||""===o;if(!a||!f){var c=encodeURIComponent(o).replace(/%2F/g,"/");"null"===c&&null===o&&(c=""),u=t[1]+c+u}f=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===u&&(u="/"),i.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(a=e[1]+a):void("variable"===e[0]&&(e[3]in r?(t=r[e[3]],delete s[e[3]]):i.defaults&&e[3]in i.defaults&&(t=i.defaults[e[3]]),a=e[1]+t+a))}),u=this.context_.base_url+u,i.requirements&&"_scheme"in i.requirements&&this.getScheme()!=i.requirements._scheme?u=i.requirements._scheme+"://"+(a||this.getHost())+u:"undefined"!=typeof i.schemes&&"undefined"!=typeof i.schemes[0]&&this.getScheme()!==i.schemes[0]?u=i.schemes[0]+"://"+(a||this.getHost())+u:a&&"undefined"!=typeof c&&this.getHost()!==a+c?u=this.getScheme()+"://"+a+":"+c+u:a&&this.getHost()!==a?u=this.getScheme()+"://"+a+u:o===!0&&(u=this.getScheme()+"://"+this.getHost()+u),Object.keys(s).length>0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file From 5e24c18298dcd7fac53c7a5dcf4afe32d2f54422 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Mon, 30 Jul 2018 13:41:21 -0400 Subject: [PATCH 09/13] Fixing issue reported by @dmaicher in: https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/320#issuecomment-408902080 --- Resources/js/router.js | 8 +++----- Resources/public/js/router.js | 8 +++----- Resources/public/js/router.min.js | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Resources/js/router.js b/Resources/js/router.js index 43cc40bd..452c8330 100644 --- a/Resources/js/router.js +++ b/Resources/js/router.js @@ -202,7 +202,7 @@ class Router { url = '', optional = true, host = '', - portextension = this.getPortExtension(); + portextension = (typeof this.getPortExtension() == "undefined" || this.getPortExtension() === null) ? '' : this.getPortExtension(); route.tokens.forEach((token) => { if ('text' === token[0]) { @@ -281,10 +281,8 @@ class Router { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && "undefined" !== typeof portextension && this.getHost() !== host + portextension) { - url = this.getScheme() + "://" + host + ":" + portextension + url; - } else if (host && this.getHost() !== host) { - url = this.getScheme() + "://" + host + url; + } else if (host && this.getHost() !== host + portextension) { + url = this.getScheme() + "://" + host + portextension + url; } else if (absolute === true) { url = this.getScheme() + "://" + this.getHost() + url; } diff --git a/Resources/public/js/router.js b/Resources/public/js/router.js index 1342798e..01bf9902 100644 --- a/Resources/public/js/router.js +++ b/Resources/public/js/router.js @@ -269,7 +269,7 @@ var Router = function () { url = '', optional = true, host = '', - portextension = this.getPortExtension(); + portextension = typeof this.getPortExtension() == "undefined" || this.getPortExtension() === null ? '' : this.getPortExtension(); route.tokens.forEach(function (token) { if ('text' === token[0]) { @@ -348,10 +348,8 @@ var Router = function () { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && "undefined" !== typeof portextension && this.getHost() !== host + portextension) { - url = this.getScheme() + "://" + host + ":" + portextension + url; - } else if (host && this.getHost() !== host) { - url = this.getScheme() + "://" + host + url; + } else if (host && this.getHost() !== host + portextension) { + url = this.getScheme() + "://" + host + portextension + url; } else if (absolute === true) { url = this.getScheme() + "://" + this.getHost() + url; } diff --git a/Resources/public/js/router.min.js b/Resources/public/js/router.min.js index 2aedd118..ee29c18a 100644 --- a/Resources/public/js/router.min.js +++ b/Resources/public/js/router.min.js @@ -1 +1 @@ -!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],i=this.getRoute(e),r=n||{},s=t({},r),u="",f=!0,a="",c=this.getPortExtension();if(i.tokens.forEach(function(t){if("text"===t[0])return u=t[1]+u,void(f=!1);{if("variable"!==t[0])throw new Error('The token type "'+t[0]+'" is not supported.');var n=i.defaults&&t[3]in i.defaults;if(!1===f||!n||t[3]in r&&r[t[3]]!=i.defaults[t[3]]){var o=void 0;if(t[3]in r)o=r[t[3]],delete s[t[3]];else{if(!n){if(f)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=i.defaults[t[3]]}var a=!0===o||!1===o||""===o;if(!a||!f){var c=encodeURIComponent(o).replace(/%2F/g,"/");"null"===c&&null===o&&(c=""),u=t[1]+c+u}f=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===u&&(u="/"),i.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(a=e[1]+a):void("variable"===e[0]&&(e[3]in r?(t=r[e[3]],delete s[e[3]]):i.defaults&&e[3]in i.defaults&&(t=i.defaults[e[3]]),a=e[1]+t+a))}),u=this.context_.base_url+u,i.requirements&&"_scheme"in i.requirements&&this.getScheme()!=i.requirements._scheme?u=i.requirements._scheme+"://"+(a||this.getHost())+u:"undefined"!=typeof i.schemes&&"undefined"!=typeof i.schemes[0]&&this.getScheme()!==i.schemes[0]?u=i.schemes[0]+"://"+(a||this.getHost())+u:a&&"undefined"!=typeof c&&this.getHost()!==a+c?u=this.getScheme()+"://"+a+":"+c+u:a&&this.getHost()!==a?u=this.getScheme()+"://"+a+u:o===!0&&(u=this.getScheme()+"://"+this.getHost()+u),Object.keys(s).length>0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file +!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],i=this.getRoute(e),r=n||{},s=t({},r),u="",f=!0,a="",c="undefined"==typeof this.getPortExtension()||null===this.getPortExtension()?"":this.getPortExtension();if(i.tokens.forEach(function(t){if("text"===t[0])return u=t[1]+u,void(f=!1);{if("variable"!==t[0])throw new Error('The token type "'+t[0]+'" is not supported.');var n=i.defaults&&t[3]in i.defaults;if(!1===f||!n||t[3]in r&&r[t[3]]!=i.defaults[t[3]]){var o=void 0;if(t[3]in r)o=r[t[3]],delete s[t[3]];else{if(!n){if(f)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=i.defaults[t[3]]}var a=!0===o||!1===o||""===o;if(!a||!f){var c=encodeURIComponent(o).replace(/%2F/g,"/");"null"===c&&null===o&&(c=""),u=t[1]+c+u}f=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===u&&(u="/"),i.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(a=e[1]+a):void("variable"===e[0]&&(e[3]in r?(t=r[e[3]],delete s[e[3]]):i.defaults&&e[3]in i.defaults&&(t=i.defaults[e[3]]),a=e[1]+t+a))}),u=this.context_.base_url+u,i.requirements&&"_scheme"in i.requirements&&this.getScheme()!=i.requirements._scheme?u=i.requirements._scheme+"://"+(a||this.getHost())+u:"undefined"!=typeof i.schemes&&"undefined"!=typeof i.schemes[0]&&this.getScheme()!==i.schemes[0]?u=i.schemes[0]+"://"+(a||this.getHost())+u:a&&this.getHost()!==a+c?u=this.getScheme()+"://"+a+c+u:o===!0&&(u=this.getScheme()+"://"+this.getHost()+u),Object.keys(s).length>0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file From 59acf3479c3d6f252463243cc96ae43ad74dd26f Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Wed, 1 Aug 2018 17:12:39 -0400 Subject: [PATCH 10/13] Fixing issue about `portextension`. Append color `:` only when *host + port* are used in JS and Extractor --- Extractor/ExposedRoutesExtractor.php | 4 ++-- Resources/js/router.js | 4 ++-- Resources/public/js/router.js | 4 ++-- Resources/public/js/router.min.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index eaba3d29..d89c0953 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -104,7 +104,7 @@ public function getHost() { $requestContext = $this->router->getContext(); - $host = $requestContext->getHost().$this->getPortExtension(); + $host = $requestContext->getHost() . ('' === $this->getPortExtension() ?: ':' . $this->getPortExtension()); return $host; } @@ -119,7 +119,7 @@ public function getPortExtension() $port=""; if ($this->usesNonStandardPort()) { $method = sprintf('get%sPort', ucfirst($requestContext->getScheme())); - $port = ':' . $requestContext->$method(); + $port = $requestContext->$method(); } return $port; diff --git a/Resources/js/router.js b/Resources/js/router.js index 452c8330..e23e50b8 100644 --- a/Resources/js/router.js +++ b/Resources/js/router.js @@ -281,8 +281,8 @@ class Router { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && this.getHost() !== host + portextension) { - url = this.getScheme() + "://" + host + portextension + url; + } else if (host && this.getHost() !== host + ('' === portextension ? '' : ':' + portextension)) { + url = this.getScheme() + "://" + host + ('' === portextension ? '' : ':' + portextension) + url; } else if (absolute === true) { url = this.getScheme() + "://" + this.getHost() + url; } diff --git a/Resources/public/js/router.js b/Resources/public/js/router.js index 01bf9902..d00829ce 100644 --- a/Resources/public/js/router.js +++ b/Resources/public/js/router.js @@ -348,8 +348,8 @@ var Router = function () { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && this.getHost() !== host + portextension) { - url = this.getScheme() + "://" + host + portextension + url; + } else if (host && this.getHost() !== host + ('' === portextension ? '' : ':' + portextension)) { + url = this.getScheme() + "://" + host + ('' === portextension ? '' : ':' + portextension) + url; } else if (absolute === true) { url = this.getScheme() + "://" + this.getHost() + url; } diff --git a/Resources/public/js/router.min.js b/Resources/public/js/router.min.js index ee29c18a..dcc9df57 100644 --- a/Resources/public/js/router.min.js +++ b/Resources/public/js/router.min.js @@ -1 +1 @@ -!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],i=this.getRoute(e),r=n||{},s=t({},r),u="",f=!0,a="",c="undefined"==typeof this.getPortExtension()||null===this.getPortExtension()?"":this.getPortExtension();if(i.tokens.forEach(function(t){if("text"===t[0])return u=t[1]+u,void(f=!1);{if("variable"!==t[0])throw new Error('The token type "'+t[0]+'" is not supported.');var n=i.defaults&&t[3]in i.defaults;if(!1===f||!n||t[3]in r&&r[t[3]]!=i.defaults[t[3]]){var o=void 0;if(t[3]in r)o=r[t[3]],delete s[t[3]];else{if(!n){if(f)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=i.defaults[t[3]]}var a=!0===o||!1===o||""===o;if(!a||!f){var c=encodeURIComponent(o).replace(/%2F/g,"/");"null"===c&&null===o&&(c=""),u=t[1]+c+u}f=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===u&&(u="/"),i.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(a=e[1]+a):void("variable"===e[0]&&(e[3]in r?(t=r[e[3]],delete s[e[3]]):i.defaults&&e[3]in i.defaults&&(t=i.defaults[e[3]]),a=e[1]+t+a))}),u=this.context_.base_url+u,i.requirements&&"_scheme"in i.requirements&&this.getScheme()!=i.requirements._scheme?u=i.requirements._scheme+"://"+(a||this.getHost())+u:"undefined"!=typeof i.schemes&&"undefined"!=typeof i.schemes[0]&&this.getScheme()!==i.schemes[0]?u=i.schemes[0]+"://"+(a||this.getHost())+u:a&&this.getHost()!==a+c?u=this.getScheme()+"://"+a+c+u:o===!0&&(u=this.getScheme()+"://"+this.getHost()+u),Object.keys(s).length>0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file +!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],i=this.getRoute(e),r=n||{},s=t({},r),u="",f=!0,a="",c="undefined"==typeof this.getPortExtension()||null===this.getPortExtension()?"":this.getPortExtension();if(i.tokens.forEach(function(t){if("text"===t[0])return u=t[1]+u,void(f=!1);{if("variable"!==t[0])throw new Error('The token type "'+t[0]+'" is not supported.');var n=i.defaults&&t[3]in i.defaults;if(!1===f||!n||t[3]in r&&r[t[3]]!=i.defaults[t[3]]){var o=void 0;if(t[3]in r)o=r[t[3]],delete s[t[3]];else{if(!n){if(f)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=i.defaults[t[3]]}var a=!0===o||!1===o||""===o;if(!a||!f){var c=encodeURIComponent(o).replace(/%2F/g,"/");"null"===c&&null===o&&(c=""),u=t[1]+c+u}f=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===u&&(u="/"),i.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(a=e[1]+a):void("variable"===e[0]&&(e[3]in r?(t=r[e[3]],delete s[e[3]]):i.defaults&&e[3]in i.defaults&&(t=i.defaults[e[3]]),a=e[1]+t+a))}),u=this.context_.base_url+u,i.requirements&&"_scheme"in i.requirements&&this.getScheme()!=i.requirements._scheme?u=i.requirements._scheme+"://"+(a||this.getHost())+u:"undefined"!=typeof i.schemes&&"undefined"!=typeof i.schemes[0]&&this.getScheme()!==i.schemes[0]?u=i.schemes[0]+"://"+(a||this.getHost())+u:a&&this.getHost()!==a+(""===c?"":":"+c)?u=this.getScheme()+"://"+a+(""===c?"":":"+c)+u:o===!0&&(u=this.getScheme()+"://"+this.getHost()+u),Object.keys(s).length>0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file From 1d1becbc13f5cb41cbf657e6b98dccd554e0db6f Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Wed, 1 Aug 2018 17:21:42 -0400 Subject: [PATCH 11/13] Fixing condition --- Extractor/ExposedRoutesExtractor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index d89c0953..b962a63a 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -104,7 +104,8 @@ public function getHost() { $requestContext = $this->router->getContext(); - $host = $requestContext->getHost() . ('' === $this->getPortExtension() ?: ':' . $this->getPortExtension()); + $host = $requestContext->getHost() . + ('' === $this->getPortExtension() ? $this->getPortExtension() : ':' . $this->getPortExtension()); return $host; } From 18a9219c05b8ff113b0afb2f0f3a2741f9fab86d Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Fri, 3 Aug 2018 15:10:28 -0400 Subject: [PATCH 12/13] Renaming `portExtension` to `port` --- Command/DumpCommand.php | 2 +- Controller/Controller.php | 2 +- Extractor/ExposedRoutesExtractor.php | 4 +-- Extractor/ExposedRoutesExtractorInterface.php | 4 +-- Resources/js/router.js | 22 ++++++++-------- Resources/js/router.test.js | 4 +-- Resources/public/js/router.js | 26 +++++++++---------- Resources/public/js/router.min.js | 2 +- Response/RoutesResponse.php | 22 ++++++++-------- .../Normalizer/RoutesResponseNormalizer.php | 12 ++++----- Tests/Controller/ControllerTest.php | 12 ++++----- .../RoutesResponseNormalizerTest.php | 2 +- 12 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Command/DumpCommand.php b/Command/DumpCommand.php index dddfe305..40fdfd42 100644 --- a/Command/DumpCommand.php +++ b/Command/DumpCommand.php @@ -167,7 +167,7 @@ private function doDump(InputInterface $input, OutputInterface $output) $extractor->getRoutes(), $extractor->getPrefix($input->getOption('locale')), $extractor->getHost(), - $extractor->getPortExtension(), + $extractor->getPort(), $extractor->getScheme() ), 'json', diff --git a/Controller/Controller.php b/Controller/Controller.php index a05144ac..7e4124be 100644 --- a/Controller/Controller.php +++ b/Controller/Controller.php @@ -96,7 +96,7 @@ public function indexAction(Request $request, $_format) $exposedRoutes, $this->exposedRoutesExtractor->getPrefix($request->getLocale()), $this->exposedRoutesExtractor->getHost(), - $this->exposedRoutesExtractor->getPortExtension(), + $this->exposedRoutesExtractor->getPort(), $this->exposedRoutesExtractor->getScheme(), $request->getLocale() ); diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index b962a63a..7e26924f 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -105,7 +105,7 @@ public function getHost() $requestContext = $this->router->getContext(); $host = $requestContext->getHost() . - ('' === $this->getPortExtension() ? $this->getPortExtension() : ':' . $this->getPortExtension()); + ('' === $this->getPort() ? $this->getPort() : ':' . $this->getPort()); return $host; } @@ -113,7 +113,7 @@ public function getHost() /** * {@inheritDoc} */ - public function getPortExtension() + public function getPort() { $requestContext = $this->router->getContext(); diff --git a/Extractor/ExposedRoutesExtractorInterface.php b/Extractor/ExposedRoutesExtractorInterface.php index 562ea655..cb09bf2a 100644 --- a/Extractor/ExposedRoutesExtractorInterface.php +++ b/Extractor/ExposedRoutesExtractorInterface.php @@ -50,11 +50,11 @@ public function getPrefix($locale); public function getHost(); /** - * Get the port extension from RequestContext, only if non standard port (Eg: ":8080") + * Get the port from RequestContext, only if non standard port (Eg: "8080") * * @return string */ - public function getPortExtension(); + public function getPort(); /** * Get the scheme from RequestContext diff --git a/Resources/js/router.js b/Resources/js/router.js index e23e50b8..388b6f0d 100644 --- a/Resources/js/router.js +++ b/Resources/js/router.js @@ -19,7 +19,7 @@ class Router { * @param {Object.=} routes */ constructor(context, routes) { - this.context_ = context || {base_url: '', prefix: '', host: '', portextension: '', scheme: ''}; + this.context_ = context || {base_url: '', prefix: '', host: '', port: '', scheme: ''}; this.setRoutes(routes || {}); } @@ -52,8 +52,8 @@ class Router { if ('prefix' in data) { this.setPrefix(data['prefix']); } - if ('portextension' in data) { - this.setPortExtension(data['portextension']); + if ('port' in data) { + this.setPort(data['port']); } this.setHost(data['host']); @@ -124,17 +124,17 @@ class Router { } /** - * @param {string} portextension + * @param {string} port */ - setPortExtension(portextension) { - this.context_.portextension = portextension; + setPort(port) { + this.context_.port = port; } /** * @return {string} */ - getPortExtension() { - return this.context_.portextension; + getPort() { + return this.context_.port; }; /** @@ -202,7 +202,7 @@ class Router { url = '', optional = true, host = '', - portextension = (typeof this.getPortExtension() == "undefined" || this.getPortExtension() === null) ? '' : this.getPortExtension(); + port = (typeof this.getPort() == "undefined" || this.getPort() === null) ? '' : this.getPort(); route.tokens.forEach((token) => { if ('text' === token[0]) { @@ -281,8 +281,8 @@ class Router { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && this.getHost() !== host + ('' === portextension ? '' : ':' + portextension)) { - url = this.getScheme() + "://" + host + ('' === portextension ? '' : ':' + portextension) + url; + } else if (host && this.getHost() !== host + ('' === port ? '' : ':' + port)) { + url = this.getScheme() + "://" + host + ('' === port ? '' : ':' + port) + url; } else if (absolute === true) { url = this.getScheme() + "://" + this.getHost() + url; } diff --git a/Resources/js/router.test.js b/Resources/js/router.test.js index 1656d40f..f4a25ae2 100644 --- a/Resources/js/router.test.js +++ b/Resources/js/router.test.js @@ -407,8 +407,8 @@ function testGenerateWithNullValue() { assertEquals('/blog-post//10', router.generate('posts', { page: null, id: 10 })); } -function testGenerateWithPortExtension() { - var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http", portextension: 443}, { +function testGenerateWithPort() { + var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http", port: 443}, { homepage: { tokens: [['text', '/bar']], defaults: {subdomain: 'api'}, diff --git a/Resources/public/js/router.js b/Resources/public/js/router.js index d00829ce..5cd2efa5 100644 --- a/Resources/public/js/router.js +++ b/Resources/public/js/router.js @@ -48,7 +48,7 @@ var Router = function () { function Router(context, routes) { _classCallCheck(this, Router); - this.context_ = context || { base_url: '', prefix: '', host: '', portextension: '', scheme: '' }; + this.context_ = context || { base_url: '', prefix: '', host: '', port: '', scheme: '' }; this.setRoutes(routes || {}); } @@ -73,8 +73,8 @@ var Router = function () { if ('prefix' in data) { this.setPrefix(data['prefix']); } - if ('portextension' in data) { - this.setPortExtension(data['portextension']); + if ('port' in data) { + this.setPort(data['port']); } this.setHost(data['host']); @@ -172,13 +172,13 @@ var Router = function () { } /** - * @param {string} portextension + * @param {string} port */ }, { - key: 'setPortExtension', - value: function setPortExtension(portextension) { - this.context_.portextension = portextension; + key: 'setPort', + value: function setPort(port) { + this.context_.port = port; } /** @@ -186,9 +186,9 @@ var Router = function () { */ }, { - key: 'getPortExtension', - value: function getPortExtension() { - return this.context_.portextension; + key: 'getPort', + value: function getPort() { + return this.context_.port; } }, { key: 'buildQueryParams', @@ -269,7 +269,7 @@ var Router = function () { url = '', optional = true, host = '', - portextension = typeof this.getPortExtension() == "undefined" || this.getPortExtension() === null ? '' : this.getPortExtension(); + port = typeof this.getPort() == "undefined" || this.getPort() === null ? '' : this.getPort(); route.tokens.forEach(function (token) { if ('text' === token[0]) { @@ -348,8 +348,8 @@ var Router = function () { url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url; } else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { url = route.schemes[0] + "://" + (host || this.getHost()) + url; - } else if (host && this.getHost() !== host + ('' === portextension ? '' : ':' + portextension)) { - url = this.getScheme() + "://" + host + ('' === portextension ? '' : ':' + portextension) + url; + } else if (host && this.getHost() !== host + ('' === port ? '' : ':' + port)) { + url = this.getScheme() + "://" + host + ('' === port ? '' : ':' + port) + url; } else if (absolute === true) { url = this.getScheme() + "://" + this.getHost() + url; } diff --git a/Resources/public/js/router.min.js b/Resources/public/js/router.min.js index dcc9df57..6b8c4d58 100644 --- a/Resources/public/js/router.min.js +++ b/Resources/public/js/router.min.js @@ -1 +1 @@ -!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],i=this.getRoute(e),r=n||{},s=t({},r),u="",f=!0,a="",c="undefined"==typeof this.getPortExtension()||null===this.getPortExtension()?"":this.getPortExtension();if(i.tokens.forEach(function(t){if("text"===t[0])return u=t[1]+u,void(f=!1);{if("variable"!==t[0])throw new Error('The token type "'+t[0]+'" is not supported.');var n=i.defaults&&t[3]in i.defaults;if(!1===f||!n||t[3]in r&&r[t[3]]!=i.defaults[t[3]]){var o=void 0;if(t[3]in r)o=r[t[3]],delete s[t[3]];else{if(!n){if(f)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=i.defaults[t[3]]}var a=!0===o||!1===o||""===o;if(!a||!f){var c=encodeURIComponent(o).replace(/%2F/g,"/");"null"===c&&null===o&&(c=""),u=t[1]+c+u}f=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===u&&(u="/"),i.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(a=e[1]+a):void("variable"===e[0]&&(e[3]in r?(t=r[e[3]],delete s[e[3]]):i.defaults&&e[3]in i.defaults&&(t=i.defaults[e[3]]),a=e[1]+t+a))}),u=this.context_.base_url+u,i.requirements&&"_scheme"in i.requirements&&this.getScheme()!=i.requirements._scheme?u=i.requirements._scheme+"://"+(a||this.getHost())+u:"undefined"!=typeof i.schemes&&"undefined"!=typeof i.schemes[0]&&this.getScheme()!==i.schemes[0]?u=i.schemes[0]+"://"+(a||this.getHost())+u:a&&this.getHost()!==a+(""===c?"":":"+c)?u=this.getScheme()+"://"+a+(""===c?"":":"+c)+u:o===!0&&(u=this.getScheme()+"://"+this.getHost()+u),Object.keys(s).length>0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return r}},{key:"setData",value:function(e){var t=i.getInstance();t.setRoutingData(e)}}]),i}();i.Route,i.Context;var r=new i;return{Router:i,Routing:r}}); \ No newline at end of file +!function(e,t){var n=t();"function"==typeof define&&define.amd?define([],n.Routing):"object"==typeof module&&module.exports?module.exports=n.Routing:(e.Routing=n.Routing,e.fos={Router:n.Router})}(this,function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=Object.assign||function(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],r=this.getRoute(e),i=n||{},s=t({},i),u="",f=!0,a="",c="undefined"==typeof this.getPort()||null===this.getPort()?"":this.getPort();if(r.tokens.forEach(function(t){if("text"===t[0])return u=t[1]+u,void(f=!1);{if("variable"!==t[0])throw new Error('The token type "'+t[0]+'" is not supported.');var n=r.defaults&&t[3]in r.defaults;if(!1===f||!n||t[3]in i&&i[t[3]]!=r.defaults[t[3]]){var o=void 0;if(t[3]in i)o=i[t[3]],delete s[t[3]];else{if(!n){if(f)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=r.defaults[t[3]]}var a=!0===o||!1===o||""===o;if(!a||!f){var c=encodeURIComponent(o).replace(/%2F/g,"/");"null"===c&&null===o&&(c=""),u=t[1]+c+u}f=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===u&&(u="/"),r.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(a=e[1]+a):void("variable"===e[0]&&(e[3]in i?(t=i[e[3]],delete s[e[3]]):r.defaults&&e[3]in r.defaults&&(t=r.defaults[e[3]]),a=e[1]+t+a))}),u=this.context_.base_url+u,r.requirements&&"_scheme"in r.requirements&&this.getScheme()!=r.requirements._scheme?u=r.requirements._scheme+"://"+(a||this.getHost())+u:"undefined"!=typeof r.schemes&&"undefined"!=typeof r.schemes[0]&&this.getScheme()!==r.schemes[0]?u=r.schemes[0]+"://"+(a||this.getHost())+u:a&&this.getHost()!==a+(""===c?"":":"+c)?u=this.getScheme()+"://"+a+(""===c?"":":"+c)+u:o===!0&&(u=this.getScheme()+"://"+this.getHost()+u),Object.keys(s).length>0){var h=void 0,l=[],y=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,l.push(encodeURIComponent(e)+"="+encodeURIComponent(t))};for(h in s)this.buildQueryParams(h,s[h],y);u=u+"?"+l.join("&").replace(/%20/g,"+")}return u}}],[{key:"getInstance",value:function(){return i}},{key:"setData",value:function(e){var t=r.getInstance();t.setRoutingData(e)}}]),r}();r.Route,r.Context;var i=new r;return{Router:r,Routing:i}}); \ No newline at end of file diff --git a/Response/RoutesResponse.php b/Response/RoutesResponse.php index f2b61c8f..538be722 100644 --- a/Response/RoutesResponse.php +++ b/Response/RoutesResponse.php @@ -19,19 +19,19 @@ class RoutesResponse private $routes; private $prefix; private $host; - private $portextension; + private $port; private $scheme; private $locale; - public function __construct($baseUrl, RouteCollection $routes = null, $prefix = null, $host = null, $portextension = null, $scheme = null, $locale = null) + public function __construct($baseUrl, RouteCollection $routes = null, $prefix = null, $host = null, $port = null, $scheme = null, $locale = null) { - $this->baseUrl = $baseUrl; - $this->routes = $routes ?: new RouteCollection(); - $this->prefix = $prefix; - $this->host = $host; - $this->portextension = $portextension; - $this->scheme = $scheme; - $this->locale = $locale; + $this->baseUrl = $baseUrl; + $this->routes = $routes ?: new RouteCollection(); + $this->prefix = $prefix; + $this->host = $host; + $this->port = $port; + $this->scheme = $scheme; + $this->locale = $locale; } public function getBaseUrl() @@ -76,9 +76,9 @@ public function getHost() return $this->host; } - public function getPortExtension() + public function getPort() { - return $this->portextension; + return $this->port; } public function getScheme() diff --git a/Serializer/Normalizer/RoutesResponseNormalizer.php b/Serializer/Normalizer/RoutesResponseNormalizer.php index 3020bd1e..74281903 100644 --- a/Serializer/Normalizer/RoutesResponseNormalizer.php +++ b/Serializer/Normalizer/RoutesResponseNormalizer.php @@ -25,12 +25,12 @@ class RoutesResponseNormalizer implements NormalizerInterface public function normalize($data, $format = null, array $context = array()) { return array( - 'base_url' => $data->getBaseUrl(), - 'routes' => $data->getRoutes(), - 'prefix' => $data->getPrefix(), - 'host' => $data->getHost(), - 'portextension' => $data->getPortExtension(), - 'scheme' => $data->getScheme(), + 'base_url' => $data->getBaseUrl(), + 'routes' => $data->getRoutes(), + 'prefix' => $data->getPrefix(), + 'host' => $data->getHost(), + 'port' => $data->getPort(), + 'scheme' => $data->getScheme(), ); } diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index 3f7ecb60..10181c4e 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -49,7 +49,7 @@ public function testIndexAction() $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","port":null,"scheme":""}', $response->getContent()); } public function testIndexActionWithLocalizedRoutes() @@ -65,7 +65,7 @@ public function testIndexActionWithLocalizedRoutes() $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","_locale"],["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":{"_locale":"en"},"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog":{"tokens":[["variable","\/","[^\/]++","_locale"],["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":{"_locale":"en"},"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","port":null,"scheme":""}', $response->getContent()); } public function testConfigCache() @@ -79,11 +79,11 @@ public function testConfigCache() ); $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","port":null,"scheme":""}', $response->getContent()); // second call should serve the cached content $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]}},"prefix":"","host":"","port":null,"scheme":""}', $response->getContent()); } /** @@ -95,7 +95,7 @@ public function testGenerateWithCallback($callback) $response = $controller->indexAction($this->getRequest('/', 'GET', array('callback' => $callback)), 'json'); $this->assertEquals( - sprintf('/**/%s({"base_url":"","routes":[],"prefix":"","host":"","portextension":null,"scheme":""});', $callback), + sprintf('/**/%s({"base_url":"","routes":[],"prefix":"","host":"","port":null,"scheme":""});', $callback), $response->getContent() ); } @@ -122,7 +122,7 @@ public function testIndexActionWithoutRoutes() $controller = new Controller($this->getSerializer(), $this->getExtractor(), array(), sys_get_temp_dir()); $response = $controller->indexAction($this->getRequest('/'), 'json'); - $this->assertEquals('{"base_url":"","routes":[],"prefix":"","host":"","portextension":null,"scheme":""}', $response->getContent()); + $this->assertEquals('{"base_url":"","routes":[],"prefix":"","host":"","port":null,"scheme":""}', $response->getContent()); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); diff --git a/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php b/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php index 280d248f..c7b69914 100644 --- a/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php +++ b/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php @@ -60,7 +60,7 @@ public function testNormalize() 'routes' => array(), 'prefix' => 'prefix', 'host' => 'host', - 'portextension' => null, + 'port' => null, 'scheme' => 'scheme', ); From 2ccdbb529233fa2a943a9907b28e249fadf227fd Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Tue, 7 Aug 2018 12:54:30 -0400 Subject: [PATCH 13/13] Remove deprecated PHP `5.3` to `5.6` --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4251d8a1..0db16cb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,7 @@ language: php matrix: include: - - php: 5.3 - env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak - dist: precise + - php: 5.6 - php: 7.1 - php: 7.2 - php: 7.1