@@ -6,44 +6,44 @@ |
||
6 | 6 | |
7 | 7 | class Response |
8 | 8 | { |
9 | - private $app; |
|
9 | + private $app; |
|
10 | 10 | |
11 | - private $headers = []; |
|
11 | + private $headers = []; |
|
12 | 12 | |
13 | - private $content = ''; |
|
13 | + private $content = ''; |
|
14 | 14 | |
15 | - public function __construct(Application $app) |
|
16 | - { |
|
15 | + public function __construct(Application $app) |
|
16 | + { |
|
17 | 17 | $this->app = $app; |
18 | - } |
|
18 | + } |
|
19 | 19 | |
20 | - public function setOutput($content) |
|
21 | - { |
|
20 | + public function setOutput($content) |
|
21 | + { |
|
22 | 22 | $this->content = $content; |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - public function setHeaders($header, $value) |
|
26 | - { |
|
25 | + public function setHeaders($header, $value) |
|
26 | + { |
|
27 | 27 | $this->headers[$header] = $value; |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - public function sendOutput() |
|
31 | - { |
|
30 | + public function sendOutput() |
|
31 | + { |
|
32 | 32 | echo $this->content; |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | - public function sendHeaders() |
|
36 | - { |
|
37 | - foreach($this->headers as $header => $value) |
|
38 | - { |
|
35 | + public function sendHeaders() |
|
36 | + { |
|
37 | + foreach($this->headers as $header => $value) |
|
38 | + { |
|
39 | 39 | header($header . ':' . $value); |
40 | - } |
|
41 | - } |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - public function send() |
|
44 | - { |
|
43 | + public function send() |
|
44 | + { |
|
45 | 45 | $this->sendHeaders(); |
46 | 46 | |
47 | 47 | $this->sendOutput(); |
48 | - } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -34,7 +34,7 @@ |
||
34 | 34 | |
35 | 35 | public function sendHeaders() |
36 | 36 | { |
37 | - foreach($this->headers as $header => $value) |
|
37 | + foreach ($this->headers as $header => $value) |
|
38 | 38 | { |
39 | 39 | header($header . ':' . $value); |
40 | 40 | } |
@@ -6,35 +6,35 @@ discard block |
||
6 | 6 | |
7 | 7 | class UploadeFile |
8 | 8 | { |
9 | - private $app; |
|
9 | + private $app; |
|
10 | 10 | |
11 | - private $file = []; |
|
11 | + private $file = []; |
|
12 | 12 | |
13 | - private $fileName; |
|
13 | + private $fileName; |
|
14 | 14 | |
15 | - private $nameOnly; |
|
15 | + private $nameOnly; |
|
16 | 16 | |
17 | - private $extension; |
|
17 | + private $extension; |
|
18 | 18 | |
19 | - private $minetype; |
|
19 | + private $minetype; |
|
20 | 20 | |
21 | - private $tempFile; |
|
21 | + private $tempFile; |
|
22 | 22 | |
23 | - private $size; |
|
23 | + private $size; |
|
24 | 24 | |
25 | - private $error; |
|
25 | + private $error; |
|
26 | 26 | |
27 | - private const AllOW_EXTENSION = ['png', 'jpg', 'jpeg', 'gif', 'webp']; |
|
27 | + private const AllOW_EXTENSION = ['png', 'jpg', 'jpeg', 'gif', 'webp']; |
|
28 | 28 | |
29 | - public function __construct(Application $app, $input) |
|
30 | - { |
|
29 | + public function __construct(Application $app, $input) |
|
30 | + { |
|
31 | 31 | $this->app = $app; |
32 | 32 | |
33 | 33 | $this->getFileInfo($input); |
34 | - } |
|
34 | + } |
|
35 | 35 | |
36 | - private function getFileInfo($input) |
|
37 | - { |
|
36 | + private function getFileInfo($input) |
|
37 | + { |
|
38 | 38 | if (empty($_FILES[$input])) return; |
39 | 39 | |
40 | 40 | $file = $_FILES[$input]; |
@@ -58,50 +58,50 @@ discard block |
||
58 | 58 | $this->nameOnly = $fileInfo['filename']; |
59 | 59 | |
60 | 60 | $this->extension = $fileInfo['extension']; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - public function exists() |
|
64 | - { |
|
63 | + public function exists() |
|
64 | + { |
|
65 | 65 | return ! empty($this->file); |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - public function getFileName() |
|
69 | - { |
|
68 | + public function getFileName() |
|
69 | + { |
|
70 | 70 | return $this->fileName; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - public function getNameOnly() |
|
74 | - { |
|
73 | + public function getNameOnly() |
|
74 | + { |
|
75 | 75 | return $this->nameOnly; |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - public function getExtension() |
|
79 | - { |
|
78 | + public function getExtension() |
|
79 | + { |
|
80 | 80 | return $this->extension; |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - public function getMinetype() |
|
84 | - { |
|
83 | + public function getMinetype() |
|
84 | + { |
|
85 | 85 | return $this->minetype; |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - public function getSize() |
|
89 | - { |
|
88 | + public function getSize() |
|
89 | + { |
|
90 | 90 | return $this->size; |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - public function getTempFile() |
|
94 | - { |
|
93 | + public function getTempFile() |
|
94 | + { |
|
95 | 95 | return $this->tempFile; |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - public function isImage() |
|
99 | - { |
|
98 | + public function isImage() |
|
99 | + { |
|
100 | 100 | return strpos($this->minetype, 'image/') === 0 && in_array($this->extension, self::AllOW_EXTENSION); |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | - public function moveTo($target, $newName = null) |
|
104 | - { |
|
103 | + public function moveTo($target, $newName = null) |
|
104 | + { |
|
105 | 105 | $newName = $newName ?: sha1(rand()) . sha1(rand()); |
106 | 106 | |
107 | 107 | $newName .= '.' . $this->extension; |
@@ -116,5 +116,5 @@ discard block |
||
116 | 116 | $uploade = move_uploaded_file($this->tempFile, $filePath); |
117 | 117 | |
118 | 118 | return $uploade; |
119 | - } |
|
119 | + } |
|
120 | 120 | } |
121 | 121 | \ No newline at end of file |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function exists() |
64 | 64 | { |
65 | - return ! empty($this->file); |
|
65 | + return !empty($this->file); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public function getFileName() |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | $newName .= '.' . $this->extension; |
108 | 108 | |
109 | - if (! is_dir($target)) mkdir($target, 0777, true); |
|
109 | + if (!is_dir($target)) mkdir($target, 0777, true); |
|
110 | 110 | |
111 | 111 | $filePath = $target . $newName; |
112 | 112 |
@@ -35,13 +35,17 @@ discard block |
||
35 | 35 | |
36 | 36 | private function getFileInfo($input) |
37 | 37 | { |
38 | - if (empty($_FILES[$input])) return; |
|
38 | + if (empty($_FILES[$input])) { |
|
39 | + return; |
|
40 | + } |
|
39 | 41 | |
40 | 42 | $file = $_FILES[$input]; |
41 | 43 | |
42 | 44 | $this->error = $file['error']; |
43 | 45 | |
44 | - if ($this->error != UPLOAD_ERR_OK) return; |
|
46 | + if ($this->error != UPLOAD_ERR_OK) { |
|
47 | + return; |
|
48 | + } |
|
45 | 49 | |
46 | 50 | $this->file = $file; |
47 | 51 | |
@@ -106,7 +110,9 @@ discard block |
||
106 | 110 | |
107 | 111 | $newName .= '.' . $this->extension; |
108 | 112 | |
109 | - if (! is_dir($target)) mkdir($target, 0777, true); |
|
113 | + if (! is_dir($target)) { |
|
114 | + mkdir($target, 0777, true); |
|
115 | + } |
|
110 | 116 | |
111 | 117 | $filePath = $target . $newName; |
112 | 118 |
@@ -4,26 +4,26 @@ discard block |
||
4 | 4 | |
5 | 5 | class Validation |
6 | 6 | { |
7 | - private $app; |
|
7 | + private $app; |
|
8 | 8 | |
9 | - private $input; |
|
9 | + private $input; |
|
10 | 10 | |
11 | - private $errors = []; |
|
11 | + private $errors = []; |
|
12 | 12 | |
13 | - public function __construct(Application $app) |
|
14 | - { |
|
13 | + public function __construct(Application $app) |
|
14 | + { |
|
15 | 15 | $this->app = $app; |
16 | - } |
|
16 | + } |
|
17 | 17 | |
18 | - public function input($input) |
|
19 | - { |
|
18 | + public function input($input) |
|
19 | + { |
|
20 | 20 | $this->input = $input; |
21 | 21 | |
22 | 22 | return $this; |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - public function require($input = null, $msg = null) |
|
26 | - { |
|
25 | + public function require($input = null, $msg = null) |
|
26 | + { |
|
27 | 27 | if (! $this->input) $this->input = $input; |
28 | 28 | |
29 | 29 | $value = $this->value($this->input); |
@@ -35,111 +35,111 @@ discard block |
||
35 | 35 | $this->addError($this->input, $msg); |
36 | 36 | } |
37 | 37 | return $this; |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public function email($input = null, $msg = null) |
|
41 | - { |
|
40 | + public function email($input = null, $msg = null) |
|
41 | + { |
|
42 | 42 | if (! $this->input) $this->input = $input; |
43 | 43 | |
44 | 44 | $value = $this->value($this->input); |
45 | 45 | |
46 | 46 | if (! filter_var($value, FILTER_VALIDATE_EMAIL)) { |
47 | 47 | |
48 | - $msg = $msg ?: sprintf('%s is not valid Email', ucfirst($this->input)); |
|
48 | + $msg = $msg ?: sprintf('%s is not valid Email', ucfirst($this->input)); |
|
49 | 49 | |
50 | - $this->addError($this->input, $msg); |
|
50 | + $this->addError($this->input, $msg); |
|
51 | 51 | } |
52 | 52 | return $this; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function number($input = null, $msg = null) |
|
56 | - { |
|
55 | + public function number($input = null, $msg = null) |
|
56 | + { |
|
57 | 57 | if (! $this->input) $this->input = $input; |
58 | 58 | |
59 | 59 | $value = $this->value($this->input); |
60 | 60 | |
61 | 61 | if ($value) { |
62 | 62 | |
63 | - if (! is_numeric($value)) { |
|
63 | + if (! is_numeric($value)) { |
|
64 | 64 | |
65 | 65 | $msg = $msg ?: 'the Input must be number'; |
66 | 66 | |
67 | 67 | $this->addError($this->input, $msg); |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | return $this; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - public function text($input = null, $msg = null) |
|
74 | - { |
|
73 | + public function text($input = null, $msg = null) |
|
74 | + { |
|
75 | 75 | if (! $this->input) $this->input = $input; |
76 | 76 | |
77 | 77 | $value = $this->value($this->input); |
78 | 78 | |
79 | 79 | if ($value) { |
80 | 80 | |
81 | - if (is_numeric($value)) { |
|
81 | + if (is_numeric($value)) { |
|
82 | 82 | |
83 | 83 | $msg = $msg ?: 'the Input must be Text'; |
84 | 84 | |
85 | 85 | $this->addError($this->input, $msg); |
86 | - } |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | return $this; |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - public function minLen($length, $msg = null) |
|
92 | - { |
|
91 | + public function minLen($length, $msg = null) |
|
92 | + { |
|
93 | 93 | $value = $this->value($this->input); |
94 | 94 | |
95 | 95 | if ($value) { |
96 | 96 | |
97 | - if (strlen($value) < $length) { |
|
97 | + if (strlen($value) < $length) { |
|
98 | 98 | |
99 | 99 | $msg = $msg ?: 'This input must be at least ' . $length; |
100 | 100 | |
101 | 101 | $this->addError($this->input, $msg); |
102 | - } |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | return $this; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - public function maxLen($length, $msg = null) |
|
108 | - { |
|
107 | + public function maxLen($length, $msg = null) |
|
108 | + { |
|
109 | 109 | $value = $this->value($this->input); |
110 | 110 | |
111 | 111 | if ($value) { |
112 | 112 | |
113 | - if (strlen($value) > $length) { |
|
113 | + if (strlen($value) > $length) { |
|
114 | 114 | |
115 | 115 | $msg = $msg ?: 'This must be ' . $length . ' or fewer'; |
116 | 116 | |
117 | 117 | $this->addError($this->input, $msg); |
118 | - } |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | return $this; |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - public function match($input, $msg = null) |
|
124 | - { |
|
123 | + public function match($input, $msg = null) |
|
124 | + { |
|
125 | 125 | $valuePassword = $this->value($this->input); |
126 | 126 | |
127 | 127 | $valueConfirm = $this->value($input); |
128 | 128 | |
129 | 129 | if ($valuePassword && $valueConfirm ) { |
130 | 130 | |
131 | - if ($valuePassword !== $valueConfirm) { |
|
131 | + if ($valuePassword !== $valueConfirm) { |
|
132 | 132 | |
133 | 133 | $msg = $msg ?: 'Passwords does not match'; |
134 | 134 | |
135 | 135 | $this->addError('match', $msg); |
136 | - } |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | return $this; |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | - public function unique($data, $msg = null) |
|
142 | - { |
|
141 | + public function unique($data, $msg = null) |
|
142 | + { |
|
143 | 143 | $value = $this->value($this->input); |
144 | 144 | |
145 | 145 | $table = null; |
@@ -162,65 +162,65 @@ discard block |
||
162 | 162 | |
163 | 163 | if ($result) { |
164 | 164 | |
165 | - $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
165 | + $msg = $msg ?: sprintf('%s is already exist', ucfirst($this->input)); |
|
166 | 166 | |
167 | - $this->addError($this->input, $msg); |
|
167 | + $this->addError($this->input, $msg); |
|
168 | 168 | } |
169 | 169 | return $this; |
170 | - } |
|
170 | + } |
|
171 | 171 | |
172 | - public function requireFile($input, $msg = null) |
|
173 | - { |
|
172 | + public function requireFile($input, $msg = null) |
|
173 | + { |
|
174 | 174 | |
175 | - } |
|
175 | + } |
|
176 | 176 | |
177 | - public function image($input, $msg = null) |
|
178 | - { |
|
177 | + public function image($input, $msg = null) |
|
178 | + { |
|
179 | 179 | |
180 | - } |
|
180 | + } |
|
181 | 181 | |
182 | - public function message($msg = null) |
|
183 | - { |
|
182 | + public function message($msg = null) |
|
183 | + { |
|
184 | 184 | $this->errors[] = $msg; |
185 | 185 | |
186 | 186 | return $this; |
187 | - } |
|
187 | + } |
|
188 | 188 | |
189 | - public function validate() |
|
190 | - { |
|
189 | + public function validate() |
|
190 | + { |
|
191 | 191 | |
192 | - } |
|
192 | + } |
|
193 | 193 | |
194 | - public function passes() |
|
195 | - { |
|
194 | + public function passes() |
|
195 | + { |
|
196 | 196 | return empty($this->errors); |
197 | - } |
|
197 | + } |
|
198 | 198 | |
199 | - public function fails() |
|
200 | - { |
|
199 | + public function fails() |
|
200 | + { |
|
201 | 201 | return ! empty($this->errors); |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - public function getMsgs() |
|
205 | - { |
|
204 | + public function getMsgs() |
|
205 | + { |
|
206 | 206 | return $this->errors; |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - private function value($input) |
|
210 | - { |
|
209 | + private function value($input) |
|
210 | + { |
|
211 | 211 | return $this->app->request->post($input); |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - public function addError($input, $msg) |
|
215 | - { |
|
214 | + public function addError($input, $msg) |
|
215 | + { |
|
216 | 216 | if (! $this->checkError($input)) { |
217 | 217 | |
218 | - $this->errors[$input] = $msg; |
|
218 | + $this->errors[$input] = $msg; |
|
219 | + } |
|
219 | 220 | } |
220 | - } |
|
221 | 221 | |
222 | - private function checkError($input) |
|
223 | - { |
|
222 | + private function checkError($input) |
|
223 | + { |
|
224 | 224 | return array_key_exists($input, $this->errors); |
225 | - } |
|
225 | + } |
|
226 | 226 | } |
227 | 227 | \ No newline at end of file |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | |
25 | 25 | public function require($input = null, $msg = null) |
26 | 26 | { |
27 | - if (! $this->input) $this->input = $input; |
|
27 | + if (!$this->input) $this->input = $input; |
|
28 | 28 | |
29 | 29 | $value = $this->value($this->input); |
30 | 30 | |
31 | - if (! $value) { |
|
31 | + if (!$value) { |
|
32 | 32 | |
33 | 33 | $msg = $msg ?: 'This input is required'; |
34 | 34 | |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | |
40 | 40 | public function email($input = null, $msg = null) |
41 | 41 | { |
42 | - if (! $this->input) $this->input = $input; |
|
42 | + if (!$this->input) $this->input = $input; |
|
43 | 43 | |
44 | 44 | $value = $this->value($this->input); |
45 | 45 | |
46 | - if (! filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
46 | + if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
47 | 47 | |
48 | 48 | $msg = $msg ?: sprintf('%s is not valid Email', ucfirst($this->input)); |
49 | 49 | |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | |
55 | 55 | public function number($input = null, $msg = null) |
56 | 56 | { |
57 | - if (! $this->input) $this->input = $input; |
|
57 | + if (!$this->input) $this->input = $input; |
|
58 | 58 | |
59 | 59 | $value = $this->value($this->input); |
60 | 60 | |
61 | 61 | if ($value) { |
62 | 62 | |
63 | - if (! is_numeric($value)) { |
|
63 | + if (!is_numeric($value)) { |
|
64 | 64 | |
65 | 65 | $msg = $msg ?: 'the Input must be number'; |
66 | 66 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | public function text($input = null, $msg = null) |
74 | 74 | { |
75 | - if (! $this->input) $this->input = $input; |
|
75 | + if (!$this->input) $this->input = $input; |
|
76 | 76 | |
77 | 77 | $value = $this->value($this->input); |
78 | 78 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | $valueConfirm = $this->value($input); |
128 | 128 | |
129 | - if ($valuePassword && $valueConfirm ) { |
|
129 | + if ($valuePassword && $valueConfirm) { |
|
130 | 130 | |
131 | 131 | if ($valuePassword !== $valueConfirm) { |
132 | 132 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | |
199 | 199 | public function fails() |
200 | 200 | { |
201 | - return ! empty($this->errors); |
|
201 | + return !empty($this->errors); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | public function getMsgs() |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | public function addError($input, $msg) |
215 | 215 | { |
216 | - if (! $this->checkError($input)) { |
|
216 | + if (!$this->checkError($input)) { |
|
217 | 217 | |
218 | 218 | $this->errors[$input] = $msg; |
219 | 219 | } |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | |
25 | 25 | public function require($input = null, $msg = null) |
26 | 26 | { |
27 | - if (! $this->input) $this->input = $input; |
|
27 | + if (! $this->input) { |
|
28 | + $this->input = $input; |
|
29 | + } |
|
28 | 30 | |
29 | 31 | $value = $this->value($this->input); |
30 | 32 | |
@@ -39,7 +41,9 @@ discard block |
||
39 | 41 | |
40 | 42 | public function email($input = null, $msg = null) |
41 | 43 | { |
42 | - if (! $this->input) $this->input = $input; |
|
44 | + if (! $this->input) { |
|
45 | + $this->input = $input; |
|
46 | + } |
|
43 | 47 | |
44 | 48 | $value = $this->value($this->input); |
45 | 49 | |
@@ -54,7 +58,9 @@ discard block |
||
54 | 58 | |
55 | 59 | public function number($input = null, $msg = null) |
56 | 60 | { |
57 | - if (! $this->input) $this->input = $input; |
|
61 | + if (! $this->input) { |
|
62 | + $this->input = $input; |
|
63 | + } |
|
58 | 64 | |
59 | 65 | $value = $this->value($this->input); |
60 | 66 | |
@@ -72,7 +78,9 @@ discard block |
||
72 | 78 | |
73 | 79 | public function text($input = null, $msg = null) |
74 | 80 | { |
75 | - if (! $this->input) $this->input = $input; |
|
81 | + if (! $this->input) { |
|
82 | + $this->input = $input; |
|
83 | + } |
|
76 | 84 | |
77 | 85 | $value = $this->value($this->input); |
78 | 86 | |
@@ -148,8 +156,12 @@ discard block |
||
148 | 156 | $id = null; |
149 | 157 | $userId = null; |
150 | 158 | |
151 | - if (count($data) == 2) list($table, $column) = $data; |
|
152 | - if (count($data) == 4) list($table, $column, $id, $userId) = $data; |
|
159 | + if (count($data) == 2) { |
|
160 | + list($table, $column) = $data; |
|
161 | + } |
|
162 | + if (count($data) == 4) { |
|
163 | + list($table, $column, $id, $userId) = $data; |
|
164 | + } |
|
153 | 165 | |
154 | 166 | $sql = $userId ? $column . ' = ? AND ' . $id . ' != ? ' : $column . ' = ?'; |
155 | 167 |
@@ -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,57 +295,57 @@ 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 | - $this->bindings = array_merge($this->bindings, array_values($value)); |
|
340 | + $this->bindings = array_merge($this->bindings, array_values($value)); |
|
341 | 341 | } else { |
342 | 342 | |
343 | - $this->bindings[] = $value; |
|
343 | + $this->bindings[] = $value; |
|
344 | + } |
|
344 | 345 | } |
345 | - } |
|
346 | 346 | |
347 | - public function query(...$bindings) |
|
348 | - { |
|
347 | + public function query(...$bindings) |
|
348 | + { |
|
349 | 349 | $sql = array_shift($bindings); |
350 | 350 | |
351 | 351 | if (count($bindings) == 1 AND is_array($bindings[0])) { |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | $query = $this->connection()->prepare($sql); |
357 | 357 | |
358 | 358 | foreach ($bindings as $key => $value) { |
359 | - $query->bindValue($key + 1, _e($value)); |
|
359 | + $query->bindValue($key + 1, _e($value)); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | $query->execute(); |
@@ -367,12 +367,12 @@ discard block |
||
367 | 367 | |
368 | 368 | } catch (PDOException $e) { |
369 | 369 | |
370 | - throw new Exception($e->getMessage()); |
|
370 | + throw new Exception($e->getMessage()); |
|
371 | + } |
|
371 | 372 | } |
372 | - } |
|
373 | 373 | |
374 | - private function reset() |
|
375 | - { |
|
374 | + private function reset() |
|
375 | + { |
|
376 | 376 | $this->table = null; |
377 | 377 | |
378 | 378 | $this->rows = 0; |
@@ -396,5 +396,5 @@ discard block |
||
396 | 396 | $this->offset = 0; |
397 | 397 | |
398 | 398 | $this->groupBy = []; |
399 | - } |
|
399 | + } |
|
400 | 400 | } |
401 | 401 | \ No newline at end of file |
@@ -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 |
@@ -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); |