From f297b2306ec6e1472b0ffe724241052e6d7a3a62 Mon Sep 17 00:00:00 2001 From: Tim Strijdhorst Date: Mon, 20 Mar 2017 18:09:10 +0100 Subject: [PATCH 1/3] +implement get_array for response object --- src/response.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/response.php b/src/response.php index f7871a7..6fddc83 100644 --- a/src/response.php +++ b/src/response.php @@ -87,6 +87,31 @@ public function __construct() { public function __toString() { return $this->get_json(); } + + /** + * generates an array for the whole response body + * + * @see jsonapi.org/format + * + * @return array, containing: + * - links + * - meta + */ + public function get_array() { + $response = array(); + + // links + if ($this->links) { + $response['links'] = $this->links; + } + + // meta data + if ($this->meta_data) { + $response['meta'] = $this->meta_data; + } + + return $response; + } /** * returns the whole response body as json From 5a5a993598e6884e51cc5d22a42cd78fe5a43262 Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Thu, 23 Mar 2017 12:34:55 +0100 Subject: [PATCH 2/3] CS indent, no functional changes --- src/response.php | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/response.php b/src/response.php index 6fddc83..6e07b8f 100644 --- a/src/response.php +++ b/src/response.php @@ -87,31 +87,31 @@ public function __construct() { public function __toString() { return $this->get_json(); } + +/** + * generates an array for the whole response body + * + * @see jsonapi.org/format + * + * @return array, containing: + * - links + * - meta + */ +public function get_array() { + $response = array(); - /** - * generates an array for the whole response body - * - * @see jsonapi.org/format - * - * @return array, containing: - * - links - * - meta - */ - public function get_array() { - $response = array(); - - // links - if ($this->links) { - $response['links'] = $this->links; - } - - // meta data - if ($this->meta_data) { - $response['meta'] = $this->meta_data; - } - - return $response; + // links + if ($this->links) { + $response['links'] = $this->links; + } + + // meta data + if ($this->meta_data) { + $response['meta'] = $this->meta_data; } + + return $response; +} /** * returns the whole response body as json From 29692cfeba79703ac3c00bc7fe71c2a82b90eec7 Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Thu, 23 Mar 2017 12:48:05 +0100 Subject: [PATCH 3/3] document the new use-case --- examples/index.html | 5 +++++ examples/meta_only.php | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 examples/meta_only.php diff --git a/examples/index.html b/examples/index.html index d4f5a73..7ee8985 100644 --- a/examples/index.html +++ b/examples/index.html @@ -33,6 +33,11 @@

Errors

  • All options
  • +

    Misc

    + + diff --git a/examples/meta_only.php b/examples/meta_only.php new file mode 100644 index 0000000..66544fb --- /dev/null +++ b/examples/meta_only.php @@ -0,0 +1,24 @@ +add_meta('foo', 'bar'); + +/** + * sending the response + */ + +$jsonapi->send_response();