]>
src.bluestatic.org Git - hoplite.git/blob - api.php
0a901acb39bde1b033717732ae447bcc9badd16e
3 // Copyright (c) 2016 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite\http2
;
19 require_once HOPLITE_ROOT
. '/http2/middleware.php';
20 require_once HOPLITE_ROOT
. '/http2/request.php';
21 require_once HOPLITE_ROOT
. '/http2/response.php';
23 class DataResponse
extends Response
{
26 public function __construct($data) {
27 parent
::__construct();
31 public function generate() {
32 throw new \
Exception(__CLASS__
. ' cannot generate a response');
36 class JsonResponse
extends Response
{
39 public function __construct(DataResponse
$r) {
40 $this->code
= $r->code
;
41 $this->data
= $r->data
;
44 public function generate() {
45 $this->headers
['Content-Type'] = 'application/json';
47 print json_encode($this->data
);
51 class JsonResponseFilter
extends Middleware
{
52 public function execute(Request
$request) {
53 $response = $this->next
->execute($request);
55 if ($response instanceof DataResponse
) {
56 return new JsonResponse($response);