!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),u=n||{},s=t({},u),c="",a=!0,l="",f="undefined"==typeof this.getPort()||null===this.getPort()?"":this.getPort();if(i.tokens.forEach(function(t){if("text"===t[0])return c=r.encodePathComponent(t[1])+c,void(a=!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===a||!n||t[3]in u&&u[t[3]]!=i.defaults[t[3]]){var o=void 0;if(t[3]in u)o=u[t[3]],delete s[t[3]];else{if(!n){if(a)return;throw new Error('The route "'+e+'" requires the parameter "'+t[3]+'".')}o=i.defaults[t[3]]}var l=!0===o||!1===o||""===o;if(!l||!a){var f=r.encodePathComponent(o);"null"===f&&null===o&&(f=""),c=t[1]+f+c}a=!1}else n&&t[3]in s&&delete s[t[3]]}}),""===c&&(c="/"),i.hosttokens.forEach(function(e){var t=void 0;return"text"===e[0]?void(l=e[1]+l):void("variable"===e[0]&&(e[3]in u?(t=u[e[3]],delete s[e[3]]):i.defaults&&e[3]in i.defaults&&(t=i.defaults[e[3]]),l=e[1]+t+l))}),c=this.context_.base_url+c,i.requirements&&"_scheme"in i.requirements&&this.getScheme()!=i.requirements._scheme){var h=l||this.getHost();c=i.requirements._scheme+"://"+h+(h.indexOf(":"+f)>-1||""===f?"":":"+f)+c}else if("undefined"!=typeof i.schemes&&"undefined"!=typeof i.schemes[0]&&this.getScheme()!==i.schemes[0]){var p=l||this.getHost();c=i.schemes[0]+"://"+p+(p.indexOf(":"+f)>-1||""===f?"":":"+f)+c}else l&&this.getHost()!==l+(l.indexOf(":"+f)>-1||""===f?"":":"+f)?c=this.getScheme()+"://"+l+(l.indexOf(":"+f)>-1||""===f?"":":"+f)+c:o===!0&&(c=this.getScheme()+"://"+this.getHost()+(this.getHost().indexOf(":"+f)>-1||""===f?"":":"+f)+c);if(Object.keys(s).length>0){var d=void 0,y=[],v=function(e,t){t="function"==typeof t?t():t,t=null===t?"":t,y.push(r.encodeQueryComponent(e)+"="+r.encodeQueryComponent(t))};for(d in s)this.buildQueryParams(d,s[d],v);c=c+"?"+y.join("&")}return c}}],[{key:"getInstance",value:function(){return i}},{key:"setData",value:function(e){var t=r.getInstance();t.setRoutingData(e)}},{key:"customEncodeURIComponent",value:function(e){return encodeURIComponent(e).replace(/%2F/g,"/").replace(/%40/g,"@").replace(/%3A/g,":").replace(/%21/g,"!").replace(/%3B/g,";").replace(/%2C/g,",").replace(/%2A/g,"*").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/'/g,"%27")}},{key:"encodePathComponent",value:function(e){return r.customEncodeURIComponent(e).replace(/%3D/g,"=").replace(/%2B/g,"+").replace(/%21/g,"!").replace(/%7C/g,"|")}},{key:"encodeQueryComponent",value:function(e){return r.customEncodeURIComponent(e).replace(/%3F/g,"?")}}]),r}();r.Route,r.Context;var i=new r;return{Router:r,Routing:i}});