Esempio n. 1
0
 protected function do_before(context $ctx)
 {
     $ctx->results = h\collection();
     $interfaces = array('GET' => '\\horn\\lib\\http_get', 'POST' => '\\horn\\lib\\http_post', 'PUT' => '\\horn\\lib\\http_put', 'DELETE' => '\\horn\\lib\\http_delete');
     $http_method = $ctx->in->method;
     if (!isset($interfaces[$http_method])) {
         h\http\response_methods::method_not_allowed($ctx->out);
         $msg = sprintf('Non-supported method \'%s\' on \'%s\'', $http_method, $ctx->in->uri);
         $ctx->error_handling['status'] = false;
         $ctx->error_handling['messages'][] = $msg;
         return false;
     }
     $controller_class = $this->configuration['routes'][$ctx->route];
     if (!class_exists($controller_class)) {
         $msg = sprintf('Undefined controller class \'%s\'', $controller_class);
         $ctx->error_handling['status'] = false;
         $ctx->error_handling['messages'][] = $msg;
         return false;
     }
     $ctrl = new $controller_class($ctx);
     if (!$ctrl instanceof $interfaces[$http_method]) {
         h\http\response_methods::method_not_allowed($ctx->out);
         $msg = sprintf('Non-supported method \'%s\' on \'%s\'', $http_method, $ctx->in->uri);
         $ctx->error_handling['status'] = false;
         $ctx->error_handling['messages'][] = $msg;
         return false;
     }
     try {
         $result = $ctrl->{"do_{$http_method}"}();
     } catch (h\http\error $e) {
         $error = get_class($e);
         $error = substr($error, 1 + strrpos($error, '\\'));
         h\http\response_methods::$error($ctx->out);
         $result = array(false, null, array($e->getMessage()));
     }
     $ctx->error_handling['status'] = $result[0];
     isset($result[1]) and $ctx->results->join($result[1]);
     isset($result[2]) and $ctx->error_handling['messages']->join($result[2]);
     return true;
 }
Esempio n. 2
0
 public function redirect_to_updated($to)
 {
     h\http\response_methods::ok($this->context->out);
     $this->location($to);
 }