]>
src.bluestatic.org Git - hoplite.git/blob - action.php
68a8788076dd21d890f32ac74aeb2109a8cae44f
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 Action
extends Middleware
{
26 public function beforeRequest() {}
28 public function afterRequest(Response
$response) {}
30 public function defaultRequest(Request
$request) {
31 return $this->next
->execute($request);
34 public function execute(Request
$request) {
35 $this->request
= $request;
37 $this->beforeRequest();
39 $action = @$request->context
[Router
::class]['data']['action'];
40 if (!$action || !method_exists($this, $action)) {
41 return $this->defaultRequest($request);
44 $response = $this->{$action
}();
46 $this->afterRequest($response);