1(function (root, factory) { 2 var routing = factory(); 3 if (typeof define === 'function' && define.amd) { 4 // AMD. Register as an anonymous module. 5 define([], routing.Routing); 6 } else if (typeof module === 'object' && module.exports) { 7 // Node. Does not work with strict CommonJS, but 8 // only CommonJS-like environments that support module.exports, 9 // like Node. 10 module.exports = routing.Routing; 11 } else { 12 // Browser globals (root is window) 13 root.Routing = routing.Routing; 14 root.fos = { 15 Router: routing.Router 16 }; 17 } 18}(this, function () { 19 var exports = {}; 20 "use strict"; 21exports.__esModule = true; 22exports.Routing = exports.Router = void 0; 23var Router = /** @class */ (function () { 24 function Router(context, routes) { 25 this.context_ = context || { base_url: '', prefix: '', host: '', port: '', scheme: '', locale: '' }; 26 this.setRoutes(routes || {}); 27 } 28 Router.getInstance = function () { 29 return exports.Routing; 30 }; 31 Router.setData = function (data) { 32 var router = Router.getInstance(); 33 router.setRoutingData(data); 34 }; 35 Router.prototype.setRoutingData = function (data) { 36 this.setBaseUrl(data['base_url']); 37 this.setRoutes(data['routes']); 38 if (typeof data.prefix !== 'undefined') { 39 this.setPrefix(data['prefix']); 40 } 41 if (typeof data.port !== 'undefined') { 42 this.setPort(data['port']); 43 } 44 if (typeof data.locale !== 'undefined') { 45 this.setLocale(data['locale']); 46 } 47 this.setHost(data['host']); 48 if (typeof data.scheme !== 'undefined') { 49 this.setScheme(data['scheme']); 50 } 51 }; 52 Router.prototype.setRoutes = function (routes) { 53 this.routes_ = Object.freeze(routes); 54 }; 55 Router.prototype.getRoutes = function () { 56 return this.routes_; 57 }; 58 Router.prototype.setBaseUrl = function (baseUrl) { 59 this.context_.base_url = baseUrl; 60 }; 61 Router.prototype.getBaseUrl = function () { 62 return this.context_.base_url; 63 }; 64 Router.prototype.setPrefix = function (prefix) { 65 this.context_.prefix = prefix; 66 }; 67 Router.prototype.setScheme = function (scheme) { 68 this.context_.scheme = scheme; 69 }; 70 Router.prototype.getScheme = function () { 71 return this.context_.scheme; 72 }; 73 Router.prototype.setHost = function (host) { 74 this.context_.host = host; 75 }; 76 Router.prototype.getHost = function () { 77 return this.context_.host; 78 }; 79 Router.prototype.setPort = function (port) { 80 this.context_.port = port; 81 }; 82 Router.prototype.getPort = function () { 83 return this.context_.port; 84 }; 85 ; 86 Router.prototype.setLocale = function (locale) { 87 this.context_.locale = locale; 88 }; 89 Router.prototype.getLocale = function () { 90 return this.context_.locale; 91 }; 92 ; 93 /** 94 * Builds query string params added to a URL. 95 * Port of jQuery's $.param() function, so credit is due there. 96 */ 97 Router.prototype.buildQueryParams = function (prefix, params, add) { 98 var _this = this; 99 var name; 100 var rbracket = new RegExp(/\[\]$/); 101 if (params instanceof Array) { 102 params.forEach(function (val, i) { 103 if (rbracket.test(prefix)) { 104 add(prefix, val); 105 } 106 else { 107 _this.buildQueryParams(prefix + '[' + (typeof val === 'object' ? i : '') + ']', val, add); 108 } 109 }); 110 } 111 else if (typeof params === 'object') { 112 for (name in params) { 113 this.buildQueryParams(prefix + '[' + name + ']', params[name], add); 114 } 115 } 116 else { 117 add(prefix, params); 118 } 119 }; 120 /** 121 * Returns a raw route object. 122 */ 123 Router.prototype.getRoute = function (name) { 124 var prefixedName = this.context_.prefix + name; 125 var sf41i18nName = name + '.' + this.context_.locale; 126 var prefixedSf41i18nName = this.context_.prefix + name + '.' + this.context_.locale; 127 var variants = [prefixedName, sf41i18nName, prefixedSf41i18nName, name]; 128 for (var i in variants) { 129 if (variants[i] in this.routes_) { 130 return this.routes_[variants[i]]; 131 } 132 } 133 throw new Error('The route "' + name + '" does not exist.'); 134 }; 135 /** 136 * Generates the URL for a route. 137 */ 138 Router.prototype.generate = function (name, opt_params, absolute) { 139 var route = (this.getRoute(name)); 140 var params = opt_params || {}; 141 var unusedParams = Object.assign({}, params); 142 var url = ''; 143 var optional = true; 144 var host = ''; 145 var port = (typeof this.getPort() == 'undefined' || this.getPort() === null) ? '' : this.getPort(); 146 route.tokens.forEach(function (token) { 147 if ('text' === token[0] && typeof token[1] === 'string') { 148 url = Router.encodePathComponent(token[1]) + url; 149 optional = false;
150 return; 151 } 152 if ('variable' === token[0]) { 153 if (token.length === 6 && token[5] === true) { // Sixth part of the token array indicates if it should be included in case of defaults 154 optional = false; 155 } 156 var hasDefault = route.defaults && !Array.isArray(route.defaults) && typeof token[3] === 'string' && (token[3] in route.defaults); 157 if (false === optional || !hasDefault || ((typeof token[3] === 'string' && token[3] in params) && !Array.isArray(route.defaults) && params[token[3]] != route.defaults[token[3]])) { 158 var value = void 0; 159 if (typeof token[3] === 'string' && token[3] in params) { 160 value = params[token[3]]; 161 delete unusedParams[token[3]]; 162 } 163 else if (typeof token[3] === 'string' && hasDefault && !Array.isArray(route.defaults)) { 164 value = route.defaults[token[3]]; 165 } 166 else if (optional) { 167 return; 168 } 169 else { 170 throw new Error('The route "' + name + '" requires the parameter "' + token[3] + '".'); 171 } 172 var empty = true === value || false === value || '' === value; 173 if (!empty || !optional) { 174 var encodedValue = Router.encodePathComponent(value); 175 if ('null' === encodedValue && null === value) { 176 encodedValue = ''; 177 } 178 url = token[1] + encodedValue + url; 179 } 180 optional = false;
181 } 182 else if (hasDefault && (typeof token[3] === 'string' && token[3] in unusedParams)) { 183 delete unusedParams[token[3]]; 184 } 185 return; 186 } 187 throw new Error('The token type "' + token[0] + '" is not supported.'); 188 }); 189 if (url === '') { 190 url = '/'; 191 } 192 route.hosttokens.forEach(function (token) { 193 var value; 194 if ('text' === token[0]) { 195 host = token[1] + host; 196 return; 197 } 198 if ('variable' === token[0]) { 199 if (token[3] in params) { 200 value = params[token[3]]; 201 delete unusedParams[token[3]]; 202 } 203 else if (route.defaults && !Array.isArray(route.defaults) && (token[3] in route.defaults)) { 204 value = route.defaults[token[3]]; 205 } 206 host = token[1] + value + host; 207 } 208 }); 209 url = this.context_.base_url + url; 210 if (route.requirements && ('_scheme' in route.requirements) && this.get
210Scheme() != route.requirements['_scheme']) { 211 var currentHost = host || this.getHost(); 212 url = route.requirements['_scheme'] + '://' + currentHost + (currentHost.indexOf(':' + port) > -1 || '' === port ? '' : ':' + port) + url; 213 } 214 else if ('undefined' !== typeof route.schemes && 'undefined' !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) { 215 var currentHost = host || this.getHost(); 216 url = route.schemes[0] + '://' + currentHost + (currentHost.indexOf(':' + port) > -1 || '' === port ? '' : ':' + port) + url; 217 } 218 else if (host && this.getHost() !== host + (host.indexOf(':' + port) > -1 || '' === port ? '' : ':' + port)) { 219 url = this.getScheme() + '://' + host + (host.indexOf(':' + port) > -1 || '' === port ? '' : ':' + port) + url; 220 } 221 else if (absolute === true) { 222 url = this.getScheme() + '://' + this.getHost() + (this.getHost().indexOf(':' + port) > -1 || '' === port ? '' : ':' + port) + url; 223 } 224 if (Object.keys(unusedParams).length > 0) { 225 var queryParams_1 = []; 226 var add = function (key, value) { 227 // if value is a function then call it and assign it's return value as value 228 value = (typeof value === 'function') ? value() : value; 229 // change null to empty string 230 value = (value === null) ? '' : value; 231 queryParams_1.push(Router.encodeQueryComponent(key) + '=' + Router.encodeQueryComponent(value)); 232 }; 233 for (var prefix in unusedParams) { 234 if (unusedParams.hasOwnProperty(prefix)) { 235 this.buildQueryParams(prefix, unusedParams[prefix], add); 236 } 237 } 238 url = url + '?' + queryParams_1.join('&'); 239 } 240 return url; 241 }; 242 /** 243 * Returns the given string encoded to mimic Symfony URL generator. 244 */ 245 Router.customEncodeURIComponent = function (value) { 246 return encodeURIComponent(value) 247 .replace(/%2F/g, '/') 248 .replace(/%40/g, '@') 249 .replace(/%3A/g, ':') 250 .replace(/%21/g, '!') 251 .replace(/%3B/g, ';') 252 .replace(/%2C/g, ',') 253 .replace(/%2A/g, '*') 254 .replace(/\(/g, '%28') 255 .replace(/\)/g, '%29') 256 .replace(/'/g, '%27'); 257 }; 258 /** 259 * Returns the given path properly encoded to mimic Symfony URL generator. 260 */ 261 Router.encodePathComponent = function (value) { 262 return Router.customEncodeURIComponent(value) 263 .replace(/%3D/g, '=') 264 .replace(/%2B/g, '+') 265 .replace(/%21/g, '!') 266 .replace(/%7C/g, '|'); 267 }; 268 /** 269 * Returns the given query parameter or value properly encoded to mimic Symfony URL generator. 270 */ 271 Router.encodeQueryComponent = function (value) { 272 return Router.customEncodeURIComponent(value) 273 .replace(/%3F/g, '?'); 274 }; 275 return Router; 276}()); 277exports.Router = Router; 278exports.Routing = new Router(); 279exports["default"] = exports.Routing; 280 281 282 return { Router: exports.Router, Routing: exports.Routing }; 283}));�
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.