public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
Basic support for overlapping routes. No exception handling yet.
Tero Heikkinen (author)
Sat Jul 05 12:03:45 -0700 2008
commit  263276bb21e837c5f09df6339ab03542b99dea2c
tree    14aeb3eb751591e223fe5634a9db73745ad0936b
parent  59e15b98643ea8de6167a68caad68677bac11b0a
...
19
20
21
 
22
23
24
25
26
 
27
28
29
...
192
193
194
195
196
 
 
197
198
 
199
200
201
...
207
208
209
210
211
 
 
 
212
213
214
215
216
217
218
219
220
221
222
223
 
 
 
 
 
 
 
 
 
 
 
 
 
224
225
226
...
232
233
234
235
 
236
237
238
 
239
240
241
242
 
 
243
244
245
...
269
270
271
 
272
273
274
...
361
362
363
364
 
 
365
 
 
366
367
368
...
375
376
377
378
379
380
381
 
 
 
 
382
383
384
385
386
387
388
 
389
390
391
 
 
392
393
394
...
417
418
419
420
421
 
 
422
423
424
...
452
453
454
455
 
456
457
458
 
 
459
460
461
462
463
 
464
465
466
 
 
 
 
 
467
468
469
...
19
20
21
22
23
24
25
26
27
28
29
30
31
...
194
195
196
 
 
197
198
199
 
200
201
202
203
...
209
210
211
 
 
212
213
214
215
216
 
217
218
219
220
221
222
 
 
 
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
...
244
245
246
 
247
248
249
 
250
251
252
 
 
253
254
255
256
257
...
281
282
283
284
285
286
287
...
374
375
376
 
377
378
379
380
381
382
383
384
...
391
392
393
 
 
 
 
394
395
396
397
398
399
400
401
402
403
 
404
405
 
 
406
407
408
409
410
...
433
434
435
 
 
436
437
438
439
440
...
468
469
470
 
471
472
 
 
473
474
475
476
477
478
 
479
480
481
 
482
483
484
485
486
487
488
489
0
@@ -19,11 +19,13 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
     public $get = array();
0
     public $component_name = '';
0
     public $request_method = 'GET';
0
+ protected $route_array = array();
0
     protected $route_id = false;
0
     protected $action_arguments = array();
0
     protected $route_arguments = array();
0
     protected $core_routes = array();
0
     protected $component_routes = array();
0
+ protected $route_definitions = null;
0
 
0
     public function __construct()
0
     {
0
@@ -192,10 +194,10 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
         {
0
             $_MIDCOM->timer->setMarker('MidCOM dispatcher::dispatch');
0
         }
0
- $route_definitions = $this->get_routes();
0
-
0
+ $this->route_definitions = $this->get_routes();
0
+
0
         $route_id_map = array();
0
- foreach ($route_definitions as $route_id => $route_configuration)
0
+ foreach ($this->route_definitions as $route_id => $route_configuration)
0
         {
0
             if ( isset($route_configuration['root_only'])
0
                 && $route_configuration['root_only'])
0
@@ -207,20 +209,30 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
                     continue;
0
                 }
0
             }
0
-
0
- $route_id_map[$route_configuration['route']] = $route_id;
0
+ $route_id_map[] = array('route' => $route_configuration['route'],
0
+ 'route_id' => $route_id);
0
+// $route_id_map[$route_configuration['route']] = $route_id;
0
         }
0
         unset($route_configuration, $route_id);
0
-
0
         if (!$this->route_matches($route_id_map))
0
         {
0
             // TODO: Check message
0
             throw new midcom_exception_notfound('No route matches current URL');
0
         }
0
         unset($route_id_map);
