resource_type == null) { throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE"); } // @todo this needs security checks $resource = ORM::factory($this->resource_type, $id); if (!$resource->loaded) { return Kohana::show_404(); } /** * We're expecting to run in an environment that only supports GET/POST, so expect to tunnel * PUT/DELETE through POST. */ $output_format = $this->input->get("_format", $this->input->post("_format", "html")); if (request::method() == "get") { $this->_get($resource, $output_format); if (Session::instance()->get("use_profiler", false)) { $profiler = new Profiler(); $profiler->render(); } return; } switch ($this->input->post("_method", $this->input->get("_method"))) { case "put": return $this->_put($resource); case "delete": return $this->_delete($resource); default: return $this->_post($resource); } } public function form($id) { if ($this->resource_type == null) { throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE"); } // @todo this needs security checks $resource = ORM::factory($this->resource_type, $id); if (!$resource->loaded) { return Kohana::show_404(); } return $this->_form($resource); } /** * Perform a GET request on this resource * @param ORM $resource the instance of this resource type */ abstract public function _get($resource, $output_format); /** * Perform a PUT request on this resource * @param ORM $resource the instance of this resource type */ abstract public function _put($resource); /** * Perform a POST request on this resource * @param ORM $resource the instance of this resource type */ abstract public function _post($resource); /** * Perform a DELETE request on this resource * @param ORM $resource the instance of this resource type */ abstract public function _delete($resource); /** * Present a form for adding a new resource * @param ORM $resource the resource container for instances of this resource type */ abstract public function _form($resource); }