1 | <?php |
||
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() { |
||
92 | |||
93 | /** |
||
94 | * Reference to short access core modules |
||
95 | */ |
||
96 | public function __get($name) { |
||
99 | |||
100 | /** |
||
101 | * Reference to short access core modules |
||
102 | */ |
||
103 | public function __call($name, $params) { |
||
106 | |||
107 | /** |
||
108 | * Check access to controller method |
||
109 | * |
||
110 | * @return boolean |
||
111 | */ |
||
112 | public function checkAccess() { |
||
118 | |||
119 | } |
||
120 |