0
-
0
- $selected_route_configuration = $route_definitions[$this->route_id];
0
-
0
+ foreach($this->route_array as $route)
0
+ {
0
+ $this->dispatch_route($route);
0
+ break; // if we get here, controller run succesfully
0
+ }
0
+ }
0
+
0
+ private function dispatch_route($route)
0
+ {
0
+ $this->route_id = $route;
0
+ $_MIDCOM->context->route_id = $this->route_id;
0
+ $selected_route_configuration = $this->route_definitions[$this->route_id];
0
+
0
         // Handle allowed HTTP methods
0
         header('Allow: ' . implode(', ', $selected_route_configuration['allowed_methods']));
0
         if (!in_array($this->request_method, $selected_route_configuration['allowed_methods']))
0
@@ -232,14 +244,14 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
         $controller_class = $selected_route_configuration['controller'];
0
         $controller = new $controller_class($_MIDCOM->context->component_instance);
0
         $controller->dispatcher = $this;
0
-
0
+
0
         // Define the action method for the route_id
0
         $action_method = "action_{$selected_route_configuration['action']}";
0
-
0
+
0
         // Handle HTTP request
0
         if ( isset($selected_route_configuration['webdav_only'])
0
- && $selected_route_configuration['webdav_only']
0
- || ( $this->request_method != 'GET'
0
+ && $selected_route_configuration['webdav_only']
0
+ || ( $this->request_method != 'GET'
0
                 && $this->request_method != 'POST')
0
             )
0
         {
0
@@ -269,6 +281,7 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
         }
0
         
0
         $this->data_to_context($selected_route_configuration, $data);
0
+
0
     }
0
     
0
     private function is_core_route($route_id)
0
@@ -361,8 +374,11 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
         // make a normalized string of $argv
0
         $argv_str = preg_replace('%/{2,}%', '/', '/' . implode('/', $this->argv) . '/');
0
         
0
- foreach ($routes as $route => $route_id)
0
+// foreach ($routes as $route => $route_id)
0
+ foreach ($routes as $r)
0
         {
0
+ $route = $r['route'];
0
+ $route_id = $r['route_id'];
0
             // Reset variables
0
             $this->action_arguments = array();
0
             list ($route_path, $route_get, $route_args) = $_MIDCOM->configuration->split_route($route);
0
@@ -375,20 +391,20 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
                         || $this->get_matches($route_get, $route))
0
                     )
0
                 {
0
- //echo "DEBUG: simple match route_id:{$route_id}\n";
0
- $this->route_id = $route_id;
0
- $_MIDCOM->context->route_id = $this->route_id;
0
- return true;
0
+ // echo "DEBUG: simple match route_id:{$route_id}\n";
0
+ $this->route_array[] = $route_id;
0
+ //$_MIDCOM->context->route_id = $this->route_id;
0
+ //return true;
0
                 }
0
                 if ($route_args) // Route @ set
0
                 {
0
                     $path = explode('@', $route_path);
0
                     if (preg_match('%' . str_replace('/', '\/', $path[0]) . '/(.*)\/%', $argv_str, $matches))
0
                     {
0
- $this->route_id = $route_id;
0
+ $this->route_array[] = $route_id;
0
                         $this->action_arguments['variable_arguments'] = explode('/', $matches[1]);
0
- $_MIDCOM->context->route_id = $this->route_id;
0
- return true;
0
+ //$_MIDCOM->context->route_id = $this->route_id;
0
+ //return true;
0
                     }
0
                 }
0
                 // Did not match, try next route
0
@@ -417,8 +433,8 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
             }
0
 
0
             // We have a complete match, setup route_id arguments and return
0
- $this->route_id = $route_id;
0
- $_MIDCOM->context->route_id = $this->route_id;
0
+ $this->route_array[] = $route_id;
0
+ //$_MIDCOM->context->route_id = $this->route_id;
0
             // Map variable arguments
0
             
0
             foreach ($route_path_matches[1] as $index => $varname)
0
@@ -452,18 +468,22 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
                     $path = explode('@', $route_path);
0
                     if (preg_match('%' . str_replace('/', '\/', preg_replace('%\{(.+?)\}%', '([^/]+?)', $path[0])) . '/(.*)\/%', $argv_str, $matches))
0
                     {
0
- $this->route_id = $route_id;
0
+ $this->route_array[] = $route_id;
0
                         $this->action_arguments = explode('/', $matches[1]);
0
- $_MIDCOM->context->route_id = $this->route_id;
0
- return true;
0
+ //$_MIDCOM->context->route_id = $this->route_id;
0
+ //return true;
0
                     }
0
                 }
0
                 
0
             }
0
- return true;
0
+ //return true;
0
         }
0
         // No match
0
- return false;
0
+ if(count($this->route_array) == 0)
0
+ {
0
+ return false;
0
+ }
0
+ return true;
0
     }
0
 
0
     /**

Comments

    No one has commented yet.