This repository was archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
56 lines (47 loc) · 1.22 KB
/
index.php
File metadata and controls
56 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* This is an example file.
* This file shows how you can start
* your project using the router module.
*
* I call this file a `base file` because
* all the request to the server is being handled
* by this.
*
* check .htaccess' RewriteRule
*/
# Require the router into your base file
require_once __DIR__ . '/.router/mod.php';
# Make a router\Router instance
$router = new Router\Router();
/**
* serve a static directory
*
* @param string $path
* @param string $prefix = '/'
*
* $router->serve(__DIR__ . '/public', '/static');
*/
# chaining is available
$router
# homepage
->get('/', function ($request, $response) {
$response->html(
'<h1>Router is running!</h1>' .
'<br>' .
'<a href="' .$request->baseURL. 'request/param_value?data1=value1&data2=value2">view request object</a>'
);
})
# middleware
->apply(function ($request, $response, $next) {
$request->customProperty = 'some value';
$response->removeHeader('X-Powered-By');
$next(); # <- this is required to proceed, unless it will response a timeout
})
# request route
->get('/request/:example', function ($request, $response) {
var_dump($request);
exit;
})
# activate $router
->activate();