Ejemplo n.º 1
0
 private function do_routing(context $ctx)
 {
     $path = $ctx->in->uri->path->_to_string();
     $routes = $this->configuration['routes'];
     $ctrl = null;
     $matches = array();
     $segments = h\collection();
     foreach ($routes as $route_pattern => $route_ctrl) {
         $results = h\regex_execute("^{$route_pattern}\$", $path);
         if ($results->is_match()) {
             $ctrl = $route_ctrl;
             $route = $route_pattern;
             $match = $results->iterate_records()[0];
             foreach ($match as $key => $pair) {
                 if (is_string($key)) {
                     $segments[$key] = \rawurldecode($path->slice($pair->begin, $pair->end));
                 }
             }
             break;
         }
     }
     $ctx->segments = $segments;
     $http_method = $ctx->in->method;
     if (is_null($ctrl)) {
         $ctx->out->status = 'HTTP/1.1 405 Method Not Allowed';
         $tpl = 'Non-supported method \'%s\' on \'%s\'';
         $msg = h\string::format($tpl, $http_method, $path);
         $ctx->error_handling['status'] = false;
         $ctx->error_handling['messages'][] = $msg;
         return false;
     }
     $ctx->route = $route;
     return true;
 }
Ejemplo n.º 2
0
 public function do_create_absolute_path(h\string $meat)
 {
     $impl = new absolute_path();
     $re_result = h\regex_execute(RE_PATH, $meat);
     if (!$re_result->is_match()) {
         throw $this->_exception('The provided string doesn\'t match an absolute path');
     }
     $match_boundaries = $re_result->iterate_matches()[0];
     $path = $meat->behead($match_boundaries->end);
     $impl->segments = $path->explode('/');
     return $impl;
 }