@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | { |
43 | 43 | $this->app = $app; |
44 | 44 | |
45 | - if (! $this->isConnected()) { |
|
45 | + if (!$this->isConnected()) { |
|
46 | 46 | $this->connect(); |
47 | 47 | } |
48 | 48 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | extract($data); |
60 | 60 | |
61 | 61 | try { |
62 | - static::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
62 | + static::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
63 | 63 | |
64 | 64 | static::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
65 | 65 | |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | |
95 | 95 | public function join($join, $localId = null, $forginId = null) |
96 | 96 | { |
97 | - if (! $localId) $localId = trim($join, 's' ). '_id'; |
|
97 | + if (!$localId) $localId = trim($join, 's') . '_id'; |
|
98 | 98 | |
99 | - if (! $forginId) $forginId = 'id'; |
|
99 | + if (!$forginId) $forginId = 'id'; |
|
100 | 100 | |
101 | 101 | $sql = $join . ' ON ' . $this->table . '.' . $localId . ' = ' . $join . '.' . $forginId; |
102 | 102 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | if ($this->orderBy) { |
220 | 220 | |
221 | - $sql .= ' ORDER BY ' . implode (' ', $this->orderBy); |
|
221 | + $sql .= ' ORDER BY ' . implode(' ', $this->orderBy); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | if ($this->limit) { |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | if ($this->groupBy) { |
235 | - $sql .= ' GROUP BY ' . implode(' ' , $this->groupBy); |
|
235 | + $sql .= ' GROUP BY ' . implode(' ', $this->groupBy); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | return $sql; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | { |
325 | 325 | $sql = ''; |
326 | 326 | |
327 | - foreach($this->data as $key => $value) { |
|
327 | + foreach ($this->data as $key => $value) { |
|
328 | 328 | |
329 | 329 | $sql .= '`' . $key . '` = ? ,'; |
330 | 330 | } |
@@ -94,9 +94,13 @@ discard block |
||
94 | 94 | |
95 | 95 | public function join($join, $localId = null, $forginId = null) |
96 | 96 | { |
97 | - if (! $localId) $localId = trim($join, 's' ). '_id'; |
|
97 | + if (! $localId) { |
|
98 | + $localId = trim($join, 's' ). '_id'; |
|
99 | + } |
|
98 | 100 | |
99 | - if (! $forginId) $forginId = 'id'; |
|
101 | + if (! $forginId) { |
|
102 | + $forginId = 'id'; |
|
103 | + } |
|
100 | 104 | |
101 | 105 | $sql = $join . ' ON ' . $this->table . '.' . $localId . ' = ' . $join . '.' . $forginId; |
102 | 106 | |
@@ -109,7 +113,9 @@ discard block |
||
109 | 113 | { |
110 | 114 | $sql = array_shift($bindings); |
111 | 115 | |
112 | - if (is_array($bindings[0])) $bindings = $bindings[0]; |
|
116 | + if (is_array($bindings[0])) { |
|
117 | + $bindings = $bindings[0]; |
|
118 | + } |
|
113 | 119 | |
114 | 120 | $this->addToBindings($bindings); |
115 | 121 |
@@ -8,92 +8,92 @@ discard block |
||
8 | 8 | |
9 | 9 | class Database |
10 | 10 | { |
11 | - private $app; |
|
11 | + private $app; |
|
12 | 12 | |
13 | - private static $connection; |
|
13 | + private static $connection; |
|
14 | 14 | |
15 | - private $table; |
|
15 | + private $table; |
|
16 | 16 | |
17 | - private $rows; |
|
17 | + private $rows; |
|
18 | 18 | |
19 | - private $lastId; |
|
19 | + private $lastId; |
|
20 | 20 | |
21 | - private $data = []; |
|
21 | + private $data = []; |
|
22 | 22 | |
23 | - private $bindings = []; |
|
23 | + private $bindings = []; |
|
24 | 24 | |
25 | - private $selects = []; |
|
25 | + private $selects = []; |
|
26 | 26 | |
27 | - private $joins = []; |
|
27 | + private $joins = []; |
|
28 | 28 | |
29 | - private $wheres = []; |
|
29 | + private $wheres = []; |
|
30 | 30 | |
31 | - private $havings = []; |
|
31 | + private $havings = []; |
|
32 | 32 | |
33 | - private $orderBy = []; |
|
33 | + private $orderBy = []; |
|
34 | 34 | |
35 | - private $limit; |
|
35 | + private $limit; |
|
36 | 36 | |
37 | - private $offset; |
|
37 | + private $offset; |
|
38 | 38 | |
39 | - private $groupBy = []; |
|
39 | + private $groupBy = []; |
|
40 | 40 | |
41 | - public function __construct(Application $app) |
|
42 | - { |
|
41 | + public function __construct(Application $app) |
|
42 | + { |
|
43 | 43 | $this->app = $app; |
44 | 44 | |
45 | 45 | if (! $this->isConnected()) { |
46 | - $this->connect(); |
|
46 | + $this->connect(); |
|
47 | + } |
|
47 | 48 | } |
48 | - } |
|
49 | 49 | |
50 | - private function isConnected() |
|
51 | - { |
|
50 | + private function isConnected() |
|
51 | + { |
|
52 | 52 | return static::$connection instanceof PDO; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - private function connect() |
|
56 | - { |
|
55 | + private function connect() |
|
56 | + { |
|
57 | 57 | $data = $this->app->config['db']; |
58 | 58 | |
59 | 59 | extract($data); |
60 | 60 | |
61 | 61 | try { |
62 | - static::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
62 | + static::$connection = new PDO('mysql:host=' . $server . ';dbname=' . $dbname, $dbuser, $dbpass); |
|
63 | 63 | |
64 | - static::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
64 | + static::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
65 | 65 | |
66 | - static::$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
|
66 | + static::$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
|
67 | 67 | |
68 | - static::$connection->exec('SET NAMES utf8'); |
|
68 | + static::$connection->exec('SET NAMES utf8'); |
|
69 | 69 | |
70 | 70 | } catch (PDOException $e) { |
71 | 71 | |
72 | - throw new Exception($e->getMessage()); |
|
72 | + throw new Exception($e->getMessage()); |
|
73 | + } |
|
73 | 74 | } |
74 | - } |
|
75 | 75 | |
76 | - public function connection() |
|
77 | - { |
|
76 | + public function connection() |
|
77 | + { |
|
78 | 78 | return static::$connection; |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - public function table($table) |
|
82 | - { |
|
81 | + public function table($table) |
|
82 | + { |
|
83 | 83 | $this->table = $table; |
84 | 84 | |
85 | 85 | return $this; |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - public function select(...$select) |
|
89 | - { |
|
88 | + public function select(...$select) |
|
89 | + { |
|
90 | 90 | $this->selects = array_merge($this->selects, $select); |
91 | 91 | |
92 | 92 | return $this; |
93 | - } |
|
93 | + } |
|
94 | 94 | |
95 | - public function join($join, $localId = null, $forginId = null) |
|
96 | - { |
|
95 | + public function join($join, $localId = null, $forginId = null) |
|
96 | + { |
|
97 | 97 | if (! $localId) $localId = trim($join, 's' ). '_id'; |
98 | 98 | |
99 | 99 | if (! $forginId) $forginId = 'id'; |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | $this->joins[] = $sql; |
104 | 104 | |
105 | 105 | return $this; |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - public function where(...$bindings) |
|
109 | - { |
|
108 | + public function where(...$bindings) |
|
109 | + { |
|
110 | 110 | $sql = array_shift($bindings); |
111 | 111 | |
112 | 112 | if (is_array($bindings[0])) $bindings = $bindings[0]; |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | $this->wheres[] = $sql; |
117 | 117 | |
118 | 118 | return $this; |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | - public function having() |
|
122 | - { |
|
121 | + public function having() |
|
122 | + { |
|
123 | 123 | $bindings = func_get_args(); |
124 | 124 | |
125 | 125 | $sql = array_shift($bindings); |
@@ -129,40 +129,40 @@ discard block |
||
129 | 129 | $this->havings[] = $sql; |
130 | 130 | |
131 | 131 | return $this; |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | - public function groupBy(...$arguments) |
|
135 | - { |
|
134 | + public function groupBy(...$arguments) |
|
135 | + { |
|
136 | 136 | $this->groupBy = $arguments; |
137 | 137 | |
138 | 138 | return $this; |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | - public function limit($limit, $offset = 0) |
|
142 | - { |
|
141 | + public function limit($limit, $offset = 0) |
|
142 | + { |
|
143 | 143 | $this->limit = $limit; |
144 | 144 | |
145 | 145 | $this->offset = $offset; |
146 | 146 | |
147 | 147 | return $this; |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - public function rows() |
|
151 | - { |
|
150 | + public function rows() |
|
151 | + { |
|
152 | 152 | return $this->rows; |
153 | - } |
|
153 | + } |
|
154 | 154 | |
155 | - public function orderBy($orderBy, $sort = 'ASC') |
|
156 | - { |
|
155 | + public function orderBy($orderBy, $sort = 'ASC') |
|
156 | + { |
|
157 | 157 | $this->orderBy = [$orderBy, $sort]; |
158 | 158 | |
159 | 159 | return $this; |
160 | - } |
|
160 | + } |
|
161 | 161 | |
162 | - public function fetch($table = null) |
|
163 | - { |
|
162 | + public function fetch($table = null) |
|
163 | + { |
|
164 | 164 | if ($table) { |
165 | - $this->table($table); |
|
165 | + $this->table($table); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $sql = $this->fetchStatment(); |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | $this->rows = $query->rowCount(); |
175 | 175 | |
176 | 176 | return $result; |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - public function fetchAll($table = null) |
|
180 | - { |
|
179 | + public function fetchAll($table = null) |
|
180 | + { |
|
181 | 181 | if ($table) { |
182 | - $this->table($table); |
|
182 | + $this->table($table); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | $sql = $this->fetchStatment(); |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | $this->rows = $query->rowCount(); |
192 | 192 | |
193 | 193 | return $results; |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - private function fetchStatment() |
|
197 | - { |
|
196 | + private function fetchStatment() |
|
197 | + { |
|
198 | 198 | $sql = 'SELECT '; |
199 | 199 | |
200 | 200 | $sql .= $this->selects ? implode(', ', $this->selects) : '*'; |
@@ -203,74 +203,74 @@ discard block |
||
203 | 203 | |
204 | 204 | if ($this->joins) { |
205 | 205 | |
206 | - $sql .= 'LEFT JOIN ' . implode(' ', $this->joins); |
|
206 | + $sql .= 'LEFT JOIN ' . implode(' ', $this->joins); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | if ($this->wheres) { |
210 | 210 | |
211 | - $sql .= ' WHERE ' . implode(' ', $this->wheres); |
|
211 | + $sql .= ' WHERE ' . implode(' ', $this->wheres); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | if ($this->havings) { |
215 | 215 | |
216 | - $sql .= ' HAVING ' . implode(' ', $this->havings) . ' '; |
|
216 | + $sql .= ' HAVING ' . implode(' ', $this->havings) . ' '; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | if ($this->orderBy) { |
220 | 220 | |
221 | - $sql .= ' ORDER BY ' . implode (' ', $this->orderBy); |
|
221 | + $sql .= ' ORDER BY ' . implode (' ', $this->orderBy); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | if ($this->limit) { |
225 | 225 | |
226 | - $sql .= ' LIMIT ' . $this->limit; |
|
226 | + $sql .= ' LIMIT ' . $this->limit; |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | if ($this->offset) { |
230 | 230 | |
231 | - $sql .= ' OFFSET ' . $this->offset; |
|
231 | + $sql .= ' OFFSET ' . $this->offset; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | if ($this->groupBy) { |
235 | - $sql .= ' GROUP BY ' . implode(' ' , $this->groupBy); |
|
235 | + $sql .= ' GROUP BY ' . implode(' ' , $this->groupBy); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | return $sql; |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | - public function lastId() |
|
242 | - { |
|
241 | + public function lastId() |
|
242 | + { |
|
243 | 243 | return $this->lastId; |
244 | - } |
|
244 | + } |
|
245 | 245 | |
246 | - public function from($table) |
|
247 | - { |
|
246 | + public function from($table) |
|
247 | + { |
|
248 | 248 | return $this->table($table); |
249 | - } |
|
249 | + } |
|
250 | 250 | |
251 | - public function data($key, $value = null) |
|
252 | - { |
|
251 | + public function data($key, $value = null) |
|
252 | + { |
|
253 | 253 | if (is_array($key)) { |
254 | 254 | |
255 | - $this->data = array_merge($this->data, $key); |
|
255 | + $this->data = array_merge($this->data, $key); |
|
256 | 256 | |
257 | - $this->addToBindings($key); |
|
257 | + $this->addToBindings($key); |
|
258 | 258 | |
259 | 259 | } else { |
260 | 260 | |
261 | - $this->data[$key] = $value; |
|
261 | + $this->data[$key] = $value; |
|
262 | 262 | |
263 | - $this->addToBindings($value); |
|
263 | + $this->addToBindings($value); |
|
264 | 264 | |
265 | 265 | } |
266 | 266 | |
267 | 267 | return $this; |
268 | - } |
|
268 | + } |
|
269 | 269 | |
270 | - public function insert($table = null) |
|
271 | - { |
|
270 | + public function insert($table = null) |
|
271 | + { |
|
272 | 272 | if ($table) { |
273 | - $this->table($table); |
|
273 | + $this->table($table); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | $sql = 'INSERT INTO ' . $this->table . ' SET '; |
@@ -282,12 +282,12 @@ discard block |
||
282 | 282 | $this->lastId = $this->connection()->lastInsertId(); |
283 | 283 | |
284 | 284 | return $this; |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | - public function update($table = null) |
|
288 | - { |
|
287 | + public function update($table = null) |
|
288 | + { |
|
289 | 289 | if ($table) { |
290 | - $this->table($table); |
|
290 | + $this->table($table); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | $sql = 'UPDATE ' . $this->table . ' SET '; |
@@ -295,69 +295,69 @@ discard block |
||
295 | 295 | $sql .= $this->setField(); |
296 | 296 | |
297 | 297 | if ($this->wheres) { |
298 | - $sql .= ' WHERE ' . implode('', $this->wheres); |
|
298 | + $sql .= ' WHERE ' . implode('', $this->wheres); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | $this->query($sql, $this->bindings); |
302 | 302 | |
303 | 303 | return $this; |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | - public function delete($table = null) |
|
307 | - { |
|
306 | + public function delete($table = null) |
|
307 | + { |
|
308 | 308 | if ($table) { |
309 | - $this->table($table); |
|
309 | + $this->table($table); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $sql = 'DELETE FROM ' . $this->table . ' '; |
313 | 313 | |
314 | 314 | if ($this->wheres) { |
315 | - $sql .= ' WHERE ' . implode('', $this->wheres); |
|
315 | + $sql .= ' WHERE ' . implode('', $this->wheres); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | $this->query($sql, $this->bindings); |
319 | 319 | |
320 | 320 | return $this; |
321 | - } |
|
321 | + } |
|
322 | 322 | |
323 | - private function setField() |
|
324 | - { |
|
323 | + private function setField() |
|
324 | + { |
|
325 | 325 | $sql = ''; |
326 | 326 | |
327 | 327 | foreach($this->data as $key => $value) { |
328 | 328 | |
329 | - $sql .= '`' . $key . '` = ? ,'; |
|
329 | + $sql .= '`' . $key . '` = ? ,'; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $sql = rtrim($sql, ' ,'); |
333 | 333 | |
334 | 334 | return $sql; |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - private function addToBindings($value) |
|
338 | - { |
|
337 | + private function addToBindings($value) |
|
338 | + { |
|
339 | 339 | if (is_array($value)) { |
340 | 340 | |
341 | - $this->bindings = array_merge($this->bindings, array_values($value)); |
|
341 | + $this->bindings = array_merge($this->bindings, array_values($value)); |
|
342 | 342 | } else { |
343 | 343 | |
344 | - $this->bindings[] = $value; |
|
344 | + $this->bindings[] = $value; |
|
345 | + } |
|
345 | 346 | } |
346 | - } |
|
347 | 347 | |
348 | - public function query(...$bindings) |
|
349 | - { |
|
348 | + public function query(...$bindings) |
|
349 | + { |
|
350 | 350 | $sql = array_shift($bindings); |
351 | 351 | |
352 | 352 | if (count($bindings) == 1 AND is_array($bindings[0])) { |
353 | - $bindings = $bindings[0]; |
|
353 | + $bindings = $bindings[0]; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | try { |
357 | 357 | $query = $this->connection()->prepare($sql); |
358 | 358 | |
359 | 359 | foreach ($bindings as $key => $value) { |
360 | - $query->bindValue($key + 1, _e($value)); |
|
360 | + $query->bindValue($key + 1, _e($value)); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | $query->execute(); |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | |
369 | 369 | } catch (PDOException $e) { |
370 | 370 | |
371 | - throw new Exception($e->getMessage()); |
|
371 | + throw new Exception($e->getMessage()); |
|
372 | + } |
|
372 | 373 | } |
373 | - } |
|
374 | 374 | |
375 | - private function reset() |
|
376 | - { |
|
375 | + private function reset() |
|
376 | + { |
|
377 | 377 | $this->table = null; |
378 | 378 | |
379 | 379 | $this->rows = 0; |
@@ -397,5 +397,5 @@ discard block |
||
397 | 397 | $this->offset = 0; |
398 | 398 | |
399 | 399 | $this->groupBy = []; |
400 | - } |
|
400 | + } |
|
401 | 401 | } |
402 | 402 | \ No newline at end of file |
@@ -4,28 +4,28 @@ |
||
4 | 4 | |
5 | 5 | class Url |
6 | 6 | { |
7 | - protected $app; |
|
7 | + protected $app; |
|
8 | 8 | |
9 | - public function __construct(Application $app) |
|
10 | - { |
|
9 | + public function __construct(Application $app) |
|
10 | + { |
|
11 | 11 | $this->app = $app; |
12 | - } |
|
12 | + } |
|
13 | 13 | |
14 | - public function link($path) |
|
15 | - { |
|
14 | + public function link($path) |
|
15 | + { |
|
16 | 16 | $link = $this->app->request->link(); |
17 | 17 | |
18 | 18 | $path = rtrim($path, '/'); |
19 | 19 | $path = ltrim($path, '/'); |
20 | 20 | |
21 | 21 | return $link . '/' . $path; |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function redirectTo($path, $num = 0) |
|
25 | - { |
|
24 | + public function redirectTo($path, $num = 0) |
|
25 | + { |
|
26 | 26 | if ($path == 'error') $this->app->session->set('error', true); |
27 | 27 | |
28 | 28 | header('Refresh: ' . $num . '; URL=' . $this->link($path)); |
29 | 29 | exit; |
30 | - } |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -23,7 +23,9 @@ |
||
23 | 23 | |
24 | 24 | public function redirectTo($path, $num = 0) |
25 | 25 | { |
26 | - if ($path == 'error') $this->app->session->set('error', true); |
|
26 | + if ($path == 'error') { |
|
27 | + $this->app->session->set('error', true); |
|
28 | + } |
|
27 | 29 | |
28 | 30 | header('Refresh: ' . $num . '; URL=' . $this->link($path)); |
29 | 31 | exit; |
@@ -3,75 +3,75 @@ discard block |
||
3 | 3 | use System\Application; |
4 | 4 | |
5 | 5 | if (! function_exists('pre')) { |
6 | - function pre($var) { |
|
6 | + function pre($var) { |
|
7 | 7 | echo '<pre>'; |
8 | 8 | print_r($var); |
9 | 9 | echo '</pre>'; |
10 | - } |
|
10 | + } |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | if (! function_exists('array_get')) { |
14 | - function array_get($array, $key, $default = null) |
|
15 | - { |
|
14 | + function array_get($array, $key, $default = null) |
|
15 | + { |
|
16 | 16 | return $array[$key] ?: $default; |
17 | - } |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | if (! function_exists('app')) { |
21 | - function app() |
|
22 | - { |
|
21 | + function app() |
|
22 | + { |
|
23 | 23 | return Application::getInstance(); |
24 | - } |
|
24 | + } |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | if (! function_exists('_e')) { |
28 | - function _e($value) |
|
29 | - { |
|
28 | + function _e($value) |
|
29 | + { |
|
30 | 30 | return htmlspecialchars($value); |
31 | - } |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | if (! function_exists('getLastIndex')) { |
35 | - function getLastIndex($index) |
|
36 | - { |
|
35 | + function getLastIndex($index) |
|
36 | + { |
|
37 | 37 | $array = explode('\\', $index); |
38 | 38 | return end($array); |
39 | - } |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | if (! function_exists('url')) { |
43 | - function url($path) { |
|
43 | + function url($path) { |
|
44 | 44 | $app = Application::getInstance(); |
45 | 45 | return $app->url->link($path); |
46 | - } |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | if (! function_exists('assets')) { |
50 | - function assets($path) |
|
51 | - { |
|
50 | + function assets($path) |
|
51 | + { |
|
52 | 52 | $app = Application::getInstance(); |
53 | 53 | return $app->url->link('public' . DS . $path); |
54 | - } |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | if (! function_exists('remove_space')) { |
58 | - function remove_space($str) { |
|
58 | + function remove_space($str) { |
|
59 | 59 | return str_replace(' ', '-', $str); |
60 | - } |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | if (! function_exists('remove_dash')) { |
64 | - function remove_dash($str) { |
|
64 | + function remove_dash($str) { |
|
65 | 65 | return str_replace('-', ' ', $str); |
66 | - } |
|
66 | + } |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | if (! function_exists('clean_name_url')) { |
70 | 70 | function clean_name_url($class = null) { |
71 | 71 | |
72 | - $app = Application::getInstance(); |
|
72 | + $app = Application::getInstance(); |
|
73 | 73 | |
74 | - if (! $class) { |
|
74 | + if (! $class) { |
|
75 | 75 | |
76 | 76 | $class = debug_backtrace()[1]['class']; |
77 | 77 | |
@@ -84,40 +84,40 @@ discard block |
||
84 | 84 | $class = strtolower($class); |
85 | 85 | |
86 | 86 | $class = '/' . $class . '/'; |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - $url = $app->request->url(); |
|
89 | + $url = $app->request->url(); |
|
90 | 90 | |
91 | - $name = str_replace($class, '', $url); |
|
91 | + $name = str_replace($class, '', $url); |
|
92 | 92 | |
93 | - $name = remove_dash($name); |
|
93 | + $name = remove_dash($name); |
|
94 | 94 | |
95 | - return $name; |
|
96 | - } |
|
95 | + return $name; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | if (! function_exists('text_char_limit')) { |
100 | - function text_char_limit($text, $limit) { |
|
100 | + function text_char_limit($text, $limit) { |
|
101 | 101 | if (strlen($text) > $limit) { |
102 | - return substr($text, 0, $limit) . '...'; |
|
102 | + return substr($text, 0, $limit) . '...'; |
|
103 | + } |
|
103 | 104 | } |
104 | - } |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | if (! function_exists('array_equal')) { |
108 | - function array_equal($a, $b) { |
|
108 | + function array_equal($a, $b) { |
|
109 | 109 | return ( |
110 | - is_array($a) |
|
110 | + is_array($a) |
|
111 | 111 | && is_array($b) |
112 | 112 | && count($a) == count($b) |
113 | 113 | && array_diff($a, $b) === array_diff($b, $a) |
114 | 114 | ); |
115 | - } |
|
115 | + } |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | if (! function_exists('redirect_after')) { |
119 | - function redirect_after($num) { |
|
119 | + function redirect_after($num) { |
|
120 | 120 | $app = Application::getInstance(); |
121 | 121 | $app->url->redirectTo('/', $num); |
122 | - } |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use System\Application; |
4 | 4 | |
5 | -if (! function_exists('pre')) { |
|
5 | +if (!function_exists('pre')) { |
|
6 | 6 | function pre($var) { |
7 | 7 | echo '<pre>'; |
8 | 8 | print_r($var); |
@@ -10,28 +10,28 @@ discard block |
||
10 | 10 | } |
11 | 11 | } |
12 | 12 | |
13 | -if (! function_exists('array_get')) { |
|
13 | +if (!function_exists('array_get')) { |
|
14 | 14 | function array_get($array, $key, $default = null) |
15 | 15 | { |
16 | 16 | return $array[$key] ?: $default; |
17 | 17 | } |
18 | 18 | } |
19 | 19 | |
20 | -if (! function_exists('app')) { |
|
20 | +if (!function_exists('app')) { |
|
21 | 21 | function app() |
22 | 22 | { |
23 | 23 | return Application::getInstance(); |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | -if (! function_exists('_e')) { |
|
27 | +if (!function_exists('_e')) { |
|
28 | 28 | function _e($value) |
29 | 29 | { |
30 | 30 | return htmlspecialchars($value); |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | -if (! function_exists('getLastIndex')) { |
|
34 | +if (!function_exists('getLastIndex')) { |
|
35 | 35 | function getLastIndex($index) |
36 | 36 | { |
37 | 37 | $array = explode('\\', $index); |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | -if (! function_exists('url')) { |
|
42 | +if (!function_exists('url')) { |
|
43 | 43 | function url($path) { |
44 | 44 | $app = Application::getInstance(); |
45 | 45 | return $app->url->link($path); |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | -if (! function_exists('assets')) { |
|
49 | +if (!function_exists('assets')) { |
|
50 | 50 | function assets($path) |
51 | 51 | { |
52 | 52 | $app = Application::getInstance(); |
@@ -54,24 +54,24 @@ discard block |
||
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | -if (! function_exists('remove_space')) { |
|
57 | +if (!function_exists('remove_space')) { |
|
58 | 58 | function remove_space($str) { |
59 | 59 | return str_replace(' ', '-', $str); |
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
63 | -if (! function_exists('remove_dash')) { |
|
63 | +if (!function_exists('remove_dash')) { |
|
64 | 64 | function remove_dash($str) { |
65 | 65 | return str_replace('-', ' ', $str); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | -if (! function_exists('clean_name_url')) { |
|
69 | +if (!function_exists('clean_name_url')) { |
|
70 | 70 | function clean_name_url($class = null) { |
71 | 71 | |
72 | 72 | $app = Application::getInstance(); |
73 | 73 | |
74 | - if (! $class) { |
|
74 | + if (!$class) { |
|
75 | 75 | |
76 | 76 | $class = debug_backtrace()[1]['class']; |
77 | 77 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | $class = strtolower($class); |
85 | 85 | |
86 | - $class = '/' . $class . '/'; |
|
86 | + $class = '/' . $class . '/'; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | $url = $app->request->url(); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | -if (! function_exists('text_char_limit')) { |
|
99 | +if (!function_exists('text_char_limit')) { |
|
100 | 100 | function text_char_limit($text, $limit) { |
101 | 101 | if (strlen($text) > $limit) { |
102 | 102 | return substr($text, 0, $limit) . '...'; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | -if (! function_exists('array_equal')) { |
|
107 | +if (!function_exists('array_equal')) { |
|
108 | 108 | function array_equal($a, $b) { |
109 | 109 | return ( |
110 | 110 | is_array($a) |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | -if (! function_exists('redirect_after')) { |
|
118 | +if (!function_exists('redirect_after')) { |
|
119 | 119 | function redirect_after($num) { |
120 | 120 | $app = Application::getInstance(); |
121 | 121 | $app->url->redirectTo('/', $num); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'classes' => [ |
|
4 | + 'classes' => [ |
|
5 | 5 | 'request' => 'System\\Http\\Request', |
6 | 6 | 'response' => 'System\\Http\\Response', |
7 | 7 | 'route' => 'System\\Route', |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | 'validator' => 'System\\Validation', |
15 | 15 | 'paginatio' => 'System\\Paginatio', |
16 | 16 | 'PugView' => 'System\\PugView', |
17 | - ], |
|
18 | - 'middlewares' => [ |
|
17 | + ], |
|
18 | + 'middlewares' => [ |
|
19 | 19 | 'admin' => [ |
20 | - 'auth' => 'App\\Middleware\\Admin\\AuthenticateMiddleware', |
|
21 | - 'ajax' => 'App\\Middleware\\Admin\\AjaxMiddleware', |
|
22 | - 'permissions' => 'App\\Middleware\\Admin\\PermissionsMiddleware', |
|
23 | - 'redirect' => 'App\\Middleware\\Admin\\RedirectMiddleware', |
|
20 | + 'auth' => 'App\\Middleware\\Admin\\AuthenticateMiddleware', |
|
21 | + 'ajax' => 'App\\Middleware\\Admin\\AjaxMiddleware', |
|
22 | + 'permissions' => 'App\\Middleware\\Admin\\PermissionsMiddleware', |
|
23 | + 'redirect' => 'App\\Middleware\\Admin\\RedirectMiddleware', |
|
24 | 24 | ], |
25 | 25 | 'website' => [ |
26 | 26 | ] |
27 | - ] |
|
27 | + ] |
|
28 | 28 | ]; |
@@ -6,12 +6,12 @@ discard block |
||
6 | 6 | |
7 | 7 | class LoginModel extends Model |
8 | 8 | { |
9 | - protected $table = 'users'; |
|
9 | + protected $table = 'users'; |
|
10 | 10 | |
11 | - private $user; |
|
11 | + private $user; |
|
12 | 12 | |
13 | - public function isValidLogin($email, $password) |
|
14 | - { |
|
13 | + public function isValidLogin($email, $password) |
|
14 | + { |
|
15 | 15 | $user = $this->where('email=?' , $email)->fetch($this->table); |
16 | 16 | |
17 | 17 | if (! $user) return false; |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | $this->user = $user; |
20 | 20 | |
21 | 21 | return password_verify($password, $user->password); |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function user() |
|
25 | - { |
|
24 | + public function user() |
|
25 | + { |
|
26 | 26 | return $this->user; |
27 | - } |
|
27 | + } |
|
28 | 28 | |
29 | - public function isLogged() |
|
30 | - { |
|
29 | + public function isLogged() |
|
30 | + { |
|
31 | 31 | if ($this->cookie->has('login')) { |
32 | 32 | |
33 | 33 | $code = $this->cookie->get('login'); |
@@ -48,5 +48,5 @@ discard block |
||
48 | 48 | $this->user = $user; |
49 | 49 | |
50 | 50 | return true; |
51 | - } |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | \ No newline at end of file |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | |
13 | 13 | public function isValidLogin($email, $password) |
14 | 14 | { |
15 | - $user = $this->where('email=?' , $email)->fetch($this->table); |
|
15 | + $user = $this->where('email=?', $email)->fetch($this->table); |
|
16 | 16 | |
17 | - if (! $user) return false; |
|
17 | + if (!$user) return false; |
|
18 | 18 | |
19 | 19 | $this->user = $user; |
20 | 20 | |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | |
44 | - $user = $this->where('code=?' , $code)->fetch($this->table); |
|
44 | + $user = $this->where('code=?', $code)->fetch($this->table); |
|
45 | 45 | |
46 | - if (! $user) return false; |
|
46 | + if (!$user) return false; |
|
47 | 47 | |
48 | 48 | $this->user = $user; |
49 | 49 |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | { |
15 | 15 | $user = $this->where('email=?' , $email)->fetch($this->table); |
16 | 16 | |
17 | - if (! $user) return false; |
|
17 | + if (! $user) { |
|
18 | + return false; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | $this->user = $user; |
20 | 22 | |
@@ -43,7 +45,9 @@ discard block |
||
43 | 45 | |
44 | 46 | $user = $this->where('code=?' , $code)->fetch($this->table); |
45 | 47 | |
46 | - if (! $user) return false; |
|
48 | + if (! $user) { |
|
49 | + return false; |
|
50 | + } |
|
47 | 51 | |
48 | 52 | $this->user = $user; |
49 | 53 |
@@ -6,24 +6,24 @@ |
||
6 | 6 | |
7 | 7 | class UsersGroupsModel extends Model |
8 | 8 | { |
9 | - protected $table = 'users_groups'; |
|
9 | + protected $table = 'users_groups'; |
|
10 | 10 | |
11 | - public function get($id) |
|
12 | - { |
|
11 | + public function get($id) |
|
12 | + { |
|
13 | 13 | $userGroup = parent::get($id); |
14 | 14 | |
15 | 15 | if ($userGroup) { |
16 | 16 | |
17 | - $userGroupInfos = $this->hasMany('UsersGroupPermissionsModel', $id); |
|
17 | + $userGroupInfos = $this->hasMany('UsersGroupPermissionsModel', $id); |
|
18 | 18 | |
19 | - $userGroup->pages = []; |
|
19 | + $userGroup->pages = []; |
|
20 | 20 | |
21 | - foreach($userGroupInfos as $userGroupInfo) { |
|
21 | + foreach($userGroupInfos as $userGroupInfo) { |
|
22 | 22 | |
23 | 23 | $userGroup->pages[] = $userGroupInfo->page; |
24 | - } |
|
24 | + } |
|
25 | 25 | |
26 | - return $userGroup; |
|
26 | + return $userGroup; |
|
27 | + } |
|
27 | 28 | } |
28 | - } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | $userGroup->pages = []; |
20 | 20 | |
21 | - foreach($userGroupInfos as $userGroupInfo) { |
|
21 | + foreach ($userGroupInfos as $userGroupInfo) { |
|
22 | 22 | |
23 | 23 | $userGroup->pages[] = $userGroupInfo->page; |
24 | 24 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | |
7 | 7 | class UsersGroupPermissionsModel extends Model |
8 | 8 | { |
9 | - protected $table = 'users_group_permissions'; |
|
9 | + protected $table = 'users_group_permissions'; |
|
10 | 10 | } |
11 | 11 | \ No newline at end of file |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class SettingsModel extends Model |
8 | 8 | { |
9 | - protected $table = 'settings'; |
|
9 | + protected $table = 'settings'; |
|
10 | 10 | |
11 | - private $settings; |
|
11 | + private $settings; |
|
12 | 12 | |
13 | - public function loadAll() |
|
14 | - { |
|
13 | + public function loadAll() |
|
14 | + { |
|
15 | 15 | foreach($this->all() as $setting) { |
16 | 16 | |
17 | - $this->settings[$setting->key] = $setting->value; |
|
17 | + $this->settings[$setting->key] = $setting->value; |
|
18 | + } |
|
18 | 19 | } |
19 | - } |
|
20 | 20 | |
21 | - public function get($key) |
|
22 | - { |
|
21 | + public function get($key) |
|
22 | + { |
|
23 | 23 | return array_get($this->settings, $key); |
24 | - } |
|
24 | + } |
|
25 | 25 | |
26 | - public function updateSettings() |
|
27 | - { |
|
26 | + public function updateSettings() |
|
27 | + { |
|
28 | 28 | |
29 | - } |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | public function loadAll() |
14 | 14 | { |
15 | - foreach($this->all() as $setting) { |
|
15 | + foreach ($this->all() as $setting) { |
|
16 | 16 | |
17 | 17 | $this->settings[$setting->key] = $setting->value; |
18 | 18 | } |
@@ -6,15 +6,15 @@ |
||
6 | 6 | |
7 | 7 | class UserModel extends Model |
8 | 8 | { |
9 | - protected $table = 'users'; |
|
9 | + protected $table = 'users'; |
|
10 | 10 | |
11 | - public function permissions($id) |
|
12 | - { |
|
11 | + public function permissions($id) |
|
12 | + { |
|
13 | 13 | return $this->hasMany('UsersGroupPermissions', $id, 'id', 'users_group_id'); |
14 | - } |
|
14 | + } |
|
15 | 15 | |
16 | - public function comments($id) |
|
17 | - { |
|
16 | + public function comments($id) |
|
17 | + { |
|
18 | 18 | return $this->hasMany('Comment', $id); |
19 | - } |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | \ No newline at end of file |