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

ZF-5805: make protected methods public

- Deprecates all _*() helper methods, and has them proxy to their public
  counterparts

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24588 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 14 лет назад
Родитель
Сommit
e094b6908e
2 измененных файлов с 108 добавлено и 33 удалено
  1. 106 0
      library/Zend/Controller/Action.php
  2. 2 33
      tests/Zend/Controller/ActionTest.php

+ 106 - 0
library/Zend/Controller/Action.php

@@ -583,6 +583,22 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac
      */
     protected function _getParam($paramName, $default = null)
     {
+        return $this->getParam($paramName, $default);
+    }
+
+    /**
+     * Gets a parameter from the {@link $_request Request object}.  If the
+     * parameter does not exist, NULL will be returned.
+     *
+     * If the parameter does not exist and $default is set, then
+     * $default will be returned instead of NULL.
+     *
+     * @param string $paramName
+     * @param mixed $default
+     * @return mixed
+     */
+    public function getParam($paramName, $default = null)
+    {
         $value = $this->getRequest()->getParam($paramName);
          if ((null === $value || '' === $value) && (null !== $default)) {
             $value = $default;
@@ -597,9 +613,23 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac
      * @param string $paramName
      * @param mixed $value
      * @return Zend_Controller_Action
+     * @deprecated Deprecated as of Zend Framework 1.7. Use
+     *             setParam() instead.
      */
     protected function _setParam($paramName, $value)
     {
+        return $this->setParam($paramName, $value);
+    }
+
+    /**
+     * Set a parameter in the {@link $_request Request object}.
+     *
+     * @param string $paramName
+     * @param mixed $value
+     * @return Zend_Controller_Action
+     */
+    public function setParam($paramName, $value)
+    {
         $this->getRequest()->setParam($paramName, $value);
 
         return $this;
@@ -611,9 +641,23 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac
      *
      * @param string $paramName
      * @return boolean
+     * @deprecated Deprecated as of Zend Framework 1.7. Use
+     *             hasParam() instead.
      */
     protected function _hasParam($paramName)
     {
+        return $this->hasParam($paramName);
+    }
+
+    /**
+     * Determine whether a given parameter exists in the
+     * {@link $_request Request object}.
+     *
+     * @param string $paramName
+     * @return boolean
+     */
+    public function hasParam($paramName)
+    {
         return null !== $this->getRequest()->getParam($paramName);
     }
 
@@ -622,9 +666,22 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac
      * as an associative array.
      *
      * @return array
+     * @deprecated Deprecated as of Zend Framework 1.7. Use
+     *             getAllParams() instead.
      */
     protected function _getAllParams()
     {
+        return $this->getAllParams();
+    }
+
+    /**
+     * Return all parameters in the {@link $_request Request object}
+     * as an associative array.
+     *
+     * @return array
+     */
+    public function getAllParams()
+    {
         return $this->getRequest()->getParams();
     }
 
@@ -654,9 +711,42 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac
      * @param string $module
      * @param array $params
      * @return void
+     * @deprecated Deprecated as of Zend Framework 1.7. Use
+     *             forward() instead.
      */
     final protected function _forward($action, $controller = null, $module = null, array $params = null)
     {
+        $this->forward($action, $controller, $module, $params);
+    }
+
+    /**
+     * Forward to another controller/action.
+     *
+     * It is important to supply the unformatted names, i.e. "article"
+     * rather than "ArticleController".  The dispatcher will do the
+     * appropriate formatting when the request is received.
+     *
+     * If only an action name is provided, forwards to that action in this
+     * controller.
+     *
+     * If an action and controller are specified, forwards to that action and
+     * controller in this module.
+     *
+     * Specifying an action, controller, and module is the most specific way to
+     * forward.
+     *
+     * A fourth argument, $params, will be used to set the request parameters.
+     * If either the controller or module are unnecessary for forwarding,
+     * simply pass null values for them before specifying the parameters.
+     *
+     * @param string $action
+     * @param string $controller
+     * @param string $module
+     * @param array $params
+     * @return void
+     */
+    final public function forward($action, $controller = null, $module = null, array $params = null)
+    {
         $request = $this->getRequest();
 
         if (null !== $params) {
@@ -684,9 +774,25 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac
      * @param string $url
      * @param array $options Options to be used when redirecting
      * @return void
+     * @deprecated Deprecated as of Zend Framework 1.7. Use
+     *             redirect() instead.
      */
     protected function _redirect($url, array $options = array())
     {
+        $this->redirect($url, $options);
+    }
+
+    /**
+     * Redirect to another URL
+     *
+     * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
+     *
+     * @param string $url
+     * @param array $options Options to be used when redirecting
+     * @return void
+     */
+    public function redirect($url, array $options = array())
+    {
         $this->_helper->redirector->gotoUrl($url, $options);
     }
 }

+ 2 - 33
tests/Zend/Controller/ActionTest.php

@@ -223,7 +223,7 @@ class Zend_Controller_ActionTest extends PHPUnit_Framework_TestCase
     public function testSetParam()
     {
         $this->_controller->setParam('foo', 'bar');
-        $params = $this->_controller->getParams();
+        $params = $this->_controller->getAllParams();
         $this->assertTrue(isset($params['foo']));
         $this->assertEquals('bar', $params['foo']);
     }
@@ -257,7 +257,7 @@ class Zend_Controller_ActionTest extends PHPUnit_Framework_TestCase
         $this->_controller->setParam('bar', 'baz');
         $this->_controller->setParam('boo', 'bah');
 
-        $params = $this->_controller->getParams();
+        $params = $this->_controller->getAllParams();
         $this->assertEquals('bar', $params['foo']);
         $this->assertEquals('baz', $params['bar']);
         $this->assertEquals('bah', $params['boo']);
@@ -545,37 +545,6 @@ class Zend_Controller_ActionTest_TestController extends Zend_Controller_Action
     {
         $this->getResponse()->setBody("Should never see this\n");
     }
-
-    public function forward($action, $controller = null, $module = null, array $params = null)
-    {
-        $this->_forward($action, $controller, $module, $params);
-    }
-
-    public function hasParam($param)
-    {
-        return $this->_hasParam($param);
-    }
-
-    public function getParams()
-    {
-        return $this->_getAllParams();
-    }
-
-    public function setParam($key, $value)
-    {
-        $this->_setParam($key, $value);
-        return $this;
-    }
-
-    public function getParam($key, $default)
-    {
-        return $this->_getParam($key, $default);
-    }
-
-    public function redirect($url, $code = 302, $prependBase = true)
-    {
-        $this->_redirect($url, array('code' => $code, 'prependBase' => $prependBase));
-    }
 }
 
 // Call Zend_Controller_ActionTest::main() if this source file is executed directly.