File indexing completed on 2024-06-16 05:29:56

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Controller
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @category   Zend
0024  * @package    Zend_Controller
0025  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0026  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0027  */
0028 abstract class Zend_Controller_Request_Abstract
0029 {
0030     /**
0031      * Has the action been dispatched?
0032      * @var boolean
0033      */
0034     protected $_dispatched = false;
0035 
0036     /**
0037      * Module
0038      * @var string
0039      */
0040     protected $_module;
0041 
0042     /**
0043      * Module key for retrieving module from params
0044      * @var string
0045      */
0046     protected $_moduleKey = 'module';
0047 
0048     /**
0049      * Controller
0050      * @var string
0051      */
0052     protected $_controller;
0053 
0054     /**
0055      * Controller key for retrieving controller from params
0056      * @var string
0057      */
0058     protected $_controllerKey = 'controller';
0059 
0060     /**
0061      * Action
0062      * @var string
0063      */
0064     protected $_action;
0065 
0066     /**
0067      * Action key for retrieving action from params
0068      * @var string
0069      */
0070     protected $_actionKey = 'action';
0071 
0072     /**
0073      * Request parameters
0074      * @var array
0075      */
0076     protected $_params = array();
0077 
0078     /**
0079      * Retrieve the module name
0080      *
0081      * @return string
0082      */
0083     public function getModuleName()
0084     {
0085         if (null === $this->_module) {
0086             $this->_module = $this->getParam($this->getModuleKey());
0087         }
0088 
0089         return $this->_module;
0090     }
0091 
0092     /**
0093      * Set the module name to use
0094      *
0095      * @param string $value
0096      * @return Zend_Controller_Request_Abstract
0097      */
0098     public function setModuleName($value)
0099     {
0100         $this->_module = $value;
0101         return $this;
0102     }
0103 
0104     /**
0105      * Retrieve the controller name
0106      *
0107      * @return string
0108      */
0109     public function getControllerName()
0110     {
0111         if (null === $this->_controller) {
0112             $this->_controller = $this->getParam($this->getControllerKey());
0113         }
0114 
0115         return $this->_controller;
0116     }
0117 
0118     /**
0119      * Set the controller name to use
0120      *
0121      * @param string $value
0122      * @return Zend_Controller_Request_Abstract
0123      */
0124     public function setControllerName($value)
0125     {
0126         $this->_controller = $value;
0127         return $this;
0128     }
0129 
0130     /**
0131      * Retrieve the action name
0132      *
0133      * @return string
0134      */
0135     public function getActionName()
0136     {
0137         if (null === $this->_action) {
0138             $this->_action = $this->getParam($this->getActionKey());
0139         }
0140 
0141         return $this->_action;
0142     }
0143 
0144     /**
0145      * Set the action name
0146      *
0147      * @param string $value
0148      * @return Zend_Controller_Request_Abstract
0149      */
0150     public function setActionName($value)
0151     {
0152         $this->_action = $value;
0153         /**
0154          * @see ZF-3465
0155          */
0156         if (null === $value) {
0157             $this->setParam($this->getActionKey(), $value);
0158         }
0159         return $this;
0160     }
0161 
0162     /**
0163      * Retrieve the module key
0164      *
0165      * @return string
0166      */
0167     public function getModuleKey()
0168     {
0169         return $this->_moduleKey;
0170     }
0171 
0172     /**
0173      * Set the module key
0174      *
0175      * @param string $key
0176      * @return Zend_Controller_Request_Abstract
0177      */
0178     public function setModuleKey($key)
0179     {
0180         $this->_moduleKey = (string) $key;
0181         return $this;
0182     }
0183 
0184     /**
0185      * Retrieve the controller key
0186      *
0187      * @return string
0188      */
0189     public function getControllerKey()
0190     {
0191         return $this->_controllerKey;
0192     }
0193 
0194     /**
0195      * Set the controller key
0196      *
0197      * @param string $key
0198      * @return Zend_Controller_Request_Abstract
0199      */
0200     public function setControllerKey($key)
0201     {
0202         $this->_controllerKey = (string) $key;
0203         return $this;
0204     }
0205 
0206     /**
0207      * Retrieve the action key
0208      *
0209      * @return string
0210      */
0211     public function getActionKey()
0212     {
0213         return $this->_actionKey;
0214     }
0215 
0216     /**
0217      * Set the action key
0218      *
0219      * @param string $key
0220      * @return Zend_Controller_Request_Abstract
0221      */
0222     public function setActionKey($key)
0223     {
0224         $this->_actionKey = (string) $key;
0225         return $this;
0226     }
0227 
0228     /**
0229      * Get an action parameter
0230      *
0231      * @param string $key
0232      * @param mixed $default Default value to use if key not found
0233      * @return mixed
0234      */
0235     public function getParam($key, $default = null)
0236     {
0237         $key = (string) $key;
0238         if (isset($this->_params[$key])) {
0239             return $this->_params[$key];
0240         }
0241 
0242         return $default;
0243     }
0244 
0245     /**
0246      * Retrieve only user params (i.e, any param specific to the object and not the environment)
0247      *
0248      * @return array
0249      */
0250     public function getUserParams()
0251     {
0252         return $this->_params;
0253     }
0254 
0255     /**
0256      * Retrieve a single user param (i.e, a param specific to the object and not the environment)
0257      *
0258      * @param string $key
0259      * @param string $default Default value to use if key not found
0260      * @return mixed
0261      */
0262     public function getUserParam($key, $default = null)
0263     {
0264         if (isset($this->_params[$key])) {
0265             return $this->_params[$key];
0266         }
0267 
0268         return $default;
0269     }
0270 
0271     /**
0272      * Set an action parameter
0273      *
0274      * A $value of null will unset the $key if it exists
0275      *
0276      * @param string $key
0277      * @param mixed $value
0278      * @return Zend_Controller_Request_Abstract
0279      */
0280     public function setParam($key, $value)
0281     {
0282         $key = (string) $key;
0283 
0284         if ((null === $value) && isset($this->_params[$key])) {
0285             unset($this->_params[$key]);
0286         } elseif (null !== $value) {
0287             $this->_params[$key] = $value;
0288         }
0289 
0290         return $this;
0291     }
0292 
0293     /**
0294      * Get all action parameters
0295      *
0296      * @return array
0297      */
0298      public function getParams()
0299      {
0300          return $this->_params;
0301      }
0302 
0303     /**
0304      * Set action parameters en masse; does not overwrite
0305      *
0306      * Null values will unset the associated key.
0307      *
0308      * @param array $array
0309      * @return Zend_Controller_Request_Abstract
0310      */
0311     public function setParams(array $array)
0312     {
0313         $this->_params = $this->_params + (array) $array;
0314 
0315         foreach ($array as $key => $value) {
0316             if (null === $value) {
0317                 unset($this->_params[$key]);
0318             }
0319         }
0320 
0321         return $this;
0322     }
0323 
0324     /**
0325      * Unset all user parameters
0326      *
0327      * @return Zend_Controller_Request_Abstract
0328      */
0329     public function clearParams()
0330     {
0331         $this->_params = array();
0332         return $this;
0333     }
0334 
0335     /**
0336      * Set flag indicating whether or not request has been dispatched
0337      *
0338      * @param boolean $flag
0339      * @return Zend_Controller_Request_Abstract
0340      */
0341     public function setDispatched($flag = true)
0342     {
0343         $this->_dispatched = $flag ? true : false;
0344         return $this;
0345     }
0346 
0347     /**
0348      * Determine if the request has been dispatched
0349      *
0350      * @return boolean
0351      */
0352     public function isDispatched()
0353     {
0354         return $this->_dispatched;
0355     }
0356 }