1 | <?php |
||
49 | class RouteManager |
||
50 | { |
||
51 | /** |
||
52 | * @access protected |
||
53 | * @var Framework |
||
54 | */ |
||
55 | protected $framework; |
||
56 | |||
57 | /** |
||
58 | * @access protected |
||
59 | * @var ObjectBackendAbstract |
||
60 | */ |
||
61 | protected $routeObjectBackend; |
||
62 | |||
63 | /** |
||
64 | * @access protected |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $routes = array(); |
||
68 | |||
69 | /** |
||
70 | * Constructs the object |
||
71 | * |
||
72 | * @access public |
||
73 | * @param \Zepi\Turbo\Framework $framework |
||
74 | * @param \Zepi\Turbo\Backend\ObjectBackendAbstract $routeObjectBackend |
||
75 | */ |
||
76 | 27 | public function __construct(Framework $framework, ObjectBackendAbstract $routeObjectBackend) |
|
81 | |||
82 | /** |
||
83 | * Initializes the routing table. The function loads |
||
84 | * the saved routes from the object backend. |
||
85 | * |
||
86 | * @access public |
||
87 | */ |
||
88 | 27 | public function initializeRoutingTable() |
|
97 | |||
98 | /** |
||
99 | * Adds an event handler for the given event. |
||
100 | * |
||
101 | * @access public |
||
102 | * @param string $route |
||
103 | * @param string $eventName |
||
104 | * @param integer $priority |
||
105 | * @return boolean |
||
106 | */ |
||
107 | 9 | public function addRoute($route, $eventName, $priority = 50) |
|
127 | |||
128 | /** |
||
129 | * Removes a route for the given priority. |
||
130 | * |
||
131 | * @access public |
||
132 | * @param string $route |
||
133 | * @param integer $priority |
||
134 | * @return boolean |
||
135 | */ |
||
136 | 3 | public function removeRoute($route, $priority = 50) |
|
154 | |||
155 | /** |
||
156 | * Clears the route cache and reactivates the modules |
||
157 | * to rebuild the cache. |
||
158 | * |
||
159 | * @access public |
||
160 | * @param boolean $reactivateModules |
||
161 | */ |
||
162 | 1 | public function clearCache($reactivateModules = true) |
|
163 | { |
||
164 | 1 | $this->routes = array(); |
|
165 | |||
166 | 1 | if ($reactivateModules) { |
|
167 | 1 | $this->framework->getModuleManager()->reactivateModules(); |
|
168 | } |
||
169 | 1 | } |
|
170 | |||
171 | /** |
||
172 | * Saves the routes in the object backend |
||
173 | * |
||
174 | * @access protected |
||
175 | */ |
||
176 | 9 | protected function saveRoutes() |
|
177 | { |
||
178 | 9 | $this->routeObjectBackend->saveObject($this->routes); |
|
179 | 9 | } |
|
180 | |||
181 | /** |
||
182 | * Returns the event name for the given request. The function uses |
||
183 | * the first possible match. The routes are sorted by the priority. |
||
184 | * |
||
185 | * @access public |
||
186 | * @param \Zepi\Turbo\Request\RequestAbstract $request |
||
187 | * @return false|string |
||
188 | */ |
||
189 | 11 | public function getEventNameForRoute(RequestAbstract $request) |
|
206 | |||
207 | /** |
||
208 | * Compares the target route with the found route in the routing table. |
||
209 | * |
||
210 | * @access protected |
||
211 | * @param string $route |
||
212 | * @param \Zepi\Turbo\Request\RequestAbstract $request |
||
213 | * @return boolean |
||
214 | */ |
||
215 | 9 | protected function compareRoute($route, RequestAbstract $request) |
|
260 | |||
261 | /** |
||
262 | * Parses the route param data to the correct format |
||
263 | * |
||
264 | * @access protected |
||
265 | * @param string $part |
||
266 | * @param string $targetPart |
||
267 | * @return array |
||
268 | */ |
||
269 | 2 | protected function parseRouteParam($part, $targetPart) |
|
290 | } |
||
291 |