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: Static.php 24593 2012-01-05 20:35:02Z matthew $ |
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'; |
28 * |
28 * |
29 * It's a lot faster compared to the standard Route implementation. |
29 * It's a lot faster compared to the standard Route implementation. |
30 * |
30 * |
31 * @package Zend_Controller |
31 * @package Zend_Controller |
32 * @subpackage Router |
32 * @subpackage Router |
33 * @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) |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 */ |
35 */ |
36 class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_Abstract |
36 class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_Abstract |
37 { |
37 { |
38 |
38 |
|
39 /** |
|
40 * Route |
|
41 * |
|
42 * @var string|null |
|
43 */ |
39 protected $_route = null; |
44 protected $_route = null; |
|
45 |
|
46 /** |
|
47 * Default values for the route (ie. module, controller, action, params) |
|
48 * |
|
49 * @var array |
|
50 */ |
40 protected $_defaults = array(); |
51 protected $_defaults = array(); |
41 |
52 |
42 public function getVersion() { |
53 /** |
|
54 * Get the version of the route |
|
55 * |
|
56 * @return int |
|
57 */ |
|
58 public function getVersion() |
|
59 { |
43 return 1; |
60 return 1; |
44 } |
61 } |
45 |
62 |
46 /** |
63 /** |
47 * Instantiates route based on passed Zend_Config structure |
64 * Instantiates route based on passed Zend_Config structure |
48 * |
65 * |
49 * @param Zend_Config $config Configuration object |
66 * @param Zend_Config $config Configuration object |
|
67 * @return Zend_Controller_Router_Route_Static |
50 */ |
68 */ |
51 public static function getInstance(Zend_Config $config) |
69 public static function getInstance(Zend_Config $config) |
52 { |
70 { |
53 $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); |
71 $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); |
|
72 |
54 return new self($config->route, $defs); |
73 return new self($config->route, $defs); |
55 } |
74 } |
56 |
75 |
57 /** |
76 /** |
58 * Prepares the route for mapping. |
77 * Prepares the route for mapping. |
59 * |
78 * |
60 * @param string $route Map used to match with later submitted URL path |
79 * @param string $route Map used to match with later submitted URL path |
61 * @param array $defaults Defaults for map variables with keys as variable names |
80 * @param array $defaults Defaults for map variables with keys as variable names |
62 */ |
81 */ |
63 public function __construct($route, $defaults = array()) |
82 public function __construct($route, $defaults = array()) |
64 { |
83 { |
65 $this->_route = trim($route, self::URI_DELIMITER); |
84 $this->_route = trim($route, self::URI_DELIMITER); |
66 $this->_defaults = (array) $defaults; |
85 $this->_defaults = (array) $defaults; |
67 } |
86 } |
68 |
87 |
69 /** |
88 /** |
70 * Matches a user submitted path with a previously defined route. |
89 * Matches a user submitted path with a previously defined route. |
78 if ($partial) { |
97 if ($partial) { |
79 if ((empty($path) && empty($this->_route)) |
98 if ((empty($path) && empty($this->_route)) |
80 || (substr($path, 0, strlen($this->_route)) === $this->_route) |
99 || (substr($path, 0, strlen($this->_route)) === $this->_route) |
81 ) { |
100 ) { |
82 $this->setMatchedPath($this->_route); |
101 $this->setMatchedPath($this->_route); |
|
102 |
83 return $this->_defaults; |
103 return $this->_defaults; |
84 } |
104 } |
85 } else { |
105 } else { |
86 if (trim($path, self::URI_DELIMITER) == $this->_route) { |
106 if (trim($path, self::URI_DELIMITER) == $this->_route) { |
87 return $this->_defaults; |
107 return $this->_defaults; |
106 * Return a single parameter of route's defaults |
126 * Return a single parameter of route's defaults |
107 * |
127 * |
108 * @param string $name Array key of the parameter |
128 * @param string $name Array key of the parameter |
109 * @return string Previously set default |
129 * @return string Previously set default |
110 */ |
130 */ |
111 public function getDefault($name) { |
131 public function getDefault($name) |
|
132 { |
112 if (isset($this->_defaults[$name])) { |
133 if (isset($this->_defaults[$name])) { |
113 return $this->_defaults[$name]; |
134 return $this->_defaults[$name]; |
114 } |
135 } |
|
136 |
115 return null; |
137 return null; |
116 } |
138 } |
117 |
139 |
118 /** |
140 /** |
119 * Return an array of defaults |
141 * Return an array of defaults |
120 * |
142 * |
121 * @return array Route defaults |
143 * @return array Route defaults |
122 */ |
144 */ |
123 public function getDefaults() { |
145 public function getDefaults() |
|
146 { |
124 return $this->_defaults; |
147 return $this->_defaults; |
125 } |
148 } |
126 |
|
127 } |
149 } |