@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * Lectura y escritura de caché para Twig |
48 | 48 | */ |
49 | -if(!is_writable(API_INTERFACE . 'app/templates/.cache/') || !is_readable(API_INTERFACE . 'app/templates/.cache/')) { |
|
49 | +if (!is_writable(API_INTERFACE . 'app/templates/.cache/') || !is_readable(API_INTERFACE . 'app/templates/.cache/')) { |
|
50 | 50 | throw new \RuntimeException('Debe conceder permisos de escritura y lectura a la ruta ' . API_INTERFACE . 'app/templates/.cache/ ó crearla si no existe.'); |
51 | 51 | } |
52 | 52 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * Estatus del DEBUG |
84 | 84 | */ |
85 | -if($config['framework']['debug']) { |
|
85 | +if ($config['framework']['debug']) { |
|
86 | 86 | Debug::enable(); |
87 | 87 | } |
88 | 88 |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $this->template->addGlobal('is_logged', $this->is_logged); |
115 | 115 | |
116 | 116 | # Datos del usuario actual |
117 | - if($this->is_logged) { |
|
117 | + if ($this->is_logged) { |
|
118 | 118 | $this->user = (new Model\Users)->getOwnerUser(); |
119 | 119 | $this->template->addGlobal('owner_user', $this->user); |
120 | 120 | } |
@@ -145,17 +145,17 @@ discard block |
||
145 | 145 | $this->controllerConfig['users_not_logged'] = false; |
146 | 146 | |
147 | 147 | # Establecer las configuraciones pasadas |
148 | - if(null != $config) { |
|
148 | + if (null != $config) { |
|
149 | 149 | # Configura el autoreload del caché de twig |
150 | - if(array_key_exists('twig_cache_reload',$config)) { |
|
150 | + if (array_key_exists('twig_cache_reload', $config)) { |
|
151 | 151 | $this->controllerConfig['twig_cache_reload'] = (bool) $config['twig_cache_reload']; |
152 | 152 | } |
153 | 153 | # Configura el controlador para solo ser visto por usuarios logeados |
154 | - if(array_key_exists('users_logged',$config)) { |
|
154 | + if (array_key_exists('users_logged', $config)) { |
|
155 | 155 | $this->controllerConfig['users_logged'] = (bool) $config['users_logged']; |
156 | 156 | } |
157 | 157 | # Configura el controlador para solo ser visto por usuario no logeados |
158 | - if(array_key_exists('users_not_logged',$config)) { |
|
158 | + if (array_key_exists('users_not_logged', $config)) { |
|
159 | 159 | $this->controllerConfig['users_not_logged'] = (bool) $config['users_not_logged']; |
160 | 160 | } |
161 | 161 | } |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | */ |
169 | 169 | private function knowVisitorPermissions() { |
170 | 170 | # Sólamente usuarios logeados |
171 | - if($this->controllerConfig['users_logged'] && !$this->is_logged) { |
|
171 | + if ($this->controllerConfig['users_logged'] && !$this->is_logged) { |
|
172 | 172 | $this->functions->redir(); |
173 | 173 | } |
174 | 174 | |
175 | 175 | # Sólamente usuarios no logeados |
176 | - if($this->controllerConfig['users_not_logged'] && $this->is_logged) { |
|
176 | + if ($this->controllerConfig['users_not_logged'] && $this->is_logged) { |
|
177 | 177 | $this->functions->redir(); |
178 | 178 | } |
179 | 179 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $mail->CharSet = "UTF-8"; |
36 | 36 | $mail->Encoding = "quoted-printable"; |
37 | 37 | |
38 | - if($is_smtp) { |
|
38 | + if ($is_smtp) { |
|
39 | 39 | $mail->isSMTP(); |
40 | 40 | $mail->SMTPAuth = true; |
41 | 41 | $mail->Host = $config['phpmailer']['host']; |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | $mail->Subject = $titulo; |
89 | 89 | $mail->Body = $HTML; |
90 | 90 | |
91 | - if(sizeof($adj)) { |
|
91 | + if (sizeof($adj)) { |
|
92 | 92 | foreach ($adj as $ruta) { |
93 | 93 | $mail->AddAttachment($ruta); |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | - if(!$mail->send()) { |
|
97 | + if (!$mail->send()) { |
|
98 | 98 | return $mail->ErrorInfo; |
99 | 99 | } |
100 | 100 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | </head> |
119 | 119 | <body style="font-family: Verdana;"> |
120 | 120 | <section> |
121 | - '.$content.' |
|
121 | + '.$content . ' |
|
122 | 122 | </section> |
123 | 123 | </body> |
124 | 124 | </html>'; |
@@ -55,16 +55,16 @@ |
||
55 | 55 | $this->databaseConfig['new_instance'] = false; |
56 | 56 | |
57 | 57 | # Añadir según lo pasado por $databaseConfig |
58 | - if(is_array($databaseConfig)) { |
|
59 | - if(array_key_exists('name',$databaseConfig)) { |
|
60 | - $this->databaseConfig['name'] = $databaseConfig['name']; |
|
58 | + if (is_array($databaseConfig)) { |
|
59 | + if (array_key_exists('name', $databaseConfig)) { |
|
60 | + $this->databaseConfig['name'] = $databaseConfig['name']; |
|
61 | 61 | } |
62 | 62 | |
63 | - if(array_key_exists('motor',$databaseConfig)) { |
|
64 | - $this->databaseConfig['motor'] = $databaseConfig['motor']; |
|
63 | + if (array_key_exists('motor', $databaseConfig)) { |
|
64 | + $this->databaseConfig['motor'] = $databaseConfig['motor']; |
|
65 | 65 | } |
66 | 66 | |
67 | - if(array_key_exists('new_instance',$databaseConfig)) { |
|
67 | + if (array_key_exists('new_instance', $databaseConfig)) { |
|
68 | 68 | $this->databaseConfig['new_instance'] = (bool) $databaseConfig['new_instance']; |
69 | 69 | } |
70 | 70 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @throws ModelsException cuando las contraseñas no coinciden |
74 | 74 | */ |
75 | 75 | private function checkPassMatch(string $pass, string $pass_repeat) { |
76 | - if($pass != $pass_repeat) { |
|
76 | + if ($pass != $pass_repeat) { |
|
77 | 77 | throw new ModelsException('Las contraseñas no coinciden.'); |
78 | 78 | } |
79 | 79 | } |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | */ |
88 | 88 | private function checkEmail(string $email) { |
89 | 89 | # Formato de email |
90 | - if(!Strings::is_email($email)) { |
|
90 | + if (!Strings::is_email($email)) { |
|
91 | 91 | throw new ModelsException('El email no tiene un formato válido.'); |
92 | 92 | } |
93 | 93 | # Existencia de email |
94 | 94 | $email = $this->db->scape($email); |
95 | - $query = $this->db->select('id_user','users',"email='$email'",'LIMIT 1'); |
|
96 | - if(false !== $query) { |
|
95 | + $query = $this->db->select('id_user', 'users', "email='$email'", 'LIMIT 1'); |
|
96 | + if (false !== $query) { |
|
97 | 97 | throw new ModelsException('El email introducido ya existe.'); |
98 | 98 | } |
99 | 99 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @return void |
108 | 108 | */ |
109 | 109 | private function restoreAttempts(string $email) { |
110 | - if(array_key_exists($email,$this->recentAttempts)) { |
|
110 | + if (array_key_exists($email, $this->recentAttempts)) { |
|
111 | 111 | $this->recentAttempts[$email]['attempts'] = 0; |
112 | 112 | $this->recentAttempts[$email]['time'] = null; |
113 | 113 | $this->updateSessionAttempts(); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | private function generateSession(array $user_data) { |
128 | 128 | global $session, $config; |
129 | 129 | |
130 | - $session->set('user_id',(int) $user_data['id_user']); |
|
130 | + $session->set('user_id', (int) $user_data['id_user']); |
|
131 | 131 | $session->set('unique_session', $config['sessions']['unique']); |
132 | 132 | } |
133 | 133 | |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * @return bool true: Cuando el inicio de sesión es correcto |
141 | 141 | * false: Cuando el inicio de sesión no es correcto |
142 | 142 | */ |
143 | - private function authentication(string $email,string $pass) : bool { |
|
143 | + private function authentication(string $email, string $pass) : bool { |
|
144 | 144 | $email = $this->db->scape($email); |
145 | - $query = $this->db->select('id_user,pass','users',"email='$email'",'LIMIT 1'); |
|
145 | + $query = $this->db->select('id_user,pass', 'users', "email='$email'", 'LIMIT 1'); |
|
146 | 146 | |
147 | 147 | # Incio de sesión con éxito |
148 | - if(false !== $query && Strings::chash($query[0]['pass'],$pass)) { |
|
148 | + if (false !== $query && Strings::chash($query[0]['pass'], $pass)) { |
|
149 | 149 | |
150 | 150 | # Restaurar intentos |
151 | 151 | $this->restoreAttempts($email); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | private function setDefaultAttempts() { |
167 | 167 | global $session; |
168 | 168 | |
169 | - if(null != $session->get('login_user_recentAttempts')) { |
|
169 | + if (null != $session->get('login_user_recentAttempts')) { |
|
170 | 170 | $this->recentAttempts = $session->get('login_user_recentAttempts'); |
171 | 171 | } |
172 | 172 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | */ |
181 | 181 | private function setNewAttempt(string $email) { |
182 | - if(!array_key_exists($email,$this->recentAttempts)) { |
|
182 | + if (!array_key_exists($email, $this->recentAttempts)) { |
|
183 | 183 | $this->recentAttempts[$email] = array( |
184 | 184 | 'attempts' => 0, # Intentos |
185 | 185 | 'time' => null # Tiempo |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * @return void |
201 | 201 | */ |
202 | 202 | private function maximumAttempts(string $email) { |
203 | - if($this->recentAttempts[$email]['attempts'] >= self::MAX_ATTEMPTS) { |
|
203 | + if ($this->recentAttempts[$email]['attempts'] >= self::MAX_ATTEMPTS) { |
|
204 | 204 | |
205 | 205 | # Colocar timestamp para recuperar más adelante la posibilidad de acceso |
206 | - if(null == $this->recentAttempts[$email]['time']) { |
|
206 | + if (null == $this->recentAttempts[$email]['time']) { |
|
207 | 207 | $this->recentAttempts[$email]['time'] = time() + self::MAX_ATTEMPTS_TIME; |
208 | 208 | } |
209 | 209 | |
210 | - if(time() < $this->recentAttempts[$email]['time']) { |
|
210 | + if (time() < $this->recentAttempts[$email]['time']) { |
|
211 | 211 | # Setear sesión |
212 | 212 | $this->updateSessionAttempts(); |
213 | 213 | # Lanzar excepción |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $pass = $http->request->get('pass'); |
236 | 236 | |
237 | 237 | # Verificar que no están vacíos |
238 | - if($this->functions->e($email,$pass)) { |
|
238 | + if ($this->functions->e($email, $pass)) { |
|
239 | 239 | throw new ModelsException('Credenciales incompletas.'); |
240 | 240 | } |
241 | 241 | |
@@ -246,13 +246,13 @@ discard block |
||
246 | 246 | $this->maximumAttempts($email); |
247 | 247 | |
248 | 248 | # Autentificar |
249 | - if($this->authentication($email,$pass)) { |
|
249 | + if ($this->authentication($email, $pass)) { |
|
250 | 250 | return array('success' => 1, 'message' => 'Conectado con éxito.'); |
251 | 251 | } |
252 | 252 | |
253 | 253 | throw new ModelsException('Credenciales incorrectas.'); |
254 | 254 | |
255 | - } catch(ModelsException $e) { |
|
255 | + } catch (ModelsException $e) { |
|
256 | 256 | return array('success' => 0, 'message' => $e->getMessage()); |
257 | 257 | } |
258 | 258 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $pass_repeat = $http->request->get('pass_repeat'); |
274 | 274 | |
275 | 275 | # Verificar que no están vacíos |
276 | - if($this->functions->e($name,$email,$pass,$pass_repeat)) { |
|
276 | + if ($this->functions->e($name, $email, $pass, $pass_repeat)) { |
|
277 | 277 | throw new ModelsException('Todos los datos son necesarios'); |
278 | 278 | } |
279 | 279 | |
@@ -281,10 +281,10 @@ discard block |
||
281 | 281 | $this->checkEmail($email); |
282 | 282 | |
283 | 283 | # Veriricar contraseñas |
284 | - $this->checkPassMatch($pass,$pass_repeat); |
|
284 | + $this->checkPassMatch($pass, $pass_repeat); |
|
285 | 285 | |
286 | 286 | # Registrar al usuario |
287 | - $this->db->insert('users',array( |
|
287 | + $this->db->insert('users', array( |
|
288 | 288 | 'name' => $name, |
289 | 289 | 'email' => $email, |
290 | 290 | 'pass' => Strings::hash($pass) |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | )); |
297 | 297 | |
298 | 298 | return array('success' => 1, 'message' => 'Registrado con éxito.'); |
299 | - } catch(ModelsException $e) { |
|
299 | + } catch (ModelsException $e) { |
|
300 | 300 | return array('success' => 0, 'message' => $e->getMessage()); |
301 | 301 | } |
302 | 302 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | $email = $http->request->get('email'); |
316 | 316 | |
317 | 317 | # Campo lleno |
318 | - if($this->functions->emp($email)) { |
|
318 | + if ($this->functions->emp($email)) { |
|
319 | 319 | throw new ModelsException('El campo email debe estar lleno.'); |
320 | 320 | } |
321 | 321 | |
@@ -323,10 +323,10 @@ discard block |
||
323 | 323 | $email = $this->db->scape($email); |
324 | 324 | |
325 | 325 | # Obtener información del usuario |
326 | - $user_data = $this->db->select('id_user,name','users',"email='$email'",'LIMIT 1'); |
|
326 | + $user_data = $this->db->select('id_user,name', 'users', "email='$email'", 'LIMIT 1'); |
|
327 | 327 | |
328 | 328 | # Verificar correo en base de datos |
329 | - if(false === $user_data) { |
|
329 | + if (false === $user_data) { |
|
330 | 330 | throw new ModelsException('El email no está registrado en el sistema.'); |
331 | 331 | } |
332 | 332 | |
@@ -335,30 +335,30 @@ discard block |
||
335 | 335 | $pass = uniqid(); |
336 | 336 | |
337 | 337 | # Construir mensaje y enviar mensaje |
338 | - $HTML = 'Hola <b>'. $user_data[0]['name'] .'</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
338 | + $HTML = 'Hola <b>' . $user_data[0]['name'] . '</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
339 | 339 | <br /> |
340 | 340 | <br /> |
341 | - Para cambiar su contraseña por <b>'. $pass .'</b> haga <a href="'. $config['site']['url'] . 'lostpass/cambiar/&token='.$token.'&user='.$user_data[0]['id_user'].'" target="_blank">clic aquí</a>.'; |
|
341 | + Para cambiar su contraseña por <b>'. $pass . '</b> haga <a href="' . $config['site']['url'] . 'lostpass/cambiar/&token=' . $token . '&user=' . $user_data[0]['id_user'] . '" target="_blank">clic aquí</a>.'; |
|
342 | 342 | |
343 | 343 | # Enviar el correo electrónico |
344 | 344 | $dest = array(); |
345 | 345 | $dest[$email] = $user_data[0]['name']; |
346 | - $email = Emails::send_mail($dest,Emails::plantilla($HTML),'Recuperar contraseña perdida'); |
|
346 | + $email = Emails::send_mail($dest, Emails::plantilla($HTML), 'Recuperar contraseña perdida'); |
|
347 | 347 | |
348 | 348 | # Verificar si hubo algún problema con el envío del correo |
349 | - if(false === $email) { |
|
349 | + if (false === $email) { |
|
350 | 350 | throw new ModelsException('No se ha podido enviar el correo electrónico.'); |
351 | 351 | } |
352 | 352 | |
353 | 353 | # Actualizar datos |
354 | 354 | $id_user = $user_data[0]['id_user']; |
355 | - $this->db->update('users',array( |
|
355 | + $this->db->update('users', array( |
|
356 | 356 | 'tmp_pass' => Strings::hash($pass), |
357 | 357 | 'token' => $token |
358 | - ),"id_user='$id_user'",'LIMIT 1'); |
|
358 | + ), "id_user='$id_user'", 'LIMIT 1'); |
|
359 | 359 | |
360 | 360 | return array('success' => 1, 'message' => 'Se ha enviado un enlace a su correo electrónico.'); |
361 | - } catch(ModelsException $e) { |
|
361 | + } catch (ModelsException $e) { |
|
362 | 362 | return array('success' => 0, 'message' => $e->getMessage()); |
363 | 363 | } |
364 | 364 | } |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $id_user = $http->query->get('user'); |
379 | 379 | $token = $http->query->get('token'); |
380 | 380 | |
381 | - if(!$this->functions->emp($token) && is_numeric($id_user) && $id_user >= 1) { |
|
381 | + if (!$this->functions->emp($token) && is_numeric($id_user) && $id_user >= 1) { |
|
382 | 382 | # Filtros a los datos |
383 | 383 | $id_user = $this->db->scape($id_user); |
384 | 384 | $token = $this->db->scape($token); |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | public function logout() { |
402 | 402 | global $session; |
403 | 403 | |
404 | - if(null != $session->get('user_id')) { |
|
404 | + if (null != $session->get('user_id')) { |
|
405 | 405 | $session->remove('user_id'); |
406 | 406 | } |
407 | 407 | |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | * @return false|array con información del usuario |
418 | 418 | */ |
419 | 419 | public function getUserById(int $id, string $select = '*') { |
420 | - return $this->db->select($select,'users',"id_user='$id'",'LIMIT 1'); |
|
420 | + return $this->db->select($select, 'users', "id_user='$id'", 'LIMIT 1'); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * @return false|array con información de los usuarios |
429 | 429 | */ |
430 | 430 | public function getUsers(string $select = '*') { |
431 | - return $this->db->select($select,'users'); |
|
431 | + return $this->db->select($select, 'users'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | * @return array con datos del usuario conectado |
441 | 441 | */ |
442 | 442 | public function getOwnerUser(string $select = '*') : array { |
443 | - if(null !== $this->id_user) { |
|
443 | + if (null !== $this->id_user) { |
|
444 | 444 | |
445 | - $user = $this->db->select($select,'users',"id_user='$this->id_user'",'LIMIT 1'); |
|
445 | + $user = $this->db->select($select, 'users', "id_user='$this->id_user'", 'LIMIT 1'); |
|
446 | 446 | |
447 | 447 | # Si se borra al usuario desde la base de datos y sigue con la sesión activa |
448 | - if(false === $user) { |
|
448 | + if (false === $user) { |
|
449 | 449 | $this->logout(); |
450 | 450 | } |
451 | 451 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | * @throws \RuntimeException si no se puede realizar la query |
462 | 462 | */ |
463 | 463 | public function install() { |
464 | - if(!$this->db->query(" |
|
464 | + if (!$this->db->query(" |
|
465 | 465 | CREATE TABLE IF NOT EXISTS `users` ( |
466 | 466 | `id_user` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, |
467 | 467 | `name` varchar(100) NOT NULL, |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @author Brayan Narváez <[email protected]> |
21 | 21 | */ |
22 | 22 | |
23 | -abstract class Models { |
|
23 | +abstract class Models { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Tiene siempre el id pasado por la ruta, en caso de no haber ninguno, será cero. |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | global $session, $config; |
54 | 54 | |
55 | 55 | # Id captado por la ruta |
56 | - if(null != $router) { |
|
56 | + if (null != $router) { |
|
57 | 57 | $this->id = $router->getId(true); |
58 | 58 | $this->id = null == $this->id ? 0 : $this->id; |
59 | 59 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $this->functions = new Functions(); |
63 | 63 | |
64 | 64 | # Verificar sesión del usuario |
65 | - if(null !== $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) { |
|
65 | + if (null !== $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) { |
|
66 | 66 | $this->id_user = $session->get('user_id'); |
67 | 67 | } |
68 | 68 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @throws ModelsException |
78 | 78 | */ |
79 | 79 | protected function setId($id, string $default_msg = 'No puedede asignarse el id.') { |
80 | - if(null == $id || !is_numeric($id) || $id <= 0) { |
|
80 | + if (null == $id || !is_numeric($id) || $id <= 0) { |
|
81 | 81 | throw new ModelsException($default_msg); |
82 | 82 | } |
83 | 83 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return int catidad de bytes escritos en el archivo |
49 | 49 | */ |
50 | 50 | final public static function write_file(string $dir, string $content) : int { |
51 | - $f = new \SplFileObject($dir,'w'); |
|
51 | + $f = new \SplFileObject($dir, 'w'); |
|
52 | 52 | return (int) $f->fwrite($content); |
53 | 53 | } |
54 | 54 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return bool true si borró el fichero, false si no (porque no existía) |
63 | 63 | */ |
64 | 64 | final public static function delete_file(string $route) : bool { |
65 | - if(file_exists($route)) { |
|
65 | + if (file_exists($route)) { |
|
66 | 66 | unlink($route); |
67 | 67 | |
68 | 68 | return true; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return bool true si es una imagen, false si no lo es |
95 | 95 | */ |
96 | 96 | final public static function is_image(string $file_name) : bool { |
97 | - return (bool) in_array(self::get_file_ext($file_name),['jpg','png','jpeg','gif','JPG','PNG','JPEG','GIF']); |
|
97 | + return (bool) in_array(self::get_file_ext($file_name), ['jpg', 'png', 'jpeg', 'gif', 'JPG', 'PNG', 'JPEG', 'GIF']); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | //------------------------------------------------ |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | final public static function get_files_in_dir(string $dir, string $types = '') : array { |
137 | 137 | $array = array(); |
138 | - if(is_dir($dir)) { |
|
138 | + if (is_dir($dir)) { |
|
139 | 139 | foreach (glob($dir . '*' . $types) as $file) { |
140 | 140 | $array[] = $file; |
141 | 141 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @return bool con true si fue creado con éxito, false si el directorio ya existía o hubo algún error |
155 | 155 | */ |
156 | 156 | final public static function create_dir(string $dir, int $permisos = 0755) : bool { |
157 | - if(is_dir($dir)) { |
|
157 | + if (is_dir($dir)) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
161 | - return (bool) mkdir($dir,$permisos,true); |
|
161 | + return (bool) mkdir($dir, $permisos, true); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | //------------------------------------------------ |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | final public static function rm_dir(string $dir) { |
176 | 176 | |
177 | 177 | # Evitar una desgracia |
178 | - if(in_array($dir,[ |
|
178 | + if (in_array($dir, [ |
|
179 | 179 | 'Ocrend/', |
180 | 180 | 'Ocrend/Kernel/', |
181 | 181 | 'Ocrend/vendor/', |
@@ -188,10 +188,10 @@ discard block |
||
188 | 188 | throw new \RuntimeException('No puede eliminar la ruta ' . $dir . ' ya que es crítica.'); |
189 | 189 | } |
190 | 190 | |
191 | - foreach(glob($dir . "/*") as $archivos_carpeta) { |
|
192 | - if (is_dir($archivos_carpeta)) { |
|
191 | + foreach (glob($dir . "/*") as $archivos_carpeta) { |
|
192 | + if (is_dir($archivos_carpeta)) { |
|
193 | 193 | self::rm_dir($archivos_carpeta); |
194 | - } else { |
|
194 | + } else { |
|
195 | 195 | unlink($archivos_carpeta); |
196 | 196 | } |
197 | 197 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @return int cantidad de imágenes |
211 | 211 | */ |
212 | 212 | final public static function images_in_dir(string $dir) : int { |
213 | - return sizeof(glob($dir . '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}',GLOB_BRACE)); |
|
213 | + return sizeof(glob($dir . '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}', GLOB_BRACE)); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | //------------------------------------------------ |
@@ -230,16 +230,16 @@ discard block |
||
230 | 230 | |
231 | 231 | self::create_dir($new_dir); |
232 | 232 | |
233 | - foreach(glob($old_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'),GLOB_BRACE) as $file) { |
|
234 | - if(file_exists($file)) { |
|
233 | + foreach (glob($old_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'), GLOB_BRACE) as $file) { |
|
234 | + if (file_exists($file)) { |
|
235 | 235 | unlink($file); |
236 | 236 | } |
237 | 237 | |
238 | - $name = explode('/',$file); |
|
238 | + $name = explode('/', $file); |
|
239 | 239 | $name = end($name); |
240 | - copy($file,$new_dir . $name); |
|
240 | + copy($file, $new_dir . $name); |
|
241 | 241 | |
242 | - if($delete_old) { |
|
242 | + if ($delete_old) { |
|
243 | 243 | unlink($file); |
244 | 244 | } |
245 | 245 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | final private function setCollectionRule(string $index, string $rule) { |
94 | 94 | # Verificar si la regla existe |
95 | - if(!in_array($rule,self::RULES)) { |
|
95 | + if (!in_array($rule, self::RULES)) { |
|
96 | 96 | throw new \RuntimeException('La regla ' . $rule . ' no existe.'); |
97 | 97 | } |
98 | 98 | # Definir la regla para la ruta |
@@ -104,14 +104,14 @@ discard block |
||
104 | 104 | */ |
105 | 105 | final private function checkRequests() { |
106 | 106 | # Verificar si existe peticiones |
107 | - if(null !== $this->requestUri) { |
|
108 | - $this->real_request = explode('/',$this->requestUri); |
|
107 | + if (null !== $this->requestUri) { |
|
108 | + $this->real_request = explode('/', $this->requestUri); |
|
109 | 109 | $this->routerCollection['/controller'] = $this->real_request[0]; |
110 | 110 | } |
111 | 111 | |
112 | 112 | # Setear las siguientes rutas |
113 | - $this->routerCollection['/method'] = array_key_exists(1,$this->real_request) ? $this->real_request[1] : null; |
|
114 | - $this->routerCollection['/id'] = array_key_exists(2,$this->real_request) ? $this->real_request[2] : null; |
|
113 | + $this->routerCollection['/method'] = array_key_exists(1, $this->real_request) ? $this->real_request[1] : null; |
|
114 | + $this->routerCollection['/id'] = array_key_exists(2, $this->real_request) ? $this->real_request[2] : null; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | final public function setRoute(string $index, string $rule = 'none') { |
126 | 126 | # Nombres de rutas no permitidos |
127 | - if(in_array($index,['/controller','/method','/id'])) { |
|
127 | + if (in_array($index, ['/controller', '/method', '/id'])) { |
|
128 | 128 | throw new \RuntimeException('No puede definirse ' . $index . ' como índice en la ruta.'); |
129 | 129 | } |
130 | 130 | |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | |
137 | 137 | # Definir la ruta y regla |
138 | 138 | $lastRoute = sizeof($this->routerCollection); |
139 | - $this->routerCollection[$index] = array_key_exists($lastRoute,$this->real_request) ? $this->real_request[$lastRoute] : null; |
|
140 | - $this->setCollectionRule($index,$rule); |
|
139 | + $this->routerCollection[$index] = array_key_exists($lastRoute, $this->real_request) ? $this->real_request[$lastRoute] : null; |
|
140 | + $this->setCollectionRule($index, $rule); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | final public function getRoute(string $index) { |
152 | 152 | # Verificar existencia de ruta |
153 | - if(!array_key_exists($index,$this->routerCollection)) { |
|
153 | + if (!array_key_exists($index, $this->routerCollection)) { |
|
154 | 154 | throw new \RuntimeException('La ruta ' . $index . ' no está definida en el controlador.'); |
155 | 155 | } |
156 | 156 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $rules = new Rules; |
160 | 160 | |
161 | 161 | # Retornar ruta con la regla definida aplicada |
162 | - if(method_exists($rules, $this->routerCollectionRules[$index])) { |
|
162 | + if (method_exists($rules, $this->routerCollectionRules[$index])) { |
|
163 | 163 | return $rules->{$this->routerCollectionRules[$index]}($ruta); |
164 | 164 | } |
165 | 165 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | final public function getId(bool $with_rules = false) { |
200 | 200 | $id = $this->routerCollection['/id']; |
201 | - if($with_rules && (!is_numeric($id) || $id <= 0)) { |
|
201 | + if ($with_rules && (!is_numeric($id) || $id <= 0)) { |
|
202 | 202 | return null; |
203 | 203 | } |
204 | 204 | |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | */ |
213 | 213 | final public function executeController() { |
214 | 214 | # Definir controlador |
215 | - if(null != ($controller = $this->getController())) { |
|
215 | + if (null != ($controller = $this->getController())) { |
|
216 | 216 | $controller = $controller . 'Controller'; |
217 | 217 | |
218 | - if(!is_readable('app/controllers/' . $controller . '.php')) { |
|
218 | + if (!is_readable('app/controllers/' . $controller . '.php')) { |
|
219 | 219 | $controller = 'errorController'; |
220 | 220 | } |
221 | 221 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | final public static function Start($name = null, $motor = null, bool $new_instance = false) : Database { |
40 | 40 | global $config; |
41 | 41 | |
42 | - if(!self::$inst instanceof self or $new_instance) { |
|
42 | + if (!self::$inst instanceof self or $new_instance) { |
|
43 | 43 | self::$inst = new self( |
44 | 44 | null === $name ? $config['database']['name'] : $name, |
45 | 45 | null === $motor ? $config['database']['motor'] : $motor |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param array $params: Lista de parámetros de configuración |
56 | 56 | */ |
57 | 57 | final private function motor_mysql(array $params) { |
58 | - parent::__construct('mysql:host='.$params['host'].';dbname='.$params['name'], |
|
58 | + parent::__construct('mysql:host=' . $params['host'] . ';dbname=' . $params['name'], |
|
59 | 59 | $params['user'], |
60 | 60 | $params['pass'], |
61 | 61 | array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param array $params: Lista de parámetros de configuración |
71 | 71 | */ |
72 | 72 | final private function motor_sqlite(array $params) { |
73 | - parent::__construct('sqlite:'.$params['name']); |
|
73 | + parent::__construct('sqlite:' . $params['name']); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * @param array $params: Lista de parámetros de configuración |
80 | 80 | */ |
81 | 81 | final private function motor_cubrid(array $params) { |
82 | - parent::__construct('cubrid:host='.$params['host'].';dbname='.$params['name'].';port='.$params['port'], |
|
82 | + parent::__construct('cubrid:host=' . $params['host'] . ';dbname=' . $params['name'] . ';port=' . $params['port'], |
|
83 | 83 | $params['user'], |
84 | - $params['pass'],array( |
|
84 | + $params['pass'], array( |
|
85 | 85 | \PDO::ATTR_EMULATE_PREPARES => false, |
86 | 86 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
87 | 87 | )); |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | * @param array $params: Lista de parámetros de configuración |
94 | 94 | */ |
95 | 95 | final private function motor_firebird(array $params) { |
96 | - parent::__construct('firebird:dbname='.$params['host'].':'.$params['name'], |
|
96 | + parent::__construct('firebird:dbname=' . $params['host'] . ':' . $params['name'], |
|
97 | 97 | $params['user'], |
98 | - $params['pass'],array( |
|
98 | + $params['pass'], array( |
|
99 | 99 | \PDO::ATTR_EMULATE_PREPARES => false, |
100 | 100 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
101 | 101 | )); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param array $params: Lista de parámetros de configuración |
108 | 108 | */ |
109 | 109 | final private function motor_odbc(array $params) { |
110 | - parent::__construct('odbc:'.$params['name'], |
|
110 | + parent::__construct('odbc:' . $params['name'], |
|
111 | 111 | $params['user'], |
112 | 112 | $params['pass'] |
113 | 113 | ); |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | final private function motor_oracle(array $params) { |
122 | 122 | parent::__construct('oci:dbname=(DESCRIPTION = |
123 | 123 | (ADDRESS_LIST = |
124 | - (ADDRESS = (PROTOCOL = '.$params['protocol'].')(HOST = '.$params['host'].')(PORT = '.$params['port'].')) |
|
124 | + (ADDRESS = (PROTOCOL = '.$params['protocol'] . ')(HOST = ' . $params['host'] . ')(PORT = ' . $params['port'] . ')) |
|
125 | 125 | ) |
126 | 126 | (CONNECT_DATA = |
127 | - (SERVICE_NAME = '.$params['name'].') |
|
127 | + (SERVICE_NAME = '.$params['name'] . ') |
|
128 | 128 | ) |
129 | - );charset=utf8',$params['database']['user'],$params['database']['pass'], |
|
129 | + );charset=utf8',$params['database']['user'], $params['database']['pass'], |
|
130 | 130 | array(\PDO::ATTR_EMULATE_PREPARES => false, |
131 | 131 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, |
132 | 132 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * @param array $params: Lista de parámetros de configuración |
140 | 140 | */ |
141 | 141 | final private function motor_postgresql(array $params) { |
142 | - parent::__construct('pgsql:host='.$params['host'].';dbname='.$params['name'].';charset=utf8', |
|
142 | + parent::__construct('pgsql:host=' . $params['host'] . ';dbname=' . $params['name'] . ';charset=utf8', |
|
143 | 143 | $params['user'], |
144 | - $params['pass'],array( |
|
144 | + $params['pass'], array( |
|
145 | 145 | \PDO::ATTR_EMULATE_PREPARES => false, |
146 | 146 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
147 | 147 | )); |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | * @param array $params: Lista de parámetros de configuración |
155 | 155 | */ |
156 | 156 | final private function motor_mssql(array $params) { |
157 | - parent::__construct('sqlsrv:Server='.$params['host'].';Database='.$params['name'].';ConnectionPooling=0', |
|
157 | + parent::__construct('sqlsrv:Server=' . $params['host'] . ';Database=' . $params['name'] . ';ConnectionPooling=0', |
|
158 | 158 | $params['user'], |
159 | - $params['pass'],array(\PDO::ATTR_EMULATE_PREPARES => false, |
|
159 | + $params['pass'], array(\PDO::ATTR_EMULATE_PREPARES => false, |
|
160 | 160 | \PDO::SQLSRV_ENCODING_UTF8, |
161 | 161 | \PDO::ATTR_ERRMODE => |
162 | 162 | \PDO::ERRMODE_EXCEPTION |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | try { |
181 | 181 | # Verificar existencia del motor |
182 | - if(method_exists($this,'motor_' . $motor)) { |
|
182 | + if (method_exists($this, 'motor_' . $motor)) { |
|
183 | 183 | $this->{'motor_' . $motor}(array( |
184 | 184 | 'host' => $config['database']['host'], |
185 | 185 | 'name' => $name, |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | 'protocol' => $config['database']['protocol'] |
190 | 190 | )); |
191 | 191 | } else { |
192 | - throw new \RuntimeException('Motor '. $motor .' de conexión no identificado.'); |
|
192 | + throw new \RuntimeException('Motor ' . $motor . ' de conexión no identificado.'); |
|
193 | 193 | } |
194 | - } catch(\PDOException $e) { |
|
194 | + } catch (\PDOException $e) { |
|
195 | 195 | throw new \RuntimeException('Problema al conectar con la base de datos: ' . $e->getMessage()); |
196 | 196 | } |
197 | 197 | } |
@@ -226,18 +226,18 @@ discard block |
||
226 | 226 | * @return mixed elemento sano |
227 | 227 | */ |
228 | 228 | final public function scape($e) { |
229 | - if(null === $e) { |
|
229 | + if (null === $e) { |
|
230 | 230 | return ''; |
231 | 231 | } |
232 | 232 | |
233 | - if(is_numeric($e) and $e <= 2147483647) { |
|
234 | - if(explode('.',$e)[0] != $e) { |
|
233 | + if (is_numeric($e) and $e <= 2147483647) { |
|
234 | + if (explode('.', $e)[0] != $e) { |
|
235 | 235 | return (float) $e; |
236 | 236 | } |
237 | 237 | return (int) $e; |
238 | 238 | } |
239 | 239 | |
240 | - return (string) trim(str_replace(['\\',"\x00",'\n','\r',"'",'"',"\x1a"],['\\\\','\\0','\\n','\\r',"\'",'\"','\\Z'],$e)); |
|
240 | + return (string) trim(str_replace(['\\', "\x00", '\n', '\r', "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\'", '\"', '\\Z'], $e)); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | final public function insert(string $table, array $e) : \PDOStatement { |
267 | 267 | if (sizeof($e) == 0) { |
268 | - throw new \RuntimeException('El arreglo pasado por $this->db->insert(\''.$table.'\',...) está vacío.'); |
|
268 | + throw new \RuntimeException('El arreglo pasado por $this->db->insert(\'' . $table . '\',...) está vacío.'); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | $query = "INSERT INTO $table ("; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | */ |
296 | 296 | final public function update(string $table, array $e, string $where, string $limit = '') : \PDOStatement { |
297 | 297 | if (sizeof($e) == 0) { |
298 | - throw new \RuntimeException('El arreglo pasado por $this->db->update(\''.$table.'\'...) está vacío.'); |
|
298 | + throw new \RuntimeException('El arreglo pasado por $this->db->update(\'' . $table . '\'...) está vacío.'); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | $query = "UPDATE $table SET "; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $result = $sql->fetchAll(); |
333 | 333 | $sql->closeCursor(); |
334 | 334 | |
335 | - if(sizeof($result) > 0) { |
|
335 | + if (sizeof($result) > 0) { |
|
336 | 336 | return $result; |
337 | 337 | } |
338 | 338 |