]>
src.bluestatic.org Git - hoplite.git/blob - router.php
d991add195e2f9e6834303d8deb019cdf8ac34c3
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/pipeline.php';
21 require_once HOPLITE_ROOT
. '/http2/route_map.php';
24 The Router is a middleware that operates on a RouteMap object. If a Request
25 matches, the value in the RouteMap is treated as a Middleware to be built by
26 Pipeline::buildMiddleware().
28 If the secondary Pipeline Router::subpipe is provided, the matched value will
29 be treated as if it were Pipeline::add()ed immediately before being built.
30 This allows additional middleware to execute IFF a route match occurs.
32 If no route mach is made, then the Router runs the next middleware.
34 class Router
extends Middleware
{
38 public function __construct(Pipeline
$pipeline,
41 Pipeline
$subpipe=NULL) {
42 parent
::__construct($pipeline, $next);
44 $this->subpipe
= $subpipe ? $subpipe : new Pipeline();
47 public function execute(Request
$request) {
48 // The query rewriter module of the webserver rewrites a request from:
49 // http://example.com/webapp/user/view/42
51 // http://example.com/webapp/index.php/user/view/42
52 // ... which then becomes accessible from PATH_INFO.
53 if (isset($_SERVER['PATH_INFO']))
54 $url = $_SERVER['PATH_INFO'];
58 $url = substr($url, 1);
61 $route_result = $this->map
->match($request);
64 $request->context
[self
::class] = $route_result;
65 $next = $this->subpipe
->buildWithTail($route_result['result']);
66 return $next->execute($request);
69 return $this->next
->execute($request);