Selaa lähdekoodia

[Routing] removed unneeded code in the dumper Apache rules

Fabien Potencier 14 vuotta sitten
vanhempi
commit
9eae7e54ca

+ 4 - 3
src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php

@@ -72,8 +72,8 @@ class ApacheMatcherDumper extends MatcherDumper
             if ($req = strtolower($route->getRequirement('_method'))) {
                 $allow = array();
                 foreach (explode('|', $req) as $method) {
-                    $methodVars[] = $var = '_ROUTING__allow_'.$method;
-                    $allow[] = 'E='.$var.':1';
+                    $methodVars[] = $method;
+                    $allow[] = 'E=_ROUTING__allow_'.$method.':1';
                 }
 
                 $rule[] = "RewriteCond %{REQUEST_URI} $regex";
@@ -96,8 +96,9 @@ class ApacheMatcherDumper extends MatcherDumper
 
         if (0 < count($methodVars)) {
             $rule = array('# 405 Method Not Allowed');
+            $methodVars = array_values(array_unique($methodVars));
             foreach ($methodVars as $i => $methodVar) {
-                $rule[] = sprintf('RewriteCond %%{%s} !-z%s', $methodVar, isset($methodVars[$i + 1]) ? ' [OR]' : '');
+                $rule[] = sprintf('RewriteCond %%{_ROUTING__allow_%s} !-z%s', $methodVar, isset($methodVars[$i + 1]) ? ' [OR]' : '');
             }
             $rule[] = sprintf('RewriteRule .* %s [QSA,L]', $options['script_name']);
 

+ 7 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.apache

@@ -13,6 +13,13 @@ RewriteRule .* - [S=1,E=_ROUTING__allow_get:1,E=_ROUTING__allow_head:1]
 RewriteCond %{REQUEST_URI} ^/bar/([^/]+?)$
 RewriteRule .* app.php [QSA,L,E=_ROUTING__route:bar,E=_ROUTING_foo:%1]
 
+# baragain
+RewriteCond %{REQUEST_URI} ^/baragain/([^/]+?)$
+RewriteCond %{REQUEST_METHOD} !^(get|post)$ [NC]
+RewriteRule .* - [S=1,E=_ROUTING__allow_get:1,E=_ROUTING__allow_post:1]
+RewriteCond %{REQUEST_URI} ^/baragain/([^/]+?)$
+RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baragain,E=_ROUTING_foo:%1]
+
 # baz
 RewriteCond %{REQUEST_URI} ^/test/baz$
 RewriteRule .* app.php [QSA,L,E=_ROUTING__route:baz]

+ 6 - 0
tests/Symfony/Tests/Component/Routing/Matcher/Dumper/ApacheMatcherDumperTest.php

@@ -40,6 +40,12 @@ class ApacheMatcherDumperTest extends \PHPUnit_Framework_TestCase
             array(),
             array('_method' => 'GET|head')
         ));
+        // method requirement (again)
+        $collection->add('baragain', new Route(
+            '/baragain/{foo}',
+            array(),
+            array('_method' => 'get|post')
+        ));
         // simple
         $collection->add('baz', new Route(
             '/test/baz'