From db1e1549201570721712602d5d767439b6aaba7b Mon Sep 17 00:00:00 2001 From: whatever22 Date: Fri, 9 Mar 2018 16:21:45 +0100 Subject: [PATCH] Added PATCH verb/method + refactoring (extracted service interface + abstracted BaseRestServiceTB.php verb methods) (#1) --- BaseRestServiceTB.php | 54 ++++++++++++++++++++++++++++++++++++++++--- RestServiceTB.php | 10 ++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 RestServiceTB.php diff --git a/BaseRestServiceTB.php b/BaseRestServiceTB.php index 8d83ba6..8287049 100644 --- a/BaseRestServiceTB.php +++ b/BaseRestServiceTB.php @@ -1,11 +1,13 @@ init(); } + /** + * Responds to an HTTP request issued with the GET method/verb. + * Returns the JSON representation of a single resource (or of all resources) + * depending on wether the resource ID is provided in the URL path (or not). + */ + abstract protected function get(); + + /** + * Responds to an HTTP request issued with the POST method/verb. + * Creates a new resource built using the POST parameters passed. + */ + abstract protected function post(); + + /** + * Responds to an HTTP request issued with the PUT method/verb. + * Updates all parameters of the resource identified by the ID provided in + * the URL path if it exists (using the parameters passed). Responds with a + * 404 HTTP response if not. + */ + abstract protected function put(); + + /** + * Responds to an HTTP request issued with the PATCH method/verb. + * Updates parts of the parameters of the resource identified by the ID + * provided in the URL path if it exists (using the parameters passed). + * Responds with a 404 HTTP response if not. + */ + abstract protected function patch(); + + /** + * Responds to an HTTP request issued with the DELETE method/verb. + * Removes the resource identified by the ID provided in the URL path if it + * exists. Responds with a 404 HTTP response if not. + */ + abstract protected function delete(); + + /** + * Responds to an HTTP request issued with the OPTIONS method/verb. + * Responds with a 200 status with an 'Allow' header listing the HTTP methods + * that may be used on this resource. + */ + abstract protected function options(); + /** Post-constructor adjustments */ protected function init() { } @@ -75,6 +120,9 @@ public function run() { case "PUT": $this->put(); break; + case "PATCH": + $this->patch(); + break; case "DELETE": $this->delete(); break; @@ -166,7 +214,7 @@ protected function getParam($name, $default=null, $collection=null) { return $default; } } - + /** * Reads and returns request body contents */ diff --git a/RestServiceTB.php b/RestServiceTB.php new file mode 100644 index 0000000..e1492a5 --- /dev/null +++ b/RestServiceTB.php @@ -0,0 +1,10 @@ +