-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppController.php
66 lines (55 loc) · 1.53 KB
/
AppController.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
66
<?php
/**
* Date: 13-9-23
* Time: 下午6:04
* Todo: AOP
*/
class AppController {
private $before_filter = array();
private $after_filter = array();
protected function before_filter($filter, $condition = array())
{
$this->set_filter("before_filter", $filter, $condition);
}
protected function after_filter($filter, $condition = array())
{
$this->set_filter("after_filter", $filter, $condition);
}
private function set_filter($var, $filter, $condition)
{
if (!is_callable(array($this, $filter)))
{
throw new BizException(ErrorInfo::$no_filter);
}
$this->{$var}[$filter] = $condition;
}
private function check_filter($method, $condition)
{
return in_array($method, $condition);
}
public function run($method)
{
if(!is_callable(array($this, $method)))
{
throw new BizException(ErrorInfo::$no_method);
}
// 校验前置过滤
foreach($this->before_filter as $filter=> $condition )
{
if (!$this->check_filter($method, $condition))
{
continue;
}
$this->$filter();
}
$this->$method();
foreach($this->after_filter as $filter => $condition)
{
if (!$this->check_filter($method, $condition))
{
continue;
}
$this->$filter();
}
}
}