-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
33 lines (29 loc) · 780 Bytes
/
index.php
File metadata and controls
33 lines (29 loc) · 780 Bytes
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
<?php
class App {
/**
* Register route with HTTP method (get, post, put, patch, delete)
*
* @param string $method Name of the HTTP method
* @param $action URL and Callback
* @return App $this
*/
function __call($method, $action) {
$this->{$method.$action[0]} = $action[1];
return $this;
}
/**
* Execute action based on the user request
*
* @return Execution of the registred Callback
*/
function run() {
foreach($this as $request => $action)
if(preg_match("@$request@i", "$_SERVER[REQUEST_METHOD]$_SERVER[REQUEST_URI]", $p))
return $action($this, $p);
}
}
(new App)
->get('/home', function() {
echo '<h1>home</h1>';
})
->run();