diff --git a/~dev_rating/application/classes/Controller/Handler.php b/~dev_rating/application/classes/Controller/Handler.php index f39efc26e2abf71f03eb410c5bd517bea8c991c0..75f4b38ae10b17224beb0bcce6002932c9b41d43 100644 --- a/~dev_rating/application/classes/Controller/Handler.php +++ b/~dev_rating/application/classes/Controller/Handler.php @@ -16,4 +16,17 @@ class Controller_Handler extends Controller $this->post = Validation::factory(Arr::map('trim', $_POST)); $this->get = Validation::factory(Arr::map('trim', $_GET)); } + + public function execute() { + $res = parent::execute(); + + if (empty($res->body())) + $res->body(json_encode([])); + + return $res; + } + + protected function fail() { + throw HTTP_Exception::factory(422)->request($this->request); + } } diff --git a/~dev_rating/system/classes/HTTP/Exception/422.php b/~dev_rating/system/classes/HTTP/Exception/422.php new file mode 100644 index 0000000000000000000000000000000000000000..3aa67f080f6d9f17d3e017b2daa587c089c43840 --- /dev/null +++ b/~dev_rating/system/classes/HTTP/Exception/422.php @@ -0,0 +1,3 @@ +<?php defined('SYSPATH') OR die('No direct script access.'); + +class HTTP_Exception_422 extends Kohana_HTTP_Exception_422 {} diff --git a/~dev_rating/system/classes/Kohana/HTTP/Exception/422.php b/~dev_rating/system/classes/Kohana/HTTP/Exception/422.php new file mode 100644 index 0000000000000000000000000000000000000000..a599b104d6fe9d145fe3108b89f6c740f877bb3f --- /dev/null +++ b/~dev_rating/system/classes/Kohana/HTTP/Exception/422.php @@ -0,0 +1,36 @@ +<?php defined('SYSPATH') OR die('No direct script access.'); + +class Kohana_HTTP_Exception_422 extends HTTP_Exception_Expected +{ + /** @var int Unprocessable Entity */ + protected $_code = 422; + + /** + * Specifies the list of allowed HTTP methods + * + * @param array $methods List of allowed methods + * @return $this + */ + public function allowed($methods) { + if (is_array($methods)) { + $methods = implode(',', $methods); + } + + $this->headers('allow', $methods); + + return $this; + } + + /** + * Validate this exception contains everything needed to continue. + * + * @throws Kohana_Exception + * @return bool + */ + public function check() { +// if ($location = $this->headers('allow') === null) +// throw new Kohana_Exception('A list of allowed methods must be specified'); + + return true; + } +} diff --git a/~dev_rating/system/classes/Kohana/Response.php b/~dev_rating/system/classes/Kohana/Response.php index 68699791573c124e7e94ac01dfe001faa93fc7a3..67abf2d7aaf5c7b83b014f363b24b5f8c0d3043c 100644 --- a/~dev_rating/system/classes/Kohana/Response.php +++ b/~dev_rating/system/classes/Kohana/Response.php @@ -75,6 +75,7 @@ class Kohana_Response implements HTTP_Response { 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', // Server Error 5xx 500 => 'Internal Server Error',