|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Controller |
|
5
|
|
|
* |
|
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
|
7
|
|
|
* @link http://inji.ru/ |
|
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
|
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
|
10
|
|
|
*/ |
|
11
|
|
|
class Controller { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Storage of cur requested controller |
|
15
|
|
|
* |
|
16
|
|
|
* @var Controller |
|
17
|
|
|
*/ |
|
18
|
|
|
public static $cur = null; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Requested params for method |
|
22
|
|
|
* |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
public $params = []; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Path to controller dir |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
public $path = ''; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Requested action name |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
public $method = 'index'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Module of this controller |
|
43
|
|
|
* |
|
44
|
|
|
* @var Module |
|
45
|
|
|
*/ |
|
46
|
|
|
public $module = null; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* This controller name |
|
50
|
|
|
* |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
public $name = ''; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Flag of controller runing |
|
57
|
|
|
* |
|
58
|
|
|
* @var boolean |
|
59
|
|
|
*/ |
|
60
|
|
|
public $run = false; |
|
61
|
|
|
|
|
62
|
|
|
public $methodResolved = false; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Run controller |
|
66
|
|
|
*/ |
|
67
|
|
|
public function run() { |
|
68
|
|
|
!$this->methodResolved && $this->resolveMethod(); |
|
69
|
|
|
if (!method_exists($this, $this->method . 'Action')) { |
|
70
|
|
|
INJI_SYSTEM_ERROR('method not found', true); |
|
71
|
|
|
} |
|
72
|
|
|
if (!$this->checkAccess()) { |
|
73
|
|
|
$msg = !empty($this->module->app->access->config['access']['accessTree'][App::$cur->type]['msg']) ? $this->module->app->access->config['access']['accessTree'][App::$cur->type]['msg'] : 'У вас нет прав доступа'; |
|
74
|
|
|
Tools::redirect($this->access->getDeniedRedirect(), $msg); |
|
75
|
|
|
} |
|
76
|
|
|
$this->run = true; |
|
77
|
|
|
call_user_func_array([$this, $this->method . 'Action'], $this->params); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function resolveMethod() { |
|
81
|
|
|
if ($this->methodResolved) { |
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
if (!empty($this->params[0]) && method_exists($this, $this->params[0] . 'Action')) { |
|
85
|
|
|
$this->method = $this->params[0]; |
|
86
|
|
|
$this->params = array_slice($this->params, 1); |
|
87
|
|
|
$this->methodResolved = true; |
|
88
|
|
|
return true; |
|
89
|
|
|
} |
|
90
|
|
|
return false; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Reference to short access core modules |
|
95
|
|
|
*/ |
|
96
|
|
|
public function __get($name) { |
|
97
|
|
|
return App::$cur->__get($name); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Reference to short access core modules |
|
102
|
|
|
*/ |
|
103
|
|
|
public function __call($name, $params) { |
|
104
|
|
|
return App::$cur->__call($name, $params); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Check access to controller method |
|
109
|
|
|
* |
|
110
|
|
|
* @return boolean |
|
111
|
|
|
*/ |
|
112
|
|
|
public function checkAccess() { |
|
113
|
|
|
if ($this->module->app->access) { |
|
114
|
|
|
return $this->module->app->access->checkAccess($this); |
|
115
|
|
|
} |
|
116
|
|
|
return true; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|