@@ -264,7 +264,6 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
264264 if ('/' === substr( \$pathinfo, -1)) {
265265 // no-op
266266 } elseif (!in_array( \$this->context->getMethod(), array('HEAD', 'GET'))) {
267- \$allow[] = 'GET';
268267 goto $ gotoname;
269268 } else {
270269 return \$this->redirect( \$rawPathinfo.'/', ' $ name');
@@ -279,11 +278,19 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
279278 throw new \LogicException ('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface. ' );
280279 }
281280 $ schemes = str_replace ("\n" , '' , var_export (array_flip ($ schemes ), true ));
282- $ code .= <<<EOF
281+ if ($ methods ) {
282+ $ methods = implode ("', ' " , $ methods );
283+ $ code .= <<<EOF
283284 \$requiredSchemes = $ schemes;
284- if (!isset( \$requiredSchemes[ \$this->context->getScheme()])) {
285+ \$hasRequiredScheme = isset( \$requiredSchemes[ \$this->context->getScheme()]);
286+ if (!in_array( \$this->context->getMethod(), array(' $ methods'))) {
287+ if ( \$hasRequiredScheme) {
288+ \$allow = array_merge( \$allow, array(' $ methods'));
289+ }
290+ goto $ gotoname;
291+ }
292+ if (! \$hasRequiredScheme) {
285293 if (!in_array( \$this->context->getMethod(), array('HEAD', 'GET'))) {
286- \$allow[] = 'GET';
287294 goto $ gotoname;
288295 }
289296
@@ -292,9 +299,21 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
292299
293300
294301EOF ;
295- }
302+ } else {
303+ $ code .= <<<EOF
304+ \$requiredSchemes = $ schemes;
305+ if (!isset( \$requiredSchemes[ \$this->context->getScheme()])) {
306+ if (!in_array( \$this->context->getMethod(), array('HEAD', 'GET'))) {
307+ goto $ gotoname;
308+ }
296309
297- if ($ methods ) {
310+ return \$this->redirect( \$rawPathinfo, ' $ name', key( \$requiredSchemes));
311+ }
312+
313+
314+ EOF ;
315+ }
316+ } elseif ($ methods ) {
298317 if (1 === count ($ methods )) {
299318 $ code .= <<<EOF
300319 if ( \$this->context->getMethod() != ' $ methods [0 ]') {
0 commit comments