@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * @return bool |
|
85 | + * @return string|boolean |
|
86 | 86 | */ |
87 | 87 | public static function value($key = null) |
88 | 88 | { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * @param $key |
98 | 98 | * |
99 | - * @return string|static |
|
99 | + * @return string |
|
100 | 100 | */ |
101 | 101 | public static function formatDate($key) |
102 | 102 | { |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | /** |
111 | 111 | * @param $value |
112 | 112 | * |
113 | - * @return mixed |
|
113 | + * @return string |
|
114 | 114 | */ |
115 | 115 | public static function formatMoney($value) |
116 | 116 | { |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param $expires |
254 | 254 | * @param $secret |
255 | 255 | * |
256 | - * @return mixed |
|
256 | + * @return string |
|
257 | 257 | */ |
258 | 258 | private static function getIv($expires, $secret) |
259 | 259 | { |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | class Utils extends Controller{ |
8 | 8 | |
9 | 9 | private static $instance; |
10 | - public $debug; |
|
10 | + public $debug; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @return Utils |
@@ -21,33 +21,33 @@ discard block |
||
21 | 21 | return self::$instance; |
22 | 22 | } |
23 | 23 | |
24 | - /** |
|
25 | - * @param $useragent |
|
26 | - * |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function detect_mobile($useragent) |
|
30 | - { |
|
31 | - if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($useragent, 0, 4))) { |
|
32 | - return true; |
|
33 | - } else { |
|
34 | - return false; |
|
35 | - } |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @param $email |
|
40 | - * |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public static function is_email($email) |
|
44 | - { |
|
45 | - if (filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
46 | - return true; |
|
47 | - } else { |
|
48 | - return false; |
|
49 | - } |
|
50 | - } |
|
24 | + /** |
|
25 | + * @param $useragent |
|
26 | + * |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function detect_mobile($useragent) |
|
30 | + { |
|
31 | + if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($useragent, 0, 4))) { |
|
32 | + return true; |
|
33 | + } else { |
|
34 | + return false; |
|
35 | + } |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @param $email |
|
40 | + * |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public static function is_email($email) |
|
44 | + { |
|
45 | + if (filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
46 | + return true; |
|
47 | + } else { |
|
48 | + return false; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param $rawData |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | return $string; |
70 | 70 | } |
71 | 71 | |
72 | - /** |
|
73 | - * @param $uri |
|
74 | - */ |
|
75 | - public function active($uri){ |
|
76 | - echo (str_replace('/','.',substr($_SERVER['REQUEST_URI'], 1)) == $uri)? "class='active'" : ""; |
|
77 | - } |
|
72 | + /** |
|
73 | + * @param $uri |
|
74 | + */ |
|
75 | + public function active($uri){ |
|
76 | + echo (str_replace('/','.',substr($_SERVER['REQUEST_URI'], 1)) == $uri)? "class='active'" : ""; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @return bool |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | |
111 | - /** |
|
111 | + /** |
|
112 | 112 | * @param $data |
113 | 113 | * @param $key |
114 | 114 | * @param $iv |
@@ -151,46 +151,46 @@ discard block |
||
151 | 151 | return $res; |
152 | 152 | } |
153 | 153 | |
154 | - public static function setDebug($exceptionCode){ |
|
155 | - $exception = null; |
|
156 | - switch ($exceptionCode){ |
|
157 | - case 23000 : $exception = "Erro ao inserir os dados!"; break; |
|
158 | - } |
|
159 | - $print = "<div class='debug'>"; |
|
160 | - $print .= $exception; |
|
161 | - $print .= "</div>"; |
|
162 | - self::getInstance()->debug = $print; |
|
163 | - } |
|
164 | - |
|
165 | - public static function getDebug(){ |
|
166 | - echo self::getInstance()->debug; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param int $length |
|
171 | - * |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public static function generateToken($length = 20) { |
|
175 | - if(function_exists('openssl_random_pseudo_bytes')) { |
|
176 | - $token = base64_encode(openssl_random_pseudo_bytes($length, $strong)); |
|
177 | - if($strong == TRUE) |
|
178 | - return strtr(substr($token, 0, $length), '+/=', '-_,'); |
|
179 | - } |
|
180 | - |
|
181 | - $characters = '0123456789'; |
|
182 | - $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
|
183 | - $charactersLength = strlen($characters)-1; |
|
184 | - $token = ''; |
|
185 | - |
|
186 | - for ($i = 0; $i < $length; $i++) { |
|
187 | - $token .= $characters[mt_rand(0, $charactersLength)]; |
|
188 | - } |
|
189 | - |
|
190 | - return $token; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
154 | + public static function setDebug($exceptionCode){ |
|
155 | + $exception = null; |
|
156 | + switch ($exceptionCode){ |
|
157 | + case 23000 : $exception = "Erro ao inserir os dados!"; break; |
|
158 | + } |
|
159 | + $print = "<div class='debug'>"; |
|
160 | + $print .= $exception; |
|
161 | + $print .= "</div>"; |
|
162 | + self::getInstance()->debug = $print; |
|
163 | + } |
|
164 | + |
|
165 | + public static function getDebug(){ |
|
166 | + echo self::getInstance()->debug; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param int $length |
|
171 | + * |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public static function generateToken($length = 20) { |
|
175 | + if(function_exists('openssl_random_pseudo_bytes')) { |
|
176 | + $token = base64_encode(openssl_random_pseudo_bytes($length, $strong)); |
|
177 | + if($strong == TRUE) |
|
178 | + return strtr(substr($token, 0, $length), '+/=', '-_,'); |
|
179 | + } |
|
180 | + |
|
181 | + $characters = '0123456789'; |
|
182 | + $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
|
183 | + $charactersLength = strlen($characters)-1; |
|
184 | + $token = ''; |
|
185 | + |
|
186 | + for ($i = 0; $i < $length; $i++) { |
|
187 | + $token .= $characters[mt_rand(0, $charactersLength)]; |
|
188 | + } |
|
189 | + |
|
190 | + return $token; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | 194 | * @param $data |
195 | 195 | * @param $key |
196 | 196 | * @param $iv |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | |
238 | - /** |
|
238 | + /** |
|
239 | 239 | * @param $expires |
240 | 240 | * @param $secret |
241 | 241 | * |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use Carbon\Carbon; |
5 | 5 | use Core\Lib\Controller; |
6 | 6 | |
7 | -class Utils extends Controller{ |
|
7 | +class Utils extends Controller { |
|
8 | 8 | |
9 | 9 | private static $instance; |
10 | 10 | public $debug; |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | * @return string |
66 | 66 | */ |
67 | 67 | public static function textLimit($string, $size) { |
68 | - $string = (strlen($string) <= $size) ? $string : substr($string, 0, $size) . '...'; |
|
68 | + $string = (strlen($string) <= $size) ? $string : substr($string, 0, $size).'...'; |
|
69 | 69 | return $string; |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @param $uri |
74 | 74 | */ |
75 | - public function active($uri){ |
|
76 | - echo (str_replace('/','.',substr($_SERVER['REQUEST_URI'], 1)) == $uri)? "class='active'" : ""; |
|
75 | + public function active($uri) { |
|
76 | + echo (str_replace('/', '.', substr($_SERVER['REQUEST_URI'], 1)) == $uri) ? "class='active'" : ""; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | static function value($key = null) { |
83 | 83 | if (isset($key) && $key !== null) { |
84 | - return (isset($_REQUEST[$key])) ? ' value=' . $_REQUEST[$key] . '' : false; |
|
84 | + return (isset($_REQUEST[$key])) ? ' value='.$_REQUEST[$key].'' : false; |
|
85 | 85 | } |
86 | 86 | return true; |
87 | 87 | } |
@@ -151,18 +151,18 @@ discard block |
||
151 | 151 | return $res; |
152 | 152 | } |
153 | 153 | |
154 | - public static function setDebug($exceptionCode){ |
|
154 | + public static function setDebug($exceptionCode) { |
|
155 | 155 | $exception = null; |
156 | - switch ($exceptionCode){ |
|
156 | + switch ($exceptionCode) { |
|
157 | 157 | case 23000 : $exception = "Erro ao inserir os dados!"; break; |
158 | 158 | } |
159 | 159 | $print = "<div class='debug'>"; |
160 | 160 | $print .= $exception; |
161 | 161 | $print .= "</div>"; |
162 | - self::getInstance()->debug = $print; |
|
162 | + self::getInstance()->debug = $print; |
|
163 | 163 | } |
164 | 164 | |
165 | - public static function getDebug(){ |
|
165 | + public static function getDebug() { |
|
166 | 166 | echo self::getInstance()->debug; |
167 | 167 | } |
168 | 168 | |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | * @return string |
173 | 173 | */ |
174 | 174 | public static function generateToken($length = 20) { |
175 | - if(function_exists('openssl_random_pseudo_bytes')) { |
|
175 | + if (function_exists('openssl_random_pseudo_bytes')) { |
|
176 | 176 | $token = base64_encode(openssl_random_pseudo_bytes($length, $strong)); |
177 | - if($strong == TRUE) |
|
177 | + if ($strong == TRUE) |
|
178 | 178 | return strtr(substr($token, 0, $length), '+/=', '-_,'); |
179 | 179 | } |
180 | 180 | |
181 | 181 | $characters = '0123456789'; |
182 | 182 | $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
183 | - $charactersLength = strlen($characters)-1; |
|
183 | + $charactersLength = strlen($characters) - 1; |
|
184 | 184 | $token = ''; |
185 | 185 | |
186 | 186 | for ($i = 0; $i < $length; $i++) { |
@@ -174,8 +174,9 @@ |
||
174 | 174 | public static function generateToken($length = 20) { |
175 | 175 | if(function_exists('openssl_random_pseudo_bytes')) { |
176 | 176 | $token = base64_encode(openssl_random_pseudo_bytes($length, $strong)); |
177 | - if($strong == TRUE) |
|
178 | - return strtr(substr($token, 0, $length), '+/=', '-_,'); |
|
177 | + if($strong == TRUE) { |
|
178 | + return strtr(substr($token, 0, $length), '+/=', '-_,'); |
|
179 | + } |
|
179 | 180 | } |
180 | 181 | |
181 | 182 | $characters = '0123456789'; |
@@ -5,7 +5,6 @@ |
||
5 | 5 | use Core\Exceptions\ExceptionHandler; |
6 | 6 | use Exception; |
7 | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | -use Symfony\Component\Routing\Exception\MethodNotAllowedException; |
|
9 | 8 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
10 | 9 | use Symfony\Component\Routing\Matcher\UrlMatcher; |
11 | 10 | use Symfony\Component\Routing\RequestContext; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | return self::$instance; |
34 | 34 | } |
35 | 35 | |
36 | - /** |
|
36 | + /** |
|
37 | 37 | * @param $prefixParam |
38 | 38 | * @param $callable |
39 | 39 | * |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $this->prefix = $oldPrefix; |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
54 | + /** |
|
55 | 55 | * @param $path |
56 | 56 | * @param $controller |
57 | 57 | * @param array $params |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $this->setMethod(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'PATCH'], $path, $controller, $params); |
62 | 62 | } |
63 | 63 | |
64 | - /** |
|
64 | + /** |
|
65 | 65 | * @param $path |
66 | 66 | * @param $controller |
67 | 67 | * @param array $params |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $this->setMethod('GET', $path, $controller, $params); |
72 | 72 | } |
73 | 73 | |
74 | - /** |
|
74 | + /** |
|
75 | 75 | * @param $path |
76 | 76 | * @param $controller |
77 | 77 | * @param array $params |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $this->setMethod('POST', $path, $controller, $params); |
82 | 82 | } |
83 | 83 | |
84 | - /** |
|
84 | + /** |
|
85 | 85 | * @param $path |
86 | 86 | * @param $controller |
87 | 87 | * @param array $params |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $this->setMethod('PUT', $path, $controller, $params); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
94 | + /** |
|
95 | 95 | * @param $httpMethod |
96 | 96 | * @param $path |
97 | 97 | * @param $controller |
@@ -121,33 +121,33 @@ discard block |
||
121 | 121 | $this->routeColletion->add(implode("", $httpMethod) . $prefixedPath, $route); |
122 | 122 | } |
123 | 123 | |
124 | - /** |
|
125 | - * @return array |
|
126 | - */ |
|
127 | - public static function getParams() |
|
124 | + /** |
|
125 | + * @return array |
|
126 | + */ |
|
127 | + public static function getParams() |
|
128 | 128 | { |
129 | 129 | static::includeRoutes(); |
130 | 130 | |
131 | - $parameters = null; |
|
132 | - $context = new RequestContext(); |
|
133 | - $context->fromRequest(Request::createFromGlobals()); |
|
134 | - $matcher = new UrlMatcher(Router::getInstance()->routeColletion, $context); |
|
135 | - |
|
136 | - try { |
|
137 | - $parameters = $matcher->match(Request::createFromGlobals()->getPathInfo()); |
|
138 | - } catch (ResourceNotFoundException $e) { |
|
139 | - $parameters = [ |
|
140 | - '_path' => $_SERVER['REQUEST_URI'], |
|
141 | - '_controller' => 'HomeController', |
|
142 | - '_method' => '_404', |
|
143 | - '_route' => 'GETPOSTPUTPATCHDELETEPATCH/' |
|
144 | - ]; |
|
145 | - } catch (Exception $e){ |
|
146 | - new ExceptionHandler($e); |
|
147 | - } |
|
148 | - return $parameters; |
|
131 | + $parameters = null; |
|
132 | + $context = new RequestContext(); |
|
133 | + $context->fromRequest(Request::createFromGlobals()); |
|
134 | + $matcher = new UrlMatcher(Router::getInstance()->routeColletion, $context); |
|
135 | + |
|
136 | + try { |
|
137 | + $parameters = $matcher->match(Request::createFromGlobals()->getPathInfo()); |
|
138 | + } catch (ResourceNotFoundException $e) { |
|
139 | + $parameters = [ |
|
140 | + '_path' => $_SERVER['REQUEST_URI'], |
|
141 | + '_controller' => 'HomeController', |
|
142 | + '_method' => '_404', |
|
143 | + '_route' => 'GETPOSTPUTPATCHDELETEPATCH/' |
|
144 | + ]; |
|
145 | + } catch (Exception $e){ |
|
146 | + new ExceptionHandler($e); |
|
147 | + } |
|
148 | + return $parameters; |
|
149 | 149 | } |
150 | - private static function includeRoutes() |
|
150 | + private static function includeRoutes() |
|
151 | 151 | { |
152 | 152 | static $included = false; |
153 | 153 | if (!$included) { |
@@ -156,30 +156,30 @@ discard block |
||
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
159 | - /** |
|
160 | - * @return bool |
|
161 | - */ |
|
162 | - public static function init() |
|
159 | + /** |
|
160 | + * @return bool |
|
161 | + */ |
|
162 | + public static function init() |
|
163 | 163 | { |
164 | 164 | static $init = false; |
165 | 165 | if (!$init) { |
166 | 166 | Router::includeRoutes(); |
167 | 167 | $init = true; |
168 | 168 | } |
169 | - return $init; |
|
169 | + return $init; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Return router collection |
|
174 | + * |
|
175 | + * @return RouteCollection |
|
176 | + */ |
|
177 | + public function getCollection() |
|
178 | + { |
|
179 | + return $this->routeColletion; |
|
170 | 180 | } |
171 | 181 | |
172 | - /** |
|
173 | - * Return router collection |
|
174 | - * |
|
175 | - * @return RouteCollection |
|
176 | - */ |
|
177 | - public function getCollection() |
|
178 | - { |
|
179 | - return $this->routeColletion; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
182 | + /** |
|
183 | 183 | * @param $params |
184 | 184 | * @param $closure |
185 | 185 | */ |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | list($controller, $method) = explode("::", $controller); |
107 | - $prefixedPath = $this->prefix . $path; |
|
107 | + $prefixedPath = $this->prefix.$path; |
|
108 | 108 | |
109 | 109 | $configsParams = array_merge(array( |
110 | 110 | "_path" => $path, |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $route = new Route($prefixedPath, $configsParams); |
120 | 120 | $route->setMethods($httpMethod); |
121 | - $this->routeColletion->add(implode("", $httpMethod) . $prefixedPath, $route); |
|
121 | + $this->routeColletion->add(implode("", $httpMethod).$prefixedPath, $route); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | '_method' => '_404', |
143 | 143 | '_route' => 'GETPOSTPUTPATCHDELETEPATCH/' |
144 | 144 | ]; |
145 | - } catch (Exception $e){ |
|
145 | + } catch (Exception $e) { |
|
146 | 146 | new ExceptionHandler($e); |
147 | 147 | } |
148 | 148 | return $parameters; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | { |
152 | 152 | static $included = false; |
153 | 153 | if (!$included) { |
154 | - require ROOT_APP . "routes.php"; |
|
154 | + require ROOT_APP."routes.php"; |
|
155 | 155 | $included = true; |
156 | 156 | } |
157 | 157 | } |
@@ -19,11 +19,11 @@ |
||
19 | 19 | { |
20 | 20 | if ($this->exception instanceof AuthException) { |
21 | 21 | die('User must be logged in'); |
22 | - }else if ($this->exception instanceof NotCallableException) { |
|
22 | + } else if ($this->exception instanceof NotCallableException) { |
|
23 | 23 | die('Method not found'); |
24 | 24 | } if ($this->exception instanceof MethodNotAllowedException) { |
25 | 25 | die('Not allowed'); |
26 | - }else { |
|
26 | + } else { |
|
27 | 27 | echo $this->exception->getMessage(); |
28 | 28 | } |
29 | 29 | } |
@@ -19,11 +19,11 @@ |
||
19 | 19 | { |
20 | 20 | if ($this->exception instanceof AuthException) { |
21 | 21 | die('User must be logged in'); |
22 | - }else if ($this->exception instanceof NotCallableException) { |
|
22 | + } else if ($this->exception instanceof NotCallableException) { |
|
23 | 23 | die('Method not found'); |
24 | 24 | } if ($this->exception instanceof MethodNotAllowedException) { |
25 | 25 | die('Not allowed'); |
26 | - }else { |
|
26 | + } else { |
|
27 | 27 | echo $this->exception->getMessage(); |
28 | 28 | } |
29 | 29 | } |
@@ -12,101 +12,101 @@ |
||
12 | 12 | |
13 | 13 | class View |
14 | 14 | { |
15 | - private $renderer; |
|
16 | - private $template; |
|
17 | - private $params = []; |
|
15 | + private $renderer; |
|
16 | + private $template; |
|
17 | + private $params = []; |
|
18 | 18 | |
19 | - private static $intance; |
|
19 | + private static $intance; |
|
20 | 20 | |
21 | - public static function getInstance() { |
|
22 | - if (!self::$intance) { |
|
23 | - self::$intance = (new View); |
|
24 | - } |
|
25 | - return self::$intance; |
|
26 | - } |
|
21 | + public static function getInstance() { |
|
22 | + if (!self::$intance) { |
|
23 | + self::$intance = (new View); |
|
24 | + } |
|
25 | + return self::$intance; |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - public function __construct() { |
|
30 | - $config = Config::getInstance(); |
|
31 | - $view_engine = $config->get('views.engine'); |
|
32 | - $view_folder = $config->get('views.path_views'); |
|
33 | - $view_cache = $config->get('views.path_cache'); |
|
29 | + public function __construct() { |
|
30 | + $config = Config::getInstance(); |
|
31 | + $view_engine = $config->get('views.engine'); |
|
32 | + $view_folder = $config->get('views.path_views'); |
|
33 | + $view_cache = $config->get('views.path_cache'); |
|
34 | 34 | |
35 | - $paths = new \SplPriorityQueue(); |
|
36 | - $paths->insert($view_folder, 1); |
|
35 | + $paths = new \SplPriorityQueue(); |
|
36 | + $paths->insert($view_folder, 1); |
|
37 | 37 | |
38 | - switch ($view_engine) { |
|
39 | - case 'blade': |
|
40 | - $this->renderer = new BladeRenderer($paths, ['cache_path' => $view_cache]); |
|
41 | - break; |
|
42 | - case 'twig': |
|
43 | - $this->renderer = new TwigRenderer($paths); |
|
44 | - break; |
|
45 | - default: |
|
46 | - $this->renderer = new BladeRenderer($paths, $view_cache); |
|
47 | - break; |
|
48 | - } |
|
38 | + switch ($view_engine) { |
|
39 | + case 'blade': |
|
40 | + $this->renderer = new BladeRenderer($paths, ['cache_path' => $view_cache]); |
|
41 | + break; |
|
42 | + case 'twig': |
|
43 | + $this->renderer = new TwigRenderer($paths); |
|
44 | + break; |
|
45 | + default: |
|
46 | + $this->renderer = new BladeRenderer($paths, $view_cache); |
|
47 | + break; |
|
48 | + } |
|
49 | 49 | |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Render the view specified |
|
54 | - * |
|
55 | - * @param string $view |
|
56 | - */ |
|
57 | - public function render($view = null , $params = null) |
|
58 | - { |
|
59 | - $params = ($params) ? $params : $this->params; |
|
60 | - $view = $view ?: $this->template; |
|
61 | - echo $this->renderer->render($view, $params); |
|
62 | - } |
|
52 | + /** |
|
53 | + * Render the view specified |
|
54 | + * |
|
55 | + * @param string $view |
|
56 | + */ |
|
57 | + public function render($view = null , $params = null) |
|
58 | + { |
|
59 | + $params = ($params) ? $params : $this->params; |
|
60 | + $view = $view ?: $this->template; |
|
61 | + echo $this->renderer->render($view, $params); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Set the view file to be rendered. |
|
66 | - * |
|
67 | - * @param string $template |
|
68 | - */ |
|
69 | - public function setView($template) |
|
70 | - { |
|
71 | - $this->template = $template; |
|
72 | - } |
|
64 | + /** |
|
65 | + * Set the view file to be rendered. |
|
66 | + * |
|
67 | + * @param string $template |
|
68 | + */ |
|
69 | + public function setView($template) |
|
70 | + { |
|
71 | + $this->template = $template; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Adds a parameter in the view. |
|
76 | - * |
|
77 | - * @param string $name |
|
78 | - * @param mixed $value |
|
79 | - */ |
|
80 | - public function addParam($name, $value) |
|
81 | - { |
|
82 | - $this->params[$name] = $value; |
|
83 | - } |
|
74 | + /** |
|
75 | + * Adds a parameter in the view. |
|
76 | + * |
|
77 | + * @param string $name |
|
78 | + * @param mixed $value |
|
79 | + */ |
|
80 | + public function addParam($name, $value) |
|
81 | + { |
|
82 | + $this->params[$name] = $value; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Add array parameters in view, each position of the array will become a variable |
|
87 | - * available to the view. |
|
88 | - * |
|
89 | - * @param array $array |
|
90 | - */ |
|
91 | - public function addParams($array) |
|
92 | - { |
|
93 | - foreach ($array as $name => $value) { |
|
94 | - $this->addParam($name, $value); |
|
95 | - } |
|
96 | - } |
|
97 | - /** |
|
98 | - * Returns the specified parameter. |
|
99 | - * |
|
100 | - * @param string $name |
|
101 | - * |
|
102 | - * @return void|mixed |
|
103 | - */ |
|
104 | - public function getParam($name) |
|
105 | - { |
|
106 | - if (isset($this->params[$name])) { |
|
107 | - return $this->params[$name]; |
|
108 | - } |
|
109 | - return true; |
|
110 | - } |
|
85 | + /** |
|
86 | + * Add array parameters in view, each position of the array will become a variable |
|
87 | + * available to the view. |
|
88 | + * |
|
89 | + * @param array $array |
|
90 | + */ |
|
91 | + public function addParams($array) |
|
92 | + { |
|
93 | + foreach ($array as $name => $value) { |
|
94 | + $this->addParam($name, $value); |
|
95 | + } |
|
96 | + } |
|
97 | + /** |
|
98 | + * Returns the specified parameter. |
|
99 | + * |
|
100 | + * @param string $name |
|
101 | + * |
|
102 | + * @return void|mixed |
|
103 | + */ |
|
104 | + public function getParam($name) |
|
105 | + { |
|
106 | + if (isset($this->params[$name])) { |
|
107 | + return $this->params[$name]; |
|
108 | + } |
|
109 | + return true; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -54,7 +54,7 @@ |
||
54 | 54 | * |
55 | 55 | * @param string $view |
56 | 56 | */ |
57 | - public function render($view = null , $params = null) |
|
57 | + public function render($view = null, $params = null) |
|
58 | 58 | { |
59 | 59 | $params = ($params) ? $params : $this->params; |
60 | 60 | $view = $view ?: $this->template; |
@@ -9,52 +9,52 @@ |
||
9 | 9 | |
10 | 10 | class Safe |
11 | 11 | { |
12 | - public static $salt = 'tfju=fiM148We4oYuyojjzmA6b9UKGhQ'; |
|
12 | + public static $salt = 'tfju=fiM148We4oYuyojjzmA6b9UKGhQ'; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @param $text |
|
16 | - * |
|
17 | - * @return string |
|
18 | - */ |
|
19 | - public static function encrypt($text) { |
|
20 | - return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, self::$salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); |
|
21 | - } |
|
14 | + /** |
|
15 | + * @param $text |
|
16 | + * |
|
17 | + * @return string |
|
18 | + */ |
|
19 | + public static function encrypt($text) { |
|
20 | + return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, self::$salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param $text |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public static function decrypt($text) { |
|
29 | - return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::$salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); |
|
30 | - } |
|
23 | + /** |
|
24 | + * @param $text |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public static function decrypt($text) { |
|
29 | + return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::$salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param $value |
|
34 | - * |
|
35 | - * @return bool|string |
|
36 | - */ |
|
37 | - public static function hashEncode($value) { |
|
38 | - return password_hash($value, PASSWORD_DEFAULT); |
|
39 | - } |
|
32 | + /** |
|
33 | + * @param $value |
|
34 | + * |
|
35 | + * @return bool|string |
|
36 | + */ |
|
37 | + public static function hashEncode($value) { |
|
38 | + return password_hash($value, PASSWORD_DEFAULT); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param $array |
|
43 | - */ |
|
44 | - public static function secure(&$array) { |
|
45 | - if (isset($array)) { |
|
46 | - foreach ($array as $key => $value) { |
|
47 | - if (is_array($array[$key])) { |
|
48 | - self::secure($array[$key]); |
|
49 | - } else { |
|
50 | - $array[$key] = trim($array[$key]); |
|
51 | - $array[$key] = htmlspecialchars($array[$key], ENT_QUOTES, 'UTF-8'); |
|
52 | - $array[$key] = strip_tags($array[$key]); |
|
53 | - $array[$key] = addslashes($array[$key]); |
|
54 | - $array[$key] = filter_var($array[$key], FILTER_SANITIZE_STRING); |
|
55 | - $array[$key] = html_entity_decode($array[$key], ENT_COMPAT, 'UTF-8'); |
|
56 | - } |
|
57 | - } |
|
58 | - } |
|
59 | - } |
|
41 | + /** |
|
42 | + * @param $array |
|
43 | + */ |
|
44 | + public static function secure(&$array) { |
|
45 | + if (isset($array)) { |
|
46 | + foreach ($array as $key => $value) { |
|
47 | + if (is_array($array[$key])) { |
|
48 | + self::secure($array[$key]); |
|
49 | + } else { |
|
50 | + $array[$key] = trim($array[$key]); |
|
51 | + $array[$key] = htmlspecialchars($array[$key], ENT_QUOTES, 'UTF-8'); |
|
52 | + $array[$key] = strip_tags($array[$key]); |
|
53 | + $array[$key] = addslashes($array[$key]); |
|
54 | + $array[$key] = filter_var($array[$key], FILTER_SANITIZE_STRING); |
|
55 | + $array[$key] = html_entity_decode($array[$key], ENT_COMPAT, 'UTF-8'); |
|
56 | + } |
|
57 | + } |
|
58 | + } |
|
59 | + } |
|
60 | 60 | } |
61 | 61 | \ No newline at end of file |
@@ -21,7 +21,7 @@ |
||
21 | 21 | return self::$instance; |
22 | 22 | } |
23 | 23 | |
24 | - /** |
|
24 | + /** |
|
25 | 25 | * @param $data |
26 | 26 | * |
27 | 27 | * @return int |
@@ -9,20 +9,20 @@ |
||
9 | 9 | |
10 | 10 | class Json |
11 | 11 | { |
12 | - /** |
|
13 | - * @param $json |
|
14 | - * @param bool $group |
|
15 | - * |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public static function encode($json, $group = false) |
|
19 | - { |
|
20 | - $jsonSafed = []; |
|
21 | - if ($group) { |
|
22 | - $jsonSafed[$group] = $json; |
|
23 | - } else { |
|
24 | - $jsonSafed = $json; |
|
25 | - } |
|
26 | - return json_encode($jsonSafed, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_PRETTY_PRINT); |
|
27 | - } |
|
12 | + /** |
|
13 | + * @param $json |
|
14 | + * @param bool $group |
|
15 | + * |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public static function encode($json, $group = false) |
|
19 | + { |
|
20 | + $jsonSafed = []; |
|
21 | + if ($group) { |
|
22 | + $jsonSafed[$group] = $json; |
|
23 | + } else { |
|
24 | + $jsonSafed = $json; |
|
25 | + } |
|
26 | + return json_encode($jsonSafed, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_PRETTY_PRINT); |
|
27 | + } |
|
28 | 28 | } |
29 | 29 | \ No newline at end of file |
@@ -5,138 +5,138 @@ |
||
5 | 5 | |
6 | 6 | class Paginate extends Controller |
7 | 7 | { |
8 | - public $perPage, $currentPage, $total , $maxPage , $items , $skip; |
|
9 | - |
|
10 | - /** |
|
11 | - * Paginate constructor. |
|
12 | - */ |
|
13 | - public function __construct() { |
|
14 | - parent::__construct(); |
|
15 | - $this->setCurrentPage((isset($_GET['page']))?$_GET['page']:1); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @return mixed |
|
20 | - */ |
|
21 | - public function getItems() |
|
22 | - { |
|
23 | - return $this->items; |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * @return mixed |
|
28 | - */ |
|
29 | - public function getSkip() |
|
30 | - { |
|
31 | - return $this->skip; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @return mixed |
|
36 | - */ |
|
37 | - public function getCurrentPage() |
|
38 | - { |
|
39 | - return $this->currentPage; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @return mixed |
|
44 | - */ |
|
45 | - public function getMaxPages() |
|
46 | - { |
|
47 | - return $this->maxPage; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @return mixed |
|
52 | - */ |
|
53 | - public function getPerPage() |
|
54 | - { |
|
55 | - return $this->perPage; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return mixed |
|
60 | - */ |
|
61 | - public function getTotal() |
|
62 | - { |
|
63 | - return $this->total; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param $skip |
|
68 | - */ |
|
69 | - public function setSkip($skip) |
|
70 | - { |
|
71 | - $this->skip = $skip; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param $items |
|
76 | - */ |
|
77 | - public function setItems($items) |
|
78 | - { |
|
79 | - $count = ceil($items->count()/$this->getPerPage()); |
|
80 | - $maxPages = (!empty($this->getMaxPages()) && $count >$this->getMaxPages())?$this->getMaxPages():$count; |
|
81 | - $this->setTotal($maxPages); |
|
82 | - $this->setSkip(($this->getCurrentPage()*$this->getPerPage())-$this->getPerPage()); |
|
83 | - $this->items = $items->skip($this->getSkip())->limit($this->getPerPage())->get(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param $currentPage |
|
88 | - */ |
|
89 | - public function setCurrentPage($currentPage) |
|
90 | - { |
|
91 | - $this->currentPage = $currentPage; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param $maxPage |
|
96 | - */ |
|
97 | - public function setMaxPages($maxPage) |
|
98 | - { |
|
99 | - $this->maxPage = $maxPage; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param $perPage |
|
104 | - */ |
|
105 | - public function setPerPage($perPage) |
|
106 | - { |
|
107 | - $this->perPage = $perPage; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param $total |
|
112 | - */ |
|
113 | - public function setTotal($total) |
|
114 | - { |
|
115 | - $this->total = $total; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - public function paginate(){ |
|
120 | - if($this->getTotal() != 1) { |
|
121 | - echo /** @lang text */ '<ul class="pagination">'; |
|
122 | - if($this->getCurrentPage() > 1){ |
|
123 | - echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()-1).'" aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
|
124 | - }else{ |
|
125 | - echo /** @lang text */ '<li class="disabled"><a aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
|
126 | - } |
|
127 | - |
|
128 | - for ($i = 1; $i <= $this->getTotal(); $i++) { |
|
129 | - |
|
130 | - $active = ($this->getCurrentPage() == $i) ? 'class="active"' : ''; |
|
131 | - |
|
132 | - echo '<li ' . $active . '><a href="?page=' . $i . '">' . $i . '</a></li>'; |
|
133 | - } |
|
134 | - if($this->getCurrentPage() < $this->getTotal()){ |
|
135 | - echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()+1).'" aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
|
136 | - }else{ |
|
137 | - echo /** @lang text */ '<li class="disabled"><a aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
|
138 | - } |
|
139 | - echo '</ul>'; |
|
140 | - } |
|
141 | - } |
|
8 | + public $perPage, $currentPage, $total , $maxPage , $items , $skip; |
|
9 | + |
|
10 | + /** |
|
11 | + * Paginate constructor. |
|
12 | + */ |
|
13 | + public function __construct() { |
|
14 | + parent::__construct(); |
|
15 | + $this->setCurrentPage((isset($_GET['page']))?$_GET['page']:1); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @return mixed |
|
20 | + */ |
|
21 | + public function getItems() |
|
22 | + { |
|
23 | + return $this->items; |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * @return mixed |
|
28 | + */ |
|
29 | + public function getSkip() |
|
30 | + { |
|
31 | + return $this->skip; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @return mixed |
|
36 | + */ |
|
37 | + public function getCurrentPage() |
|
38 | + { |
|
39 | + return $this->currentPage; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @return mixed |
|
44 | + */ |
|
45 | + public function getMaxPages() |
|
46 | + { |
|
47 | + return $this->maxPage; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @return mixed |
|
52 | + */ |
|
53 | + public function getPerPage() |
|
54 | + { |
|
55 | + return $this->perPage; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return mixed |
|
60 | + */ |
|
61 | + public function getTotal() |
|
62 | + { |
|
63 | + return $this->total; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param $skip |
|
68 | + */ |
|
69 | + public function setSkip($skip) |
|
70 | + { |
|
71 | + $this->skip = $skip; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param $items |
|
76 | + */ |
|
77 | + public function setItems($items) |
|
78 | + { |
|
79 | + $count = ceil($items->count()/$this->getPerPage()); |
|
80 | + $maxPages = (!empty($this->getMaxPages()) && $count >$this->getMaxPages())?$this->getMaxPages():$count; |
|
81 | + $this->setTotal($maxPages); |
|
82 | + $this->setSkip(($this->getCurrentPage()*$this->getPerPage())-$this->getPerPage()); |
|
83 | + $this->items = $items->skip($this->getSkip())->limit($this->getPerPage())->get(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param $currentPage |
|
88 | + */ |
|
89 | + public function setCurrentPage($currentPage) |
|
90 | + { |
|
91 | + $this->currentPage = $currentPage; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param $maxPage |
|
96 | + */ |
|
97 | + public function setMaxPages($maxPage) |
|
98 | + { |
|
99 | + $this->maxPage = $maxPage; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param $perPage |
|
104 | + */ |
|
105 | + public function setPerPage($perPage) |
|
106 | + { |
|
107 | + $this->perPage = $perPage; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param $total |
|
112 | + */ |
|
113 | + public function setTotal($total) |
|
114 | + { |
|
115 | + $this->total = $total; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + public function paginate(){ |
|
120 | + if($this->getTotal() != 1) { |
|
121 | + echo /** @lang text */ '<ul class="pagination">'; |
|
122 | + if($this->getCurrentPage() > 1){ |
|
123 | + echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()-1).'" aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
|
124 | + }else{ |
|
125 | + echo /** @lang text */ '<li class="disabled"><a aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
|
126 | + } |
|
127 | + |
|
128 | + for ($i = 1; $i <= $this->getTotal(); $i++) { |
|
129 | + |
|
130 | + $active = ($this->getCurrentPage() == $i) ? 'class="active"' : ''; |
|
131 | + |
|
132 | + echo '<li ' . $active . '><a href="?page=' . $i . '">' . $i . '</a></li>'; |
|
133 | + } |
|
134 | + if($this->getCurrentPage() < $this->getTotal()){ |
|
135 | + echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()+1).'" aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
|
136 | + }else{ |
|
137 | + echo /** @lang text */ '<li class="disabled"><a aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
|
138 | + } |
|
139 | + echo '</ul>'; |
|
140 | + } |
|
141 | + } |
|
142 | 142 | } |
143 | 143 | \ No newline at end of file |
@@ -5,14 +5,14 @@ discard block |
||
5 | 5 | |
6 | 6 | class Paginate extends Controller |
7 | 7 | { |
8 | - public $perPage, $currentPage, $total , $maxPage , $items , $skip; |
|
8 | + public $perPage, $currentPage, $total, $maxPage, $items, $skip; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Paginate constructor. |
12 | 12 | */ |
13 | 13 | public function __construct() { |
14 | 14 | parent::__construct(); |
15 | - $this->setCurrentPage((isset($_GET['page']))?$_GET['page']:1); |
|
15 | + $this->setCurrentPage((isset($_GET['page'])) ? $_GET['page'] : 1); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function setItems($items) |
78 | 78 | { |
79 | - $count = ceil($items->count()/$this->getPerPage()); |
|
80 | - $maxPages = (!empty($this->getMaxPages()) && $count >$this->getMaxPages())?$this->getMaxPages():$count; |
|
79 | + $count = ceil($items->count() / $this->getPerPage()); |
|
80 | + $maxPages = (!empty($this->getMaxPages()) && $count > $this->getMaxPages()) ? $this->getMaxPages() : $count; |
|
81 | 81 | $this->setTotal($maxPages); |
82 | - $this->setSkip(($this->getCurrentPage()*$this->getPerPage())-$this->getPerPage()); |
|
83 | - $this->items = $items->skip($this->getSkip())->limit($this->getPerPage())->get(); |
|
82 | + $this->setSkip(($this->getCurrentPage() * $this->getPerPage()) - $this->getPerPage()); |
|
83 | + $this->items = $items->skip($this->getSkip())->limit($this->getPerPage())->get(); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | |
119 | - public function paginate(){ |
|
120 | - if($this->getTotal() != 1) { |
|
119 | + public function paginate() { |
|
120 | + if ($this->getTotal() != 1) { |
|
121 | 121 | echo /** @lang text */ '<ul class="pagination">'; |
122 | - if($this->getCurrentPage() > 1){ |
|
123 | - echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()-1).'" aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
|
124 | - }else{ |
|
122 | + if ($this->getCurrentPage() > 1) { |
|
123 | + echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage() - 1).'" aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
|
124 | + } else { |
|
125 | 125 | echo /** @lang text */ '<li class="disabled"><a aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
126 | 126 | } |
127 | 127 | |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | |
130 | 130 | $active = ($this->getCurrentPage() == $i) ? 'class="active"' : ''; |
131 | 131 | |
132 | - echo '<li ' . $active . '><a href="?page=' . $i . '">' . $i . '</a></li>'; |
|
132 | + echo '<li '.$active.'><a href="?page='.$i.'">'.$i.'</a></li>'; |
|
133 | 133 | } |
134 | - if($this->getCurrentPage() < $this->getTotal()){ |
|
135 | - echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()+1).'" aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
|
136 | - }else{ |
|
134 | + if ($this->getCurrentPage() < $this->getTotal()) { |
|
135 | + echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage() + 1).'" aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
|
136 | + } else { |
|
137 | 137 | echo /** @lang text */ '<li class="disabled"><a aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
138 | 138 | } |
139 | 139 | echo '</ul>'; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | echo /** @lang text */ '<ul class="pagination">'; |
122 | 122 | if($this->getCurrentPage() > 1){ |
123 | 123 | echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()-1).'" aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
124 | - }else{ |
|
124 | + } else{ |
|
125 | 125 | echo /** @lang text */ '<li class="disabled"><a aria-label="Previous"><span aria-hidden="true">Anterior</span></a></li>'; |
126 | 126 | } |
127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | if($this->getCurrentPage() < $this->getTotal()){ |
135 | 135 | echo /** @lang text */ '<li><a href="?page='.($this->getCurrentPage()+1).'" aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
136 | - }else{ |
|
136 | + } else{ |
|
137 | 137 | echo /** @lang text */ '<li class="disabled"><a aria-label="Next"><span aria-hidden="true">Próxima</span></a></li>'; |
138 | 138 | } |
139 | 139 | echo '</ul>'; |
@@ -20,20 +20,20 @@ discard block |
||
20 | 20 | |
21 | 21 | public function __construct() |
22 | 22 | { |
23 | - $di_builder = new ContainerBuilder(); |
|
24 | - $di_builder->useAutowiring(true); |
|
25 | - $this->di = $di_builder->build(); |
|
23 | + $di_builder = new ContainerBuilder(); |
|
24 | + $di_builder->useAutowiring(true); |
|
25 | + $this->di = $di_builder->build(); |
|
26 | 26 | $this->session = new Session(); |
27 | 27 | try{ |
28 | - $this->capsuleDb = new Capsule(); |
|
29 | - $this->capsuleDb->addConnection(Config::get('database.providers.pdo')); |
|
30 | - $this->capsuleDb->setEventDispatcher(new Dispatcher(new Container)); |
|
31 | - $this->capsuleDb->bootEloquent(); |
|
32 | - $this->capsuleDb->setAsGlobal(); |
|
33 | - $this->db = $this->capsuleDb->getConnection(); |
|
34 | - }catch (\PDOException $exc){ |
|
35 | - die("Database ".Config::get('database.providers.pdo.database')." not found"); |
|
36 | - } |
|
28 | + $this->capsuleDb = new Capsule(); |
|
29 | + $this->capsuleDb->addConnection(Config::get('database.providers.pdo')); |
|
30 | + $this->capsuleDb->setEventDispatcher(new Dispatcher(new Container)); |
|
31 | + $this->capsuleDb->bootEloquent(); |
|
32 | + $this->capsuleDb->setAsGlobal(); |
|
33 | + $this->db = $this->capsuleDb->getConnection(); |
|
34 | + }catch (\PDOException $exc){ |
|
35 | + die("Database ".Config::get('database.providers.pdo.database')." not found"); |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | return header('location: /' . $url); |
77 | 77 | } |
78 | 78 | |
79 | - /** |
|
80 | - * @return bool|mixed |
|
81 | - */ |
|
82 | - public function run() |
|
79 | + /** |
|
80 | + * @return bool|mixed |
|
81 | + */ |
|
82 | + public function run() |
|
83 | 83 | { |
84 | 84 | try { |
85 | 85 | |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | $controllerParams[$paramName] = $paramValue; |
108 | 108 | } |
109 | 109 | } |
110 | - $controllerFullName = "\\App\\Controllers\\" . $routerParams["_controller"]; |
|
111 | - try{ |
|
112 | - return $this->di->call($controllerFullName."::".$routerParams["_method"], $controllerParams); |
|
113 | - }catch (Exception $e){ |
|
114 | - new ExceptionHandler($e); |
|
115 | - } |
|
110 | + $controllerFullName = "\\App\\Controllers\\" . $routerParams["_controller"]; |
|
111 | + try{ |
|
112 | + return $this->di->call($controllerFullName."::".$routerParams["_method"], $controllerParams); |
|
113 | + }catch (Exception $e){ |
|
114 | + new ExceptionHandler($e); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } catch (Exception $e) { |
118 | 118 | new ExceptionHandler($e); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return true; |
122 | 122 | } |
123 | 123 | |
124 | - /** |
|
124 | + /** |
|
125 | 125 | * @param $routerParams |
126 | 126 | */ |
127 | 127 | private function handleMiddlewares($routerParams) |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | public $capsuleDb = array(); |
18 | - public $cache , $session , $di; |
|
18 | + public $cache, $session, $di; |
|
19 | 19 | private static $instance; |
20 | 20 | |
21 | 21 | public function __construct() |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | $di_builder->useAutowiring(true); |
25 | 25 | $this->di = $di_builder->build(); |
26 | 26 | $this->session = new Session(); |
27 | - try{ |
|
27 | + try { |
|
28 | 28 | $this->capsuleDb = new Capsule(); |
29 | 29 | $this->capsuleDb->addConnection(Config::get('database.providers.pdo')); |
30 | 30 | $this->capsuleDb->setEventDispatcher(new Dispatcher(new Container)); |
31 | 31 | $this->capsuleDb->bootEloquent(); |
32 | 32 | $this->capsuleDb->setAsGlobal(); |
33 | 33 | $this->db = $this->capsuleDb->getConnection(); |
34 | - }catch (\PDOException $exc){ |
|
34 | + } catch (\PDOException $exc) { |
|
35 | 35 | die("Database ".Config::get('database.providers.pdo.database')." not found"); |
36 | 36 | } |
37 | 37 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | public function redirect($url) |
74 | 74 | { |
75 | 75 | $url = str_replace(".", DS, $url); |
76 | - return header('location: /' . $url); |
|
76 | + return header('location: /'.$url); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | $controllerParams[$paramName] = $paramValue; |
108 | 108 | } |
109 | 109 | } |
110 | - $controllerFullName = "\\App\\Controllers\\" . $routerParams["_controller"]; |
|
111 | - try{ |
|
110 | + $controllerFullName = "\\App\\Controllers\\".$routerParams["_controller"]; |
|
111 | + try { |
|
112 | 112 | return $this->di->call($controllerFullName."::".$routerParams["_method"], $controllerParams); |
113 | - }catch (Exception $e){ |
|
113 | + } catch (Exception $e) { |
|
114 | 114 | new ExceptionHandler($e); |
115 | 115 | } |
116 | 116 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $this->capsuleDb->bootEloquent(); |
32 | 32 | $this->capsuleDb->setAsGlobal(); |
33 | 33 | $this->db = $this->capsuleDb->getConnection(); |
34 | - }catch (\PDOException $exc){ |
|
34 | + } catch (\PDOException $exc){ |
|
35 | 35 | die("Database ".Config::get('database.providers.pdo.database')." not found"); |
36 | 36 | } |
37 | 37 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $controllerFullName = "\\App\\Controllers\\" . $routerParams["_controller"]; |
111 | 111 | try{ |
112 | 112 | return $this->di->call($controllerFullName."::".$routerParams["_method"], $controllerParams); |
113 | - }catch (Exception $e){ |
|
113 | + } catch (Exception $e){ |
|
114 | 114 | new ExceptionHandler($e); |
115 | 115 | } |
116 | 116 |