@@ -181,57 +181,56 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
181181 }
182182
183183 $ schemeAuthority = '' ;
184- if ( $ host = $ this ->context ->getHost ()) {
185- $ scheme = $ this ->context ->getScheme ();
184+ $ host = $ this ->context ->getHost ();
185+ $ scheme = $ this ->context ->getScheme ();
186186
187- if ($ requiredSchemes ) {
188- if (!in_array ($ scheme , $ requiredSchemes , true )) {
189- $ referenceType = self ::ABSOLUTE_URL ;
190- $ scheme = current ($ requiredSchemes );
191- }
187+ if ($ requiredSchemes ) {
188+ if (!in_array ($ scheme , $ requiredSchemes , true )) {
189+ $ referenceType = self ::ABSOLUTE_URL ;
190+ $ scheme = current ($ requiredSchemes );
192191 }
192+ }
193193
194- if ($ hostTokens ) {
195- $ routeHost = '' ;
196- foreach ($ hostTokens as $ token ) {
197- if ('variable ' === $ token [0 ]) {
198- if (null !== $ this ->strictRequirements && !preg_match ('#^ ' .$ token [2 ].'$#i ' .(empty ($ token [4 ]) ? '' : 'u ' ), $ mergedParams [$ token [3 ]])) {
199- if ($ this ->strictRequirements ) {
200- throw new InvalidParameterException (strtr ($ message , array ('{parameter} ' => $ token [3 ], '{route} ' => $ name , '{expected} ' => $ token [2 ], '{given} ' => $ mergedParams [$ token [3 ]])));
201- }
202-
203- if ($ this ->logger ) {
204- $ this ->logger ->error ($ message , array ('parameter ' => $ token [3 ], 'route ' => $ name , 'expected ' => $ token [2 ], 'given ' => $ mergedParams [$ token [3 ]]));
205- }
194+ if ($ hostTokens ) {
195+ $ routeHost = '' ;
196+ foreach ($ hostTokens as $ token ) {
197+ if ('variable ' === $ token [0 ]) {
198+ if (null !== $ this ->strictRequirements && !preg_match ('#^ ' .$ token [2 ].'$#i ' .(empty ($ token [4 ]) ? '' : 'u ' ), $ mergedParams [$ token [3 ]])) {
199+ if ($ this ->strictRequirements ) {
200+ throw new InvalidParameterException (strtr ($ message , array ('{parameter} ' => $ token [3 ], '{route} ' => $ name , '{expected} ' => $ token [2 ], '{given} ' => $ mergedParams [$ token [3 ]])));
201+ }
206202
207- return ;
203+ if ($ this ->logger ) {
204+ $ this ->logger ->error ($ message , array ('parameter ' => $ token [3 ], 'route ' => $ name , 'expected ' => $ token [2 ], 'given ' => $ mergedParams [$ token [3 ]]));
208205 }
209206
210- $ routeHost = $ token [1 ].$ mergedParams [$ token [3 ]].$ routeHost ;
211- } else {
212- $ routeHost = $ token [1 ].$ routeHost ;
207+ return ;
213208 }
214- }
215209
216- if ($ routeHost !== $ host ) {
217- $ host = $ routeHost ;
218- if (self ::ABSOLUTE_URL !== $ referenceType ) {
219- $ referenceType = self ::NETWORK_PATH ;
220- }
210+ $ routeHost = $ token [1 ].$ mergedParams [$ token [3 ]].$ routeHost ;
211+ } else {
212+ $ routeHost = $ token [1 ].$ routeHost ;
221213 }
222214 }
223215
224- if (self ::ABSOLUTE_URL === $ referenceType || self ::NETWORK_PATH === $ referenceType ) {
225- $ port = '' ;
226- if ('http ' === $ scheme && 80 != $ this ->context ->getHttpPort ()) {
227- $ port = ': ' .$ this ->context ->getHttpPort ();
228- } elseif ('https ' === $ scheme && 443 != $ this ->context ->getHttpsPort ()) {
229- $ port = ': ' .$ this ->context ->getHttpsPort ();
216+ if ($ routeHost !== $ host ) {
217+ $ host = $ routeHost ;
218+ if (self ::ABSOLUTE_URL !== $ referenceType ) {
219+ $ referenceType = self ::NETWORK_PATH ;
230220 }
221+ }
222+ }
231223
232- $ schemeAuthority = self ::NETWORK_PATH === $ referenceType ? '// ' : "$ scheme:// " ;
233- $ schemeAuthority .= $ host .$ port ;
224+ if ((self ::ABSOLUTE_URL === $ referenceType || self ::NETWORK_PATH === $ referenceType ) && !empty ($ host )) {
225+ $ port = '' ;
226+ if ('http ' === $ scheme && 80 != $ this ->context ->getHttpPort ()) {
227+ $ port = ': ' .$ this ->context ->getHttpPort ();
228+ } elseif ('https ' === $ scheme && 443 != $ this ->context ->getHttpsPort ()) {
229+ $ port = ': ' .$ this ->context ->getHttpsPort ();
234230 }
231+
232+ $ schemeAuthority = self ::NETWORK_PATH === $ referenceType ? '// ' : "$ scheme:// " ;
233+ $ schemeAuthority .= $ host .$ port ;
235234 }
236235
237236 if (self ::RELATIVE_PATH === $ referenceType ) {
0 commit comments