-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
67 lines (50 loc) · 1.67 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Basic front controller
*/
namespace App;
use App\Controller\ListActionController;
use App\Controller\AddActionController;
use App\Controller\CompleteActionController;
use App\Controller\ActivateActionController;
class App {
private $action;
private $params;
static private $validActions = array('add', 'list', 'complete', 'activate');
public function __construct($params) {
if (!isset($params['action'])) {
$params['action'] = 'list';
}
if (!in_array($params['action'], self::$validActions)) {
throw new \InvalidArgumentException('Unrecognized action');
}
$this->params = $params;
$this->action = trim($this->params['action']);
}
/**
* Basic routing
*/
public function execute() {
switch ($this->action) {
case 'add':
require_once 'Controller/AddActionController.php';
$controller = new AddActionController($this->params);
break;
case 'list':
require_once 'Controller/ListActionController.php';
$controller = new ListActionController($this->params);
break;
case 'complete':
require_once 'Controller/CompleteActionController.php';
$controller = new CompleteActionController($this->params);
break;
case 'activate':
require_once 'Controller/ActivateActionController.php';
$controller = new ActivateActionController($this->params);
break;
}
$controller->run();
}
}
$app = new App($_GET);
$app->execute();