here is my front.php file.
Code: Select all
1<?php
2final class Front {
3 protected $registry;
4 protected $pre_action = array();
5 protected $error;
6
7 public function __construct($registry) {
8 $this->registry = $registry;
9 }
10
11 public function addPreAction($pre_action) {
12 $this->pre_action[] = $pre_action;
13 }
14
15 public function dispatch($action, $error) {
16 $this->error = $error;
17
18 foreach ($this->pre_action as $pre_action) {
19 $result = $this->execute($pre_action);
20
21 if ($result) {
22 $action = $result;
23
24 break;
25 }
26 }
27
28 while ($action) {
29 $action = $this->execute($action);
30 }
31 }
32
33 private function execute($action) {
34 $file = $action->getFile();
35 $class = $action->getClass();
36 $method = $action->getMethod();
37 $args = $action->getArgs();
38
39 $action = '';
40
41 if (file_exists($file)) {
42 require_once($file);
43
44 $controller = new $class($this->registry);
45
46 if (is_callable(array($controller, $method))) {
47 $action = call_user_func_array(array($controller, $method), $args);
48 } else {
49 $action = $this->error;
50
51 $this->error = '';
52 }
53 } else {
54 $action = $this->error;
55
56 $this->error = '';
57 }
58
59 return $action;
60 }
61}
62?>