1 | <?php |
||
11 | class Controller |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | private $container; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $data; |
||
22 | |||
23 | /** |
||
24 | * Constructor. |
||
25 | * |
||
26 | * @param array $container |
||
27 | */ |
||
28 | public function __construct(array $container) |
||
32 | |||
33 | /** |
||
34 | * @param string $name Item name |
||
35 | * |
||
36 | * @return mixed Item from container |
||
37 | */ |
||
38 | public function get($name) |
||
44 | |||
45 | /** |
||
46 | * @param string $name Config name |
||
47 | * |
||
48 | * @return mixed Config value |
||
49 | */ |
||
50 | public function config($name) |
||
56 | |||
57 | /** |
||
58 | * Get request variable. |
||
59 | * |
||
60 | * @param string $type Request type |
||
61 | * @param string $name Index name. Null for all |
||
62 | * |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function getFromRequest($type = 'get', $name = null) |
||
83 | |||
84 | /** |
||
85 | * @return string |
||
86 | */ |
||
87 | public function dir() |
||
91 | |||
92 | /** |
||
93 | * Check is user logged. |
||
94 | * |
||
95 | * @return bool Return true, if logged |
||
96 | */ |
||
97 | public function isLogged() |
||
101 | |||
102 | /** |
||
103 | * @param string $type Message type |
||
104 | * @param mixed $message Message content |
||
105 | * |
||
106 | * @return void |
||
107 | */ |
||
108 | public function setMessage($type = 'success', $message = 'Success') |
||
109 | { |
||
110 | switch ($type) { |
||
111 | case 'success': |
||
112 | $this->get('flash')->success($message); |
||
113 | break; |
||
114 | case 'info': |
||
115 | $this->get('flash')->info($message); |
||
116 | break; |
||
117 | case 'warning': |
||
118 | $this->get('flash')->warning($message); |
||
119 | break; |
||
120 | case 'error': |
||
121 | $this->get('flash')->error($message); |
||
122 | break; |
||
123 | |||
124 | default: |
||
125 | $this->get('flash')->error($message); |
||
126 | break; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Redirect. |
||
132 | * |
||
133 | * @param string $path Path to redirect |
||
134 | * |
||
135 | * @return void |
||
136 | */ |
||
137 | public function redirect($path) |
||
138 | { |
||
139 | header('Location: '.$this->dir().$path); |
||
140 | } |
||
141 | |||
142 | public function terminate($code = 1) |
||
143 | { |
||
144 | exit($code); |
||
|
|||
145 | } |
||
146 | |||
147 | private function selectMessagesTemplate() |
||
155 | |||
156 | /** |
||
157 | * @param string $template Template name |
||
158 | * @param array $data Data to use in template |
||
159 | */ |
||
160 | public function render($template, $data = []) |
||
194 | } |
||
195 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.