web/lib/Zend/Controller/Router/Route/Chain.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  * @version    $Id: Chain.php 25249 2013-02-06 09:54:24Z frosch $
    19  * @version    $Id$
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    21  */
    21  */
    22 
    22 
    23 /** Zend_Controller_Router_Route_Abstract */
    23 /** Zend_Controller_Router_Route_Abstract */
    24 require_once 'Zend/Controller/Router/Route/Abstract.php';
    24 require_once 'Zend/Controller/Router/Route/Abstract.php';
    26 /**
    26 /**
    27  * Chain route is used for managing route chaining.
    27  * Chain route is used for managing route chaining.
    28  *
    28  *
    29  * @package    Zend_Controller
    29  * @package    Zend_Controller
    30  * @subpackage Router
    30  * @subpackage Router
    31  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    31  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    33  */
    33  */
    34 class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Abstract
    34 class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Abstract
    35 {
    35 {
       
    36 
       
    37     /**
       
    38      * Routes
       
    39      *
       
    40      * @var array
       
    41      */
    36     protected $_routes = array();
    42     protected $_routes = array();
       
    43 
       
    44     /**
       
    45      * Separators
       
    46      *
       
    47      * @var array
       
    48      */
    37     protected $_separators = array();
    49     protected $_separators = array();
    38 
    50 
    39     /**
    51     /**
    40      * Instantiates route based on passed Zend_Config structure
    52      * Instantiates route based on passed Zend_Config structure
    41      *
    53      *
    43      * @return Zend_Controller_Router_Route_Chain
    55      * @return Zend_Controller_Router_Route_Chain
    44      */
    56      */
    45     public static function getInstance(Zend_Config $config)
    57     public static function getInstance(Zend_Config $config)
    46     {
    58     {
    47         $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
    59         $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
       
    60 
    48         return new self($config->route, $defs);
    61         return new self($config->route, $defs);
    49     }
    62     }
    50 
    63 
    51     /**
    64     /**
    52      * Add a route to this chain
    65      * Add a route to this chain
    59     {
    72     {
    60         $this->_routes[]     = $route;
    73         $this->_routes[]     = $route;
    61         $this->_separators[] = $separator;
    74         $this->_separators[] = $separator;
    62 
    75 
    63         return $this;
    76         return $this;
    64 
       
    65     }
    77     }
    66 
    78 
    67     /**
    79     /**
    68      * Matches a user submitted path with a previously defined route.
    80      * Matches a user submitted path with a previously defined route.
    69      * Assigns and returns an array of defaults on a successful match.
    81      * Assigns and returns an array of defaults on a successful match.
   109             }
   121             }
   110 
   122 
   111             $matchedPath = $route->getMatchedPath();
   123             $matchedPath = $route->getMatchedPath();
   112 
   124 
   113             if ($matchedPath !== null) {
   125             if ($matchedPath !== null) {
   114                 $subPath     = substr($subPath, strlen($matchedPath));
   126                 $subPath   = substr($subPath, strlen($matchedPath));
   115                 $separator   = substr($subPath, 0, strlen($this->_separators[$key]));
   127                 $separator = substr($subPath, 0, strlen($this->_separators[$key]));
   116             }
   128             }
   117 
   129 
   118             $values = $res + $values;
   130             $values = $res + $values;
   119         }
   131         }
   120 
   132 
   173             if (method_exists($route, 'setRequest')) {
   185             if (method_exists($route, 'setRequest')) {
   174                 $route->setRequest($request);
   186                 $route->setRequest($request);
   175             }
   187             }
   176         }
   188         }
   177     }
   189     }
   178     
   190 
   179     /**
   191     /**
   180      * Return a single parameter of route's defaults
   192      * Return a single parameter of route's defaults
   181      *
   193      *
   182      * @param  string $name Array key of the parameter
   194      * @param  string $name Array key of the parameter
   183      * @return string Previously set default
   195      * @return string Previously set default