File indexing completed on 2024-12-22 05:36:34

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  * @subpackage Router
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /** Zend_Controller_Router_Interface */
0024 // require_once 'Zend/Controller/Router/Interface.php';
0025 
0026 /**
0027  * Simple first implementation of a router, to be replaced
0028  * with rules-based URI processor.
0029  *
0030  * @category   Zend
0031  * @package    Zend_Controller
0032  * @subpackage Router
0033  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0034  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0035  */
0036 abstract class Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface
0037 {
0038     /**
0039      * URI delimiter
0040      */
0041     const URI_DELIMITER = '/';
0042 
0043     /**
0044      * Front controller instance
0045      *
0046      * @var Zend_Controller_Front
0047      */
0048     protected $_frontController;
0049 
0050     /**
0051      * Array of invocation parameters to use when instantiating action
0052      * controllers
0053      *
0054      * @var array
0055      */
0056     protected $_invokeParams = array();
0057 
0058     /**
0059      * Constructor
0060      *
0061      * @param array $params
0062      */
0063     public function __construct(array $params = array())
0064     {
0065         $this->setParams($params);
0066     }
0067 
0068     /**
0069      * Add or modify a parameter to use when instantiating an action controller
0070      *
0071      * @param string $name
0072      * @param mixed  $value
0073      * @return Zend_Controller_Router_Abstract
0074      */
0075     public function setParam($name, $value)
0076     {
0077         $name                       = (string)$name;
0078         $this->_invokeParams[$name] = $value;
0079 
0080         return $this;
0081     }
0082 
0083     /**
0084      * Set parameters to pass to action controller constructors
0085      *
0086      * @param array $params
0087      * @return Zend_Controller_Router_Abstract
0088      */
0089     public function setParams(array $params)
0090     {
0091         $this->_invokeParams = array_merge($this->_invokeParams, $params);
0092 
0093         return $this;
0094     }
0095 
0096     /**
0097      * Retrieve a single parameter from the controller parameter stack
0098      *
0099      * @param string $name
0100      * @return mixed
0101      */
0102     public function getParam($name)
0103     {
0104         if (isset($this->_invokeParams[$name])) {
0105             return $this->_invokeParams[$name];
0106         }
0107 
0108         return null;
0109     }
0110 
0111     /**
0112      * Retrieve action controller instantiation parameters
0113      *
0114      * @return array
0115      */
0116     public function getParams()
0117     {
0118         return $this->_invokeParams;
0119     }
0120 
0121     /**
0122      * Clear the controller parameter stack
0123      *
0124      * By default, clears all parameters. If a parameter name is given, clears
0125      * only that parameter; if an array of parameter names is provided, clears
0126      * each.
0127      *
0128      * @param null|string|array single key or array of keys for params to clear
0129      * @return Zend_Controller_Router_Abstract
0130      */
0131     public function clearParams($name = null)
0132     {
0133         if (null === $name) {
0134             $this->_invokeParams = array();
0135         } elseif (is_string($name) && isset($this->_invokeParams[$name])) {
0136             unset($this->_invokeParams[$name]);
0137         } elseif (is_array($name)) {
0138             foreach ($name as $key) {
0139                 if (is_string($key) && isset($this->_invokeParams[$key])) {
0140                     unset($this->_invokeParams[$key]);
0141                 }
0142             }
0143         }
0144 
0145         return $this;
0146     }
0147 
0148     /**
0149      * Retrieve Front Controller
0150      *
0151      * @return Zend_Controller_Front
0152      */
0153     public function getFrontController()
0154     {
0155         // Used cache version if found
0156         if (null !== $this->_frontController) {
0157             return $this->_frontController;
0158         }
0159 
0160         // require_once 'Zend/Controller/Front.php';
0161         $this->_frontController = Zend_Controller_Front::getInstance();
0162 
0163         return $this->_frontController;
0164     }
0165 
0166     /**
0167      * Set Front Controller
0168      *
0169      * @param Zend_Controller_Front $controller
0170      * @return Zend_Controller_Router_Interface
0171      */
0172     public function setFrontController(Zend_Controller_Front $controller)
0173     {
0174         $this->_frontController = $controller;
0175 
0176         return $this;
0177     }
0178 }