private function invokeRoute($routes, $request, &$respond)
{
$method = $request['$._SERVER.REQUEST_METHOD'];
$path = $request['$.path'];
$uri = $request['$._SERVER.REQUEST_URI'];
list(, $params) = explode('?', $uri) + array(null, null);
$params = is_null($params) ? null : explode('&', $params);
Logger::debug("try to find route {$method} " . $uri);
$match_path = array();
if (isset($routes[$method])) {
if (($api = $routes[$method]->findByArray($path, $params, $match_path)) !== null) {
Logger::debug("invoke {$uri} => {$api->getClassName()}::{$api->getMethodName()}");
$api($request, $respond);
return true;
}
}
if (!isset($routes['*'])) {
return false;
}
if (($api = $routes['*']->find($uri, $match_path)) === null) {
return false;
}
Logger::debug("invoke {$uri} => {$api->getClassName()}::{$api->getMethodName()}");
$api($request, $respond);
return true;
}