@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | final public static function amigable_time(int $from, int $to = 0) : string { |
| 31 | 31 | $intervalos = array("segundo", "minuto", "hora", "día", "semana", "mes", "año"); |
| 32 | - $duraciones = array("60","60","24","7","4.35","12"); |
|
| 32 | + $duraciones = array("60", "60", "24", "7", "4.35", "12"); |
|
| 33 | 33 | $to = $to === 0 ? time() : $to; |
| 34 | 34 | |
| 35 | - if(empty($from)) { |
|
| 35 | + if (empty($from)) { |
|
| 36 | 36 | return "Fecha incorracta"; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if($to > $from) { |
|
| 39 | + if ($to > $from) { |
|
| 40 | 40 | $diferencia = $to - $from; |
| 41 | 41 | $tiempo = "Hace"; |
| 42 | 42 | } else { |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | $tiempo = "Dentro de"; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - for($j = 0; $diferencia >= $duraciones[$j] && $j < count($duraciones)-1; $j++) { |
|
| 47 | + for ($j = 0; $diferencia >= $duraciones[$j] && $j < count($duraciones) - 1; $j++) { |
|
| 48 | 48 | $diferencia /= $duraciones[$j]; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $diferencia = round($diferencia); |
| 52 | 52 | |
| 53 | - if($diferencia != 1) { |
|
| 54 | - $intervalos[5].="e"; //MESES |
|
| 55 | - $intervalos[$j].= "s"; |
|
| 53 | + if ($diferencia != 1) { |
|
| 54 | + $intervalos[5] .= "e"; //MESES |
|
| 55 | + $intervalos[$j] .= "s"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | return "$tiempo $diferencia $intervalos[$j]"; |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | */ |
| 95 | 95 | final public static function date_difference(string $ini, string $fin) : int { |
| 96 | - $ini_i = explode('-',str_replace('/','-',$ini)); |
|
| 97 | - $fin_i = explode('-',str_replace('/','-',$fin)); |
|
| 98 | - return (int) floor((mktime(0, 0, 0, $fin_i[1], $fin_i[0], $fin_i[2]) - mktime(0, 0, 0, $ini_i[1], $ini_i[0], $ini_i[2])) / 86400); |
|
| 96 | + $ini_i = explode('-', str_replace('/', '-', $ini)); |
|
| 97 | + $fin_i = explode('-', str_replace('/', '-', $fin)); |
|
| 98 | + return (int) floor((mktime(0, 0, 0, $fin_i[1], $fin_i[0], $fin_i[2]) - mktime(0, 0, 0, $ini_i[1], $ini_i[0], $ini_i[2]))/86400); |
|
| 99 | 99 | } |
| 100 | 100 | //------------------------------------------------ |
| 101 | 101 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | */ |
| 120 | 120 | final public static function days_of_month() : int { |
| 121 | - return cal_days_in_month(CAL_GREGORIAN, (int) date('m',time()), (int) date('Y',time())); |
|
| 121 | + return cal_days_in_month(CAL_GREGORIAN, (int) date('m', time()), (int) date('Y', time())); |
|
| 122 | 122 | } |
| 123 | 123 | //------------------------------------------------ |
| 124 | 124 | /** |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @return int Cantidad de palabras |
| 289 | 289 | */ |
| 290 | 290 | final public static function count_words(string $s) : int { |
| 291 | - return (int) str_word_count($s,0); |
|
| 291 | + return (int) str_word_count($s, 0); |
|
| 292 | 292 | } |
| 293 | 293 | //------------------------------------------------ |
| 294 | 294 | /** |
@@ -50,12 +50,12 @@ |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | # Recorrer el segundo arreglo |
| 53 | - foreach($b as $llave => $contenido) { |
|
| 53 | + foreach ($b as $llave => $contenido) { |
|
| 54 | 54 | # Verificar que no hay desnivel |
| 55 | - if(!is_array($a[$llave]) && !is_array($b[$llave])) { |
|
| 55 | + if (!is_array($a[$llave]) && !is_array($b[$llave])) { |
|
| 56 | 56 | $a[$llave] += $b[$llave]; |
| 57 | 57 | } else { |
| 58 | - throw new \RuntimeException('Existe un problema para operar en la llave '.$llave.'.'); |
|
| 58 | + throw new \RuntimeException('Existe un problema para operar en la llave ' . $llave . '.'); |
|
| 59 | 59 | break; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return bool con el resultado de la comparación |
| 30 | 30 | */ |
| 31 | 31 | final private function check_str_to_time(int $index, array $detail, int $max) : bool { |
| 32 | - return !array_key_exists($index,$detail) || !is_numeric($detail[$index]) || intval($detail[$index]) < $max; |
|
| 32 | + return !array_key_exists($index, $detail) || !is_numeric($detail[$index]) || intval($detail[$index]) < $max; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | //------------------------------------------------ |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return bool con true si está vacío, false si no, un espacio en blanco cuenta como vacío |
| 105 | 105 | */ |
| 106 | 106 | final public function emp($var) : bool { |
| 107 | - return (null === $var || empty(trim(str_replace(' ','',$var)))); |
|
| 107 | + return (null === $var || empty(trim(str_replace(' ', '', $var)))); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | //------------------------------------------------ |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | * @return bool con true si están todos llenos, false si al menos uno está vacío |
| 119 | 119 | */ |
| 120 | 120 | final public function all_full(array $array) : bool { |
| 121 | - foreach($array as $e) { |
|
| 122 | - if($this->emp($e) and $e != '0') { |
|
| 121 | + foreach ($array as $e) { |
|
| 122 | + if ($this->emp($e) and $e != '0') { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | final public function e() : bool { |
| 137 | 137 | for ($i = 0, $nargs = func_num_args(); $i < $nargs; $i++) { |
| 138 | - if($this->emp(func_get_arg($i)) && func_get_arg($i) != '0') { |
|
| 138 | + if ($this->emp(func_get_arg($i)) && func_get_arg($i) != '0') { |
|
| 139 | 139 | return true; |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return string con la fecha en formato humano (y en español) |
| 154 | 154 | */ |
| 155 | 155 | final public function fecha(string $format, int $time = 0) : string { |
| 156 | - $date = date($format,$time == 0 ? time() : $time); |
|
| 156 | + $date = date($format, $time == 0 ? time() : $time); |
|
| 157 | 157 | $cambios = array( |
| 158 | 158 | 'Monday'=> 'Lunes', |
| 159 | 159 | 'Tuesday'=> 'Martes', |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @return string con el número del día |
| 227 | 227 | */ |
| 228 | 228 | final public function last_day_month(int $mes, int $anio) : string { |
| 229 | - return date('d', (mktime(0,0,0,$mes + 1, 1, $anio) - 1)); |
|
| 229 | + return date('d', (mktime(0, 0, 0, $mes + 1, 1, $anio) - 1)); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | //------------------------------------------------ |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @return string cifra con cero a la izquirda |
| 240 | 240 | */ |
| 241 | 241 | final public function cero_izq(int $num) : string { |
| 242 | - if($num < 10) { |
|
| 242 | + if ($num < 10) { |
|
| 243 | 243 | return '0' . $num; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -257,17 +257,17 @@ discard block |
||
| 257 | 257 | * @return int|null con el timestamp |
| 258 | 258 | */ |
| 259 | 259 | final public function str_to_time($fecha, string $hora = '00:00:00') { |
| 260 | - if(null == $fecha) { |
|
| 260 | + if (null == $fecha) { |
|
| 261 | 261 | return null; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $detail = explode('/',$fecha); |
|
| 264 | + $detail = explode('/', $fecha); |
|
| 265 | 265 | |
| 266 | 266 | // Formato de día incorrecto, mes y año incorrectos |
| 267 | - if ($this->check_str_to_time(0,$detail,1) |
|
| 268 | - || $this->check_str_to_time(1,$detail,1) |
|
| 267 | + if ($this->check_str_to_time(0, $detail, 1) |
|
| 268 | + || $this->check_str_to_time(1, $detail, 1) |
|
| 269 | 269 | || intval($detail[1]) > 12 |
| 270 | - || $this->check_str_to_time(2,$detail,1970)) { |
|
| 270 | + || $this->check_str_to_time(2, $detail, 1970)) { |
|
| 271 | 271 | return null; |
| 272 | 272 | } |
| 273 | 273 | |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | final public function desde_date(int $desde) { |
| 297 | 297 | # Obtener esta fecha |
| 298 | - $hoy = date('d/m/Y/D',time()); |
|
| 299 | - $hoy = explode('/',$hoy); |
|
| 298 | + $hoy = date('d/m/Y/D', time()); |
|
| 299 | + $hoy = explode('/', $hoy); |
|
| 300 | 300 | |
| 301 | 301 | # Arreglo de condiciones y subcondiciones |
| 302 | 302 | $fecha = array( |
@@ -311,21 +311,21 @@ discard block |
||
| 311 | 311 | 'Sat' => intval($hoy[0]) - 5, |
| 312 | 312 | 'Sun' => intval($hoy[0]) - 6 |
| 313 | 313 | ), |
| 314 | - 4 => '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2], |
|
| 314 | + 4 => '01/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2], |
|
| 315 | 315 | 5 => '01/01/' . $hoy[2] |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - if($desde == 3) { |
|
| 318 | + if ($desde == 3) { |
|
| 319 | 319 | # Dia actual |
| 320 | 320 | $dia = $fecha[3][$hoy[3]]; |
| 321 | 321 | |
| 322 | 322 | # Mes anterior y posiblemente, año también. |
| 323 | - if($dia == 0) { |
|
| 323 | + if ($dia == 0) { |
|
| 324 | 324 | # Restante de la fecha |
| 325 | - $real_fecha = $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/'; |
|
| 325 | + $real_fecha = $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/'; |
|
| 326 | 326 | |
| 327 | 327 | # Verificamos si estamos en enero |
| 328 | - if($hoy[1] == 1) { |
|
| 328 | + if ($hoy[1] == 1) { |
|
| 329 | 329 | return $real_fecha . ($hoy[2] - 1); |
| 330 | 330 | } |
| 331 | 331 | |
@@ -333,8 +333,8 @@ discard block |
||
| 333 | 333 | return $real_fecha . $hoy[2]; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - return $this->cero_izq($dia) .'/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
|
| 337 | - } else if(array_key_exists($desde,$fecha)) { |
|
| 336 | + return $this->cero_izq($dia) . '/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2]; |
|
| 337 | + } else if (array_key_exists($desde, $fecha)) { |
|
| 338 | 338 | return $fecha[$desde]; |
| 339 | 339 | } |
| 340 | 340 | |
@@ -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 | |
@@ -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::ATTR_ERRMODE => |
| 161 | 161 | \PDO::ERRMODE_EXCEPTION |
| 162 | 162 | )); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | try { |
| 180 | 180 | # Verificar existencia del motor |
| 181 | - if(method_exists($this,'motor_' . $motor)) { |
|
| 181 | + if (method_exists($this, 'motor_' . $motor)) { |
|
| 182 | 182 | $this->{'motor_' . $motor}(array( |
| 183 | 183 | 'host' => $config['database']['host'], |
| 184 | 184 | 'name' => $name, |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | 'protocol' => $config['database']['protocol'] |
| 189 | 189 | )); |
| 190 | 190 | } else { |
| 191 | - throw new \RuntimeException('Motor '. $motor .' de conexión no identificado.'); |
|
| 191 | + throw new \RuntimeException('Motor ' . $motor . ' de conexión no identificado.'); |
|
| 192 | 192 | } |
| 193 | 193 | } catch (\PDOException $e) { |
| 194 | 194 | throw new \RuntimeException('Problema al conectar con la base de datos: ' . $e->getMessage()); |