Просмотр исходного кода

ZF-7367: add support for returnResponse flag to Frontcontroller resource and Bootstrap

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20885 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 лет назад
Родитель
Сommit
6ef1aeed4e

+ 9 - 0
documentation/manual/en/module_specs/Zend_Application-AvailableResources-Frontcontroller.xml

@@ -90,6 +90,14 @@
                 register with the front controller.
             </para>
         </listitem>
+
+        <listitem>
+            <para>
+                <emphasis><property>returnresponse</property></emphasis>: whether or not to return
+                the response object after dispatching the front controller. Value should be a
+                boolean; by default, this is disabled.
+            </para>
+        </listitem>
     </itemizedlist>
 
     <para>
@@ -118,6 +126,7 @@ resources.frontController.plugins.foo = "My_Plugin_Foo"
 resources.frontController.plugins.bar = "My_Plugin_Bar"
 resources.frontController.plugins.baz.class = "My_Plugin_Baz"
 resources.frontController.plugins.baz.stackIndex = 123
+resources.frontController.returnresponse = 1
 resources.frontController.env = APPLICATION_ENV
 ]]></programlisting>
     </example>

+ 5 - 2
library/Zend/Application/Bootstrap/Bootstrap.php

@@ -80,7 +80,7 @@ class Zend_Application_Bootstrap_Bootstrap
      * If so, it registers the bootstrap with the 'bootstrap' parameter of
      * the front controller, and dispatches the front controller.
      *
-     * @return void
+     * @return mixed
      * @throws Zend_Application_Bootstrap_Exception
      */
     public function run()
@@ -94,7 +94,10 @@ class Zend_Application_Bootstrap_Bootstrap
         }
 
         $front->setParam('bootstrap', $this);
-        $front->dispatch();
+        $response = $front->dispatch();
+        if ($front->returnResponse()) {
+            return $response;
+        }
     }
 
     /**

+ 4 - 0
library/Zend/Application/Resource/Frontcontroller.php

@@ -113,6 +113,10 @@ class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resourc
                     }
                     break;
 
+                case 'returnresponse':
+                    $front->returnResponse((bool) $value);
+                    break;
+
                 case 'throwexceptions':
                     $front->throwExceptions((bool) $value);
                     break;

+ 23 - 0
tests/Zend/Application/Bootstrap/BootstrapTest.php

@@ -167,6 +167,29 @@ class Zend_Application_Bootstrap_BootstrapTest extends PHPUnit_Framework_TestCas
         $al = $bootstrap->getResourceLoader();
         $this->assertEquals('Default', $al->getNamespace());
     }
+
+    /**
+     * @group ZF-7367
+     */
+    public function testBootstrapRunMethodShouldReturnResponseIfFlagEnabled()
+    {
+        $this->bootstrap->setOptions(array(
+            'resources' => array(
+                'frontcontroller' => array(
+                    'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
+                    'returnresponse'  => true,
+                ),
+            ),
+        ));
+        $this->bootstrap->bootstrap();
+
+        $front   = $this->bootstrap->getResource('FrontController');
+        $request = $front->getRequest();
+        $request->setRequestUri('/zfappbootstrap');
+
+        $result = $this->bootstrap->run();
+        $this->assertTrue($result instanceof Zend_Controller_Response_Abstract);
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Bootstrap_BootstrapTest::main') {

+ 14 - 0
tests/Zend/Application/Resource/FrontcontrollerTest.php

@@ -334,6 +334,20 @@ class Zend_Application_Resource_FrontcontrollerTest extends PHPUnit_Framework_Te
         	$this->assertEquals($class, get_class($plugins[$index]));
         }
     }
+
+    /**
+     * @group ZF-7367
+     */
+    public function testPassingReturnResponseFlagShouldAlterFrontControllerStatus()
+    {
+        require_once 'Zend/Application/Resource/Frontcontroller.php';
+        $resource = new Zend_Application_Resource_Frontcontroller(array(
+            'returnresponse' => true,
+        ));
+        $resource->init();
+        $front = $resource->getFrontController();
+        $this->assertTrue($front->returnResponse());
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_FrontcontrollerTest::main') {