Forráskód Böngészése

ZF-5107: getParams() should honor paramSources setting

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18268 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 éve
szülő
commit
12716c04fa

+ 12 - 5
library/Zend/Controller/Request/Http.php

@@ -726,12 +726,19 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
      */
     public function getParams()
     {
-        $return = $this->_params;
-        if (isset($_GET) && is_array($_GET)) {
-            $return += $_GET;
+        $return       = $this->_params;
+        $paramSources = $this->getParamSources();
+        if (in_array('_GET', $paramSources) 
+            && isset($_GET) 
+            && is_array($_GET)
+        ) { 
+            $return += $_GET; 
         }
-        if (isset($_POST) && is_array($_POST)) {
-            $return += $_POST;
+        if (in_array('_POST', $paramSources) 
+            && isset($_POST) 
+            && is_array($_POST)
+        ) { 
+            $return += $_POST; 
         }
         return $return;
     }

+ 12 - 0
tests/Zend/Controller/Request/HttpTest.php

@@ -792,6 +792,18 @@ class Zend_Controller_Request_HttpTest extends PHPUnit_Framework_TestCase
         $this->assertSame($first, $request->getRawBody());
         stream_wrapper_restore('php');
     }
+
+    /**
+     * @group ZF-5107
+     */
+    public function testGetParamsShouldHonorParamSourcesSetting()
+    {
+        $_GET  = array('foo' => 'bar');
+        $_POST = array('foo' => 'baz');
+        $this->_request->setParamSources(array('_POST'));
+        $params = $this->_request->getParams();
+        $this->assertEquals(array('foo' => 'baz'), $params);
+    }
 }
 
 // Call Zend_Controller_Request_HttpTest::main() if this source file is executed directly.