web/lib/Zend/Controller/Router/Abstract.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Controller
    16  * @package    Zend_Controller
    17  * @subpackage Router
    17  * @subpackage Router
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Abstract.php 24593 2012-01-05 20:35:02Z matthew $
    20  * @version    $Id$
    21  */
    21  */
    22 
       
    23 
    22 
    24 /** Zend_Controller_Router_Interface */
    23 /** Zend_Controller_Router_Interface */
    25 require_once 'Zend/Controller/Router/Interface.php';
    24 require_once 'Zend/Controller/Router/Interface.php';
    26 
    25 
    27 /**
    26 /**
    29  * with rules-based URI processor.
    28  * with rules-based URI processor.
    30  *
    29  *
    31  * @category   Zend
    30  * @category   Zend
    32  * @package    Zend_Controller
    31  * @package    Zend_Controller
    33  * @subpackage Router
    32  * @subpackage Router
    34  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    36  */
    35  */
    37 abstract class Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface
    36 abstract class Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface
    38 {
    37 {
    39     /**
    38     /**
    40      * URI delimiter
    39      * URI delimiter
    41      */
    40      */
    42     const URI_DELIMITER = '/';
    41     const URI_DELIMITER = '/';
    43     
    42 
    44     /**
    43     /**
    45      * Front controller instance
    44      * Front controller instance
       
    45      *
    46      * @var Zend_Controller_Front
    46      * @var Zend_Controller_Front
    47      */
    47      */
    48     protected $_frontController;
    48     protected $_frontController;
    49 
    49 
    50     /**
    50     /**
    51      * Array of invocation parameters to use when instantiating action
    51      * Array of invocation parameters to use when instantiating action
    52      * controllers
    52      * controllers
       
    53      *
    53      * @var array
    54      * @var array
    54      */
    55      */
    55     protected $_invokeParams = array();
    56     protected $_invokeParams = array();
    56 
    57 
    57     /**
    58     /**
    58      * Constructor
    59      * Constructor
    59      *
    60      *
    60      * @param array $params
    61      * @param array $params
    61      * @return void
       
    62      */
    62      */
    63     public function __construct(array $params = array())
    63     public function __construct(array $params = array())
    64     {
    64     {
    65         $this->setParams($params);
    65         $this->setParams($params);
    66     }
    66     }
    67 
    67 
    68     /**
    68     /**
    69      * Add or modify a parameter to use when instantiating an action controller
    69      * Add or modify a parameter to use when instantiating an action controller
    70      *
    70      *
    71      * @param string $name
    71      * @param string $name
    72      * @param mixed $value
    72      * @param mixed  $value
    73      * @return Zend_Controller_Router
    73      * @return Zend_Controller_Router_Abstract
    74      */
    74      */
    75     public function setParam($name, $value)
    75     public function setParam($name, $value)
    76     {
    76     {
    77         $name = (string) $name;
    77         $name                       = (string)$name;
    78         $this->_invokeParams[$name] = $value;
    78         $this->_invokeParams[$name] = $value;
       
    79 
    79         return $this;
    80         return $this;
    80     }
    81     }
    81 
    82 
    82     /**
    83     /**
    83      * Set parameters to pass to action controller constructors
    84      * Set parameters to pass to action controller constructors
    84      *
    85      *
    85      * @param array $params
    86      * @param array $params
    86      * @return Zend_Controller_Router
    87      * @return Zend_Controller_Router_Abstract
    87      */
    88      */
    88     public function setParams(array $params)
    89     public function setParams(array $params)
    89     {
    90     {
    90         $this->_invokeParams = array_merge($this->_invokeParams, $params);
    91         $this->_invokeParams = array_merge($this->_invokeParams, $params);
       
    92 
    91         return $this;
    93         return $this;
    92     }
    94     }
    93 
    95 
    94     /**
    96     /**
    95      * Retrieve a single parameter from the controller parameter stack
    97      * Retrieve a single parameter from the controller parameter stack
    97      * @param string $name
    99      * @param string $name
    98      * @return mixed
   100      * @return mixed
    99      */
   101      */
   100     public function getParam($name)
   102     public function getParam($name)
   101     {
   103     {
   102         if(isset($this->_invokeParams[$name])) {
   104         if (isset($this->_invokeParams[$name])) {
   103             return $this->_invokeParams[$name];
   105             return $this->_invokeParams[$name];
   104         }
   106         }
   105 
   107 
   106         return null;
   108         return null;
   107     }
   109     }
   122      * By default, clears all parameters. If a parameter name is given, clears
   124      * By default, clears all parameters. If a parameter name is given, clears
   123      * only that parameter; if an array of parameter names is provided, clears
   125      * only that parameter; if an array of parameter names is provided, clears
   124      * each.
   126      * each.
   125      *
   127      *
   126      * @param null|string|array single key or array of keys for params to clear
   128      * @param null|string|array single key or array of keys for params to clear
   127      * @return Zend_Controller_Router
   129      * @return Zend_Controller_Router_Abstract
   128      */
   130      */
   129     public function clearParams($name = null)
   131     public function clearParams($name = null)
   130     {
   132     {
   131         if (null === $name) {
   133         if (null === $name) {
   132             $this->_invokeParams = array();
   134             $this->_invokeParams = array();
   155             return $this->_frontController;
   157             return $this->_frontController;
   156         }
   158         }
   157 
   159 
   158         require_once 'Zend/Controller/Front.php';
   160         require_once 'Zend/Controller/Front.php';
   159         $this->_frontController = Zend_Controller_Front::getInstance();
   161         $this->_frontController = Zend_Controller_Front::getInstance();
       
   162 
   160         return $this->_frontController;
   163         return $this->_frontController;
   161     }
   164     }
   162 
   165 
   163     /**
   166     /**
   164      * Set Front Controller
   167      * Set Front Controller
   167      * @return Zend_Controller_Router_Interface
   170      * @return Zend_Controller_Router_Interface
   168      */
   171      */
   169     public function setFrontController(Zend_Controller_Front $controller)
   172     public function setFrontController(Zend_Controller_Front $controller)
   170     {
   173     {
   171         $this->_frontController = $controller;
   174         $this->_frontController = $controller;
       
   175 
   172         return $this;
   176         return $this;
   173     }
   177     }
   174 
       
   175 }
   178 }