0
@@ -166,7 +166,7 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
public function get_routes()
0
- $this->core_routes = $_MIDCOM->configuration->
get('routes');
0
+ $this->core_routes = $_MIDCOM->configuration->
normalize_routes($_MIDCOM->configuration->get('routes'));
0
if ( !isset($_MIDCOM->context->component_instance)
0
|| !$_MIDCOM->context->component_instance)
0
@@ -174,11 +174,12 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
return $this->core_routes;
0
- $this->component_routes = $_MIDCOM->con
text->component_instance->configuration->get('routes');
0
+ $this->component_routes = $_MIDCOM->con
figuration->normalize_routes($_MIDCOM->context->component_instance->configuration->get('routes'));
0
return array_merge($this->core_routes, $this->component_routes);
0
* Load a component and dispatch the request to it
0
@@ -217,13 +218,35 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
$selected_route_configuration = $route_definitions[$this->route_id];
0
+ // Handle allowed HTTP methods
0
+ header('Allow: ' . implode(', ', $selected_route_configuration['allowed_methods']));
0
+ if (!in_array($_SERVER['REQUEST_METHOD'], $selected_route_configuration['allowed_methods']))
0
+ throw new midcom_exception_httperror("{$_SERVER['REQUEST_METHOD']} not allowed", 405);
0
// Initialize controller
0
$controller_class = $selected_route_configuration['controller'];
0
$controller = new $controller_class($_MIDCOM->context->component_instance);
0
$controller->dispatcher = $this;
0
- //
Then call the route_id
0
+ //
Define the action method for the route_id
0
$action_method = "action_{$selected_route_configuration['action']}";
0
+ // Handle HTTP request
0
+ switch ($_SERVER['REQUEST_METHOD'])
0
+ // Short-cut these types directly to the controller
0
+ // For others, start the full WebDAV server instance
0
+ $webdav_server = new midcom_core_helpers_webdav($controller);
0
+ $webdav_server->serve($this->route_id, $action_method, $this->action_arguments);
0
// TODO: store this array somewhere where it can be accessed via get_context_item
0
@@ -312,44 +335,6 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
return preg_replace('%/{2,}%', '/', $_MIDCOM->context->prefix . $link);
0
- * Normalizes given route definition ready for parsing
0
- * @param string $route route definition
0
- * @return string normalized route
0
- public function normalize_route($route)
0
- if ( strpos($route, '?') === false
0
- && substr($route, -1, 1) !== '/')
0
- return preg_replace('%/{2,}%', '/', $route);
0
- * Splits a given route (after normalizing it) to it's path and get parts
0
- * @param string $route reference to a route definition
0
- * @return array first item is path part, second is get part, both default to boolean false
0
- public function split_route(&$route)
0
- $route = $this->normalize_route($route);
0
- $route_parts = explode('?', $route, 2);
0
- $route_path = $route_parts[0];
0
- if (isset($route_parts[1]))
0
- $route_get = $route_parts[1];
0
- return array($route_path, $route_get);
0
* Tries to match one route from an array of route definitions
0
@@ -377,7 +362,7 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
$this->action_arguments = array();
0
- list ($route_path, $route_get
) = $this->split_route($route);
0
+ list ($route_path, $route_get
, $route_args) = $_MIDCOM->configuration->split_route($route);
0
//echo "DEBUG: route_id: {$route_id} route:{$route} argv_str:{$argv_str}\n";
0
@@ -419,8 +404,16 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
foreach ($route_path_matches[1] as $index => $varname)
0
- preg_match('/{$([a-zA-Z]+):([a-zA-Z]+)}/', $varname, $matches);
0
- $type_hint = $matches[0];
0
+ preg_match('%/{\$([a-zA-Z]+):([a-zA-Z]+)}/%', $varname, $matches);
0
+ if(count($matches) == 0)
0
+ $type_hint = $matches[1];
0
// Strip type hints from variable names
0
$varname = preg_replace('/^.+:/', '', $varname);
0
@@ -483,8 +476,16 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
- preg_match('/{$([a-zA-Z]+):([a-zA-Z]+)}/', $route_get_matches[2][$index], $matches);
0
- $type_hint = $matches[0];
0
+ preg_match('%/{\$([a-zA-Z]+):([a-zA-Z]+)}/%', $route_get_matches[2][$index], $matches);
0
+ if(count($matches) == 0)
0
+ $type_hint = $matches[1];
0
// Strip type hints from variable names
0
$varname = preg_replace('/^.+:/', '', $route_get_matches[2][$index]);
Comments
No one has commented yet.