0
@@ -19,11 +19,13 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
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
public function __construct()
0
@@ -192,10 +194,10 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
$_MIDCOM->timer->setMarker('MidCOM dispatcher::dispatch');
0
- $route_definitions = $this->get_routes();
0
+ $this->route_definitions = $this->get_routes();
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
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
- $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
unset($route_configuration, $route_id);
0
if (!$this->route_matches($route_id_map))
0
throw new midcom_exception_notfound('No route matches current URL');
0
- $selected_route_configuration = $route_definitions[$this->route_id];
0
+ foreach($this->route_array as $route)
0
+ $this->dispatch_route($route);
0
+ break; // if we get here, controller run succesfully
0
+ private function dispatch_route($route)
0
+ $this->route_id = $route;
0
+ $_MIDCOM->context->route_id = $this->route_id;
0
+ $selected_route_configuration = $this->route_definitions[$this->route_id];
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
// Define the action method for the route_id
0
$action_method = "action_{$selected_route_configuration['action']}";
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
@@ -269,6 +281,7 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
$this->data_to_context($selected_route_configuration, $data);
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
- foreach ($routes as $route => $route_id)
0
+// foreach ($routes as $route => $route_id)
0
+ foreach ($routes as $r)
0
+ $route_id = $r['route_id'];
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
- //echo "DEBUG: simple match route_id:{$route_id}\n";
0
- $this->route_id = $route_id;
0
- $_MIDCOM->context->route_id = $this->route_id;
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
if ($route_args) // Route @ set
0
$path = explode('@', $route_path);
0
if (preg_match('%' . str_replace('/', '\/', $path[0]) . '/(.*)\/%', $argv_str, $matches))
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
+ //$_MIDCOM->context->route_id = $this->route_id;
0
// Did not match, try next route
0
@@ -417,8 +433,8 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
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
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
- $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
+ //$_MIDCOM->context->route_id = $this->route_id;
0
+ if(count($this->route_array) == 0)
Comments
No one has commented yet.