Middleware no longer takes a Pipeline.
[hoplite.git] / http2 / middleware.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2016 Blue Static
4 //
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.
8 //
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
12 // more details.
13 //
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/>.
16
17 namespace hoplite\http2;
18
19 require_once HOPLITE_ROOT . '/http2/pipeline.php';
20 require_once HOPLITE_ROOT . '/http2/request.php';
21 require_once HOPLITE_ROOT . '/http2/response.php';
22
23 abstract class Middleware {
24 protected $next;
25
26 public function __construct(Middleware $next) {
27 $this->next = $next;
28 }
29
30 public abstract /*http\Response*/ function execute(Request $request);
31 }
32
33 class Sentinel extends Middleware {
34 private $response;
35
36 public function __construct(Response $response) {
37 $this->response = $response;
38 }
39
40 public function execute(Request $request) {
41 return $this->response;
42 }
43 }
44
45 class ClosureMiddleware extends Middleware {
46 private $closure;
47
48 public function __construct(Middleware $next,
49 \Closure $closure) {
50 parent::__construct($next);
51 $this->closure = $closure;
52 }
53
54 public function execute(Request $request) {
55 $closure = $this->closure;
56 return $closure($request, $this->next);
57 }
58 }