@@ -217,7 +217,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
217217 $ methods [] = 'HEAD ' ;
218218 }
219219
220- $ supportsTrailingSlash = $ supportsRedirections && (!$ methods || in_array ('HEAD ' , $ methods ));
220+ $ supportsTrailingSlash = $ supportsRedirections && (!$ methods || in_array ('GET ' , $ methods ));
221221
222222 if (!count ($ compiledRoute ->getPathVariables ()) && false !== preg_match ('#^(.)\^(?P<url>.*?)\$\1# ' , $ compiledRoute ->getRegex (), $ m )) {
223223 if ($ supportsTrailingSlash && '/ ' === substr ($ m ['url ' ], -1 )) {
@@ -258,34 +258,13 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
258258EOF ;
259259
260260 $ gotoname = 'not_ ' .preg_replace ('/[^A-Za-z0-9_]/ ' , '' , $ name );
261- if ($ methods ) {
262- if (1 === count ($ methods )) {
263- $ code .= <<<EOF
264- if ( \$this->context->getMethod() != ' $ methods [0 ]') {
265- \$allow[] = ' $ methods [0 ]';
266- goto $ gotoname;
267- }
268-
269-
270- EOF ;
271- } else {
272- $ methods = implode ("', ' " , $ methods );
273- $ code .= <<<EOF
274- if (!in_array( \$this->context->getMethod(), array(' $ methods'))) {
275- \$allow = array_merge( \$allow, array(' $ methods'));
276- goto $ gotoname;
277- }
278-
279-
280- EOF ;
281- }
282- }
283261
284262 if ($ hasTrailingSlash ) {
285263 $ code .= <<<EOF
286264 if ('/' === substr( \$pathinfo, -1)) {
287265 // no-op
288266 } elseif (!in_array( \$this->context->getMethod(), array('HEAD', 'GET'))) {
267+ \$allow[] = 'GET';
289268 goto $ gotoname;
290269 } else {
291270 return \$this->redirect( \$rawPathinfo.'/', ' $ name');
@@ -303,13 +282,41 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
303282 $ code .= <<<EOF
304283 \$requiredSchemes = $ schemes;
305284 if (!isset( \$requiredSchemes[ \$this->context->getScheme()])) {
285+ if (!in_array( \$this->context->getMethod(), array('HEAD', 'GET'))) {
286+ \$allow[] = 'GET';
287+ goto $ gotoname;
288+ }
289+
306290 return \$this->redirect( \$rawPathinfo, ' $ name', key( \$requiredSchemes));
307291 }
308292
309293
310294EOF ;
311295 }
312296
297+ if ($ methods ) {
298+ if (1 === count ($ methods )) {
299+ $ code .= <<<EOF
300+ if ( \$this->context->getMethod() != ' $ methods [0 ]') {
301+ \$allow[] = ' $ methods [0 ]';
302+ goto $ gotoname;
303+ }
304+
305+
306+ EOF ;
307+ } else {
308+ $ methods = implode ("', ' " , $ methods );
309+ $ code .= <<<EOF
310+ if (!in_array( \$this->context->getMethod(), array(' $ methods'))) {
311+ \$allow = array_merge( \$allow, array(' $ methods'));
312+ goto $ gotoname;
313+ }
314+
315+
316+ EOF ;
317+ }
318+ }
319+
313320 // optimize parameters array
314321 if ($ matches || $ hostMatches ) {
315322 $ vars = array ();
@@ -333,7 +340,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
333340 }
334341 $ code .= " } \n" ;
335342
336- if ($ methods || $ hasTrailingSlash ) {
343+ if ($ hasTrailingSlash || $ schemes || $ methods ) {
337344 $ code .= " $ gotoname: \n" ;
338345 }
339346
0 commit comments