-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.php
33 lines (27 loc) · 810 Bytes
/
index.php
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
/**
* This is the Front Controller.
* The Front Controller decides which action to run.
*
* This particular Front Controller defines a route table, which says
* which defines which URLs map to which actions.
*
* @author Damien Walsh <[email protected]>
*/
require_once 'vendor/autoload.php';
// Define the routes table
$routes = array(
'/\/hello\/(.+)/' => array('HelloController', 'helloAction')
);
// Decide which route to run
foreach ($routes as $url => $action) {
// See if the route matches the current request
$matches = preg_match($url, $_SERVER['REQUEST_URI'], $params);
// If it matches...
if ($matches > 0) {
// Run this action, passing the parameters.
$controller = new $action[0];
$controller->{$action[1]}($params);
break;
}
}