@@ -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 | } |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | //------------------------------------------------ |
41 | 41 | |
42 | 42 | /** |
43 | - * Escribe un string completo en un archivo, si este no existe lo crea |
|
44 | - * |
|
45 | - * @param string $dir: Directorio del archivo escribir/crear |
|
46 | - * @param string $content: Contenido a escribir |
|
47 | - * |
|
48 | - * @return int catidad de bytes escritos en el archivo |
|
49 | - */ |
|
43 | + * Escribe un string completo en un archivo, si este no existe lo crea |
|
44 | + * |
|
45 | + * @param string $dir: Directorio del archivo escribir/crear |
|
46 | + * @param string $content: Contenido a escribir |
|
47 | + * |
|
48 | + * @return int catidad de bytes escritos en el archivo |
|
49 | + */ |
|
50 | 50 | final public static function write_file(string $dir, string $content) : int { |
51 | 51 | $f = new \SplFileObject($dir,'w'); |
52 | 52 | return (int) $f->fwrite($content); |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | //------------------------------------------------ |
75 | 75 | |
76 | 76 | /** |
77 | - * Devuelve la extensión de un archivo cualquiera, da igual si es solo el nombre o la ruta con el nombre |
|
78 | - * |
|
79 | - * @param string $file_name: Nombre del archivo, da igual si es solo el nombre o la ruta con el nombre |
|
80 | - * |
|
81 | - * @return mixed string con la extensión, devuelve un string '' si no existe información alguna acerca de la extensión |
|
82 | - */ |
|
77 | + * Devuelve la extensión de un archivo cualquiera, da igual si es solo el nombre o la ruta con el nombre |
|
78 | + * |
|
79 | + * @param string $file_name: Nombre del archivo, da igual si es solo el nombre o la ruta con el nombre |
|
80 | + * |
|
81 | + * @return mixed string con la extensión, devuelve un string '' si no existe información alguna acerca de la extensión |
|
82 | + */ |
|
83 | 83 | final public static function get_file_ext(string $file_name) { |
84 | 84 | return pathinfo($file_name, PATHINFO_EXTENSION); |
85 | 85 | } |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | //------------------------------------------------ |
88 | 88 | |
89 | 89 | /** |
90 | - * Dice si un elemento es una imagen o no según su extensión |
|
91 | - * |
|
92 | - * @param string $file_name: Nombre del archivo, da igual si es solo el nombre o la ruta con el nombre |
|
93 | - * |
|
94 | - * @return bool true si es una imagen, false si no lo es |
|
95 | - */ |
|
90 | + * Dice si un elemento es una imagen o no según su extensión |
|
91 | + * |
|
92 | + * @param string $file_name: Nombre del archivo, da igual si es solo el nombre o la ruta con el nombre |
|
93 | + * |
|
94 | + * @return bool true si es una imagen, false si no lo es |
|
95 | + */ |
|
96 | 96 | final public static function is_image(string $file_name) : bool { |
97 | 97 | return (bool) in_array(self::get_file_ext($file_name), ['jpg', 'png', 'jpeg', 'gif', 'JPG', 'PNG', 'JPEG', 'GIF']); |
98 | 98 | } |
@@ -100,39 +100,39 @@ discard block |
||
100 | 100 | //------------------------------------------------ |
101 | 101 | |
102 | 102 | /** |
103 | - * Devuelve el tamaño en Kbytes de un fichero |
|
104 | - * |
|
105 | - * @param string $file: path del fichero |
|
106 | - * |
|
107 | - * @return int con el tamaño del fichero |
|
108 | - */ |
|
103 | + * Devuelve el tamaño en Kbytes de un fichero |
|
104 | + * |
|
105 | + * @param string $file: path del fichero |
|
106 | + * |
|
107 | + * @return int con el tamaño del fichero |
|
108 | + */ |
|
109 | 109 | final public static function file_size(string $file) : int { |
110 | - return (int) round(filesize($file)*0.0009765625, 1); |
|
110 | + return (int) round(filesize($file)*0.0009765625, 1); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | //------------------------------------------------ |
114 | 114 | |
115 | 115 | /** |
116 | - * Devuelve la fecha y hora exacta de creación de un fichero |
|
117 | - * |
|
118 | - * @param string $file: path del fichero |
|
119 | - * |
|
120 | - * @return string con la fecha del fichero en el formato d-m-y h:i:s |
|
121 | - */ |
|
116 | + * Devuelve la fecha y hora exacta de creación de un fichero |
|
117 | + * |
|
118 | + * @param string $file: path del fichero |
|
119 | + * |
|
120 | + * @return string con la fecha del fichero en el formato d-m-y h:i:s |
|
121 | + */ |
|
122 | 122 | final public static function date_file(string $file) : string { |
123 | - return date('d-m-Y h:i:s', filemtime($file)); |
|
123 | + return date('d-m-Y h:i:s', filemtime($file)); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | //------------------------------------------------ |
127 | 127 | |
128 | 128 | /** |
129 | - * Devuelve en un arreglo numérico, la ruta de todos los ficheros en un directorio filtrado por tipos |
|
130 | - * |
|
131 | - * @param string $dir: directorio completo |
|
132 | - * @param string $types: tipos de archivos a buscar, por defecto '' significa todos, se puede pasar por ejemplo 'jpg' |
|
133 | - * |
|
134 | - * @return array con las rutas de todos los ficheros encontrados, un array vacío si no encontró ficheros |
|
135 | - */ |
|
129 | + * Devuelve en un arreglo numérico, la ruta de todos los ficheros en un directorio filtrado por tipos |
|
130 | + * |
|
131 | + * @param string $dir: directorio completo |
|
132 | + * @param string $types: tipos de archivos a buscar, por defecto '' significa todos, se puede pasar por ejemplo 'jpg' |
|
133 | + * |
|
134 | + * @return array con las rutas de todos los ficheros encontrados, un array vacío si no encontró ficheros |
|
135 | + */ |
|
136 | 136 | final public static function get_files_in_dir(string $dir, string $types = '') : array { |
137 | 137 | $array = array(); |
138 | 138 | if (is_dir($dir)) { |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | //------------------------------------------------ |
147 | 147 | |
148 | 148 | /** |
149 | - * Crea un directorio |
|
150 | - * |
|
151 | - * @param string $dir: Directorio a crear |
|
152 | - * @param int $permisos: Permisos del directorio a crear, por defecto es "todos los permisos" |
|
153 | - * |
|
154 | - * @return bool con true si fue creado con éxito, false si el directorio ya existía o hubo algún error |
|
155 | - */ |
|
149 | + * Crea un directorio |
|
150 | + * |
|
151 | + * @param string $dir: Directorio a crear |
|
152 | + * @param int $permisos: Permisos del directorio a crear, por defecto es "todos los permisos" |
|
153 | + * |
|
154 | + * @return bool con true si fue creado con éxito, false si el directorio ya existía o hubo algún error |
|
155 | + */ |
|
156 | 156 | final public static function create_dir(string $dir, int $permisos = 0755) : bool { |
157 | 157 | if(is_dir($dir)) { |
158 | 158 | return false; |
@@ -248,10 +248,10 @@ discard block |
||
248 | 248 | //------------------------------------------------ |
249 | 249 | |
250 | 250 | /** |
251 | - * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
|
252 | - * |
|
253 | - * @return array con todas las funciones con sus respectivos nombres de acceso en plantillas twig |
|
254 | - */ |
|
251 | + * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
|
252 | + * |
|
253 | + * @return array con todas las funciones con sus respectivos nombres de acceso en plantillas twig |
|
254 | + */ |
|
255 | 255 | public function getFunctions() : array { |
256 | 256 | return array( |
257 | 257 | new \Twig_Function('images_in_dir', array($this, 'images_in_dir')), |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | //------------------------------------------------ |
267 | 267 | |
268 | 268 | /** |
269 | - * Identificador único para la extensión de twig |
|
270 | - * |
|
271 | - * @return string con el nombre de la extensión |
|
272 | - */ |
|
269 | + * Identificador único para la extensión de twig |
|
270 | + * |
|
271 | + * @return string con el nombre de la extensión |
|
272 | + */ |
|
273 | 273 | public function getName() : string { |
274 | 274 | return 'ocrend_framework_helper_files'; |
275 | 275 | } |
@@ -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 | |
@@ -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 | //------------------------------------------------ |
@@ -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 | } |
@@ -25,65 +25,65 @@ |
||
25 | 25 | abstract class Controllers { |
26 | 26 | |
27 | 27 | /** |
28 | - * Obtiene el objeto del template |
|
29 | - * |
|
30 | - * @var \Twig_Environment |
|
31 | - */ |
|
28 | + * Obtiene el objeto del template |
|
29 | + * |
|
30 | + * @var \Twig_Environment |
|
31 | + */ |
|
32 | 32 | protected $template; |
33 | 33 | |
34 | 34 | /** |
35 | - * Verifica si está definida la ruta /id como un integer >= 1 |
|
36 | - * |
|
37 | - * @var bool |
|
38 | - */ |
|
35 | + * Verifica si está definida la ruta /id como un integer >= 1 |
|
36 | + * |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | 39 | protected $isset_id = false; |
40 | 40 | |
41 | 41 | /** |
42 | - * Tiene el valor de la ruta /método |
|
43 | - * |
|
44 | - * @var string|null |
|
45 | - */ |
|
42 | + * Tiene el valor de la ruta /método |
|
43 | + * |
|
44 | + * @var string|null |
|
45 | + */ |
|
46 | 46 | protected $method; |
47 | 47 | |
48 | 48 | /** |
49 | - * Contiene una instancia del helper para funciones |
|
50 | - * |
|
51 | - * @var \Ocrend\Kernel\Helpers\Functions |
|
52 | - */ |
|
49 | + * Contiene una instancia del helper para funciones |
|
50 | + * |
|
51 | + * @var \Ocrend\Kernel\Helpers\Functions |
|
52 | + */ |
|
53 | 53 | protected $functions; |
54 | 54 | |
55 | 55 | /** |
56 | - * Arreglo con la información del usuario conectado actualmente. |
|
57 | - * |
|
58 | - * @var array |
|
59 | - */ |
|
56 | + * Arreglo con la información del usuario conectado actualmente. |
|
57 | + * |
|
58 | + * @var array |
|
59 | + */ |
|
60 | 60 | protected $user = array(); |
61 | 61 | |
62 | 62 | /** |
63 | - * Contiene información sobre el estado del usuario, si está o no conectado. |
|
64 | - * |
|
65 | - * @var bool |
|
66 | - */ |
|
63 | + * Contiene información sobre el estado del usuario, si está o no conectado. |
|
64 | + * |
|
65 | + * @var bool |
|
66 | + */ |
|
67 | 67 | private $is_logged = false; |
68 | 68 | |
69 | 69 | /** |
70 | - * Parámetros de configuración para el controlador con la forma: |
|
71 | - * 'parmáetro' => (bool) valor |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
70 | + * Parámetros de configuración para el controlador con la forma: |
|
71 | + * 'parmáetro' => (bool) valor |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | 75 | private $controllerConfig; |
76 | 76 | |
77 | 77 | /** |
78 | - * Configuración inicial de cualquier controlador |
|
79 | - * |
|
80 | - * @param IRouter $router: Instancia de un Router |
|
81 | - * @param array|null $configController: Arreglo de configuración con la forma |
|
82 | - * 'twig_cache_reload' => bool, # Configura el autoreload del caché de twig |
|
83 | - * 'users_logged' => bool, # Configura el controlador para solo ser visto por usuarios logeados |
|
84 | - * 'users_not_logged' => bool, # Configura el controlador para solo ser visto por !(usuarios logeados) |
|
85 | - * |
|
86 | - */ |
|
78 | + * Configuración inicial de cualquier controlador |
|
79 | + * |
|
80 | + * @param IRouter $router: Instancia de un Router |
|
81 | + * @param array|null $configController: Arreglo de configuración con la forma |
|
82 | + * 'twig_cache_reload' => bool, # Configura el autoreload del caché de twig |
|
83 | + * 'users_logged' => bool, # Configura el controlador para solo ser visto por usuarios logeados |
|
84 | + * 'users_not_logged' => bool, # Configura el controlador para solo ser visto por !(usuarios logeados) |
|
85 | + * |
|
86 | + */ |
|
87 | 87 | protected function __construct(IRouter $router, $configController = null) { |
88 | 88 | global $config, $http, $session; |
89 | 89 |
@@ -123,7 +123,7 @@ |
||
123 | 123 | $this->template->addExtension($this->functions); |
124 | 124 | |
125 | 125 | # Debug disponible en twig |
126 | - if($config['framework']['debug']) { |
|
126 | + if ($config['framework']['debug']) { |
|
127 | 127 | $this->template->addExtension(new \Twig_Extension_Debug()); |
128 | 128 | } |
129 | 129 |
@@ -20,89 +20,89 @@ |
||
20 | 20 | final class Rules { |
21 | 21 | |
22 | 22 | /** |
23 | - * Sin ninguna regla |
|
24 | - * |
|
25 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
26 | - * |
|
27 | - * @return mixed |
|
28 | - */ |
|
23 | + * Sin ninguna regla |
|
24 | + * |
|
25 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
26 | + * |
|
27 | + * @return mixed |
|
28 | + */ |
|
29 | 29 | final public function none($ruta) { |
30 | 30 | return $ruta; |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * Sólamente letras |
|
35 | - * |
|
36 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
37 | - * |
|
38 | - * @return mixed |
|
39 | - */ |
|
34 | + * Sólamente letras |
|
35 | + * |
|
36 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
37 | + * |
|
38 | + * @return mixed |
|
39 | + */ |
|
40 | 40 | final public function letters($ruta) { |
41 | 41 | return preg_match("/^[a-zA-Z ]*$/", $ruta) ? $ruta : null; |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Letras y números |
|
46 | - * |
|
47 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
48 | - * |
|
49 | - * @return mixed |
|
50 | - */ |
|
45 | + * Letras y números |
|
46 | + * |
|
47 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
48 | + * |
|
49 | + * @return mixed |
|
50 | + */ |
|
51 | 51 | final public function alphanumeric($ruta) { |
52 | 52 | return preg_match('/^[a-zA-Z0-9 ]*$/', $ruta) ? $ruta : null; |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * Con forma para URL (letras,números y el caracter -) |
|
57 | - * |
|
58 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
59 | - * |
|
60 | - * @return mixed |
|
61 | - */ |
|
56 | + * Con forma para URL (letras,números y el caracter -) |
|
57 | + * |
|
58 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
59 | + * |
|
60 | + * @return mixed |
|
61 | + */ |
|
62 | 62 | final public function url($ruta) { |
63 | 63 | return preg_match('/^[a-zA-Z0-9- ]*$/', $ruta) ? $ruta : null; |
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | - * Sólamente números enteros |
|
68 | - * |
|
69 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
70 | - * |
|
71 | - * @return int|null |
|
72 | - */ |
|
67 | + * Sólamente números enteros |
|
68 | + * |
|
69 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
70 | + * |
|
71 | + * @return int|null |
|
72 | + */ |
|
73 | 73 | final public function integer($ruta) { |
74 | 74 | return is_numeric($ruta) ? (int) $ruta : null; |
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | - * Solamente números enteros positivos |
|
79 | - * |
|
80 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
81 | - * |
|
82 | - * @return int|null |
|
83 | - */ |
|
78 | + * Solamente números enteros positivos |
|
79 | + * |
|
80 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
81 | + * |
|
82 | + * @return int|null |
|
83 | + */ |
|
84 | 84 | final public function integer_positive($ruta) { |
85 | 85 | return (is_numeric($ruta) && $ruta >= 0) ? (int) $ruta : null; |
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Solamente números con decimal |
|
90 | - * |
|
91 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
92 | - * |
|
93 | - * @return float|null |
|
94 | - */ |
|
89 | + * Solamente números con decimal |
|
90 | + * |
|
91 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
92 | + * |
|
93 | + * @return float|null |
|
94 | + */ |
|
95 | 95 | final public function float($ruta) { |
96 | 96 | return is_numeric($ruta) ? (float) $ruta : null; |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | - * Solamente números con decimal y positivos |
|
101 | - * |
|
102 | - * @param mixed $ruta : Ruta a aplicar la regla |
|
103 | - * |
|
104 | - * @return float|null |
|
105 | - */ |
|
100 | + * Solamente números con decimal y positivos |
|
101 | + * |
|
102 | + * @param mixed $ruta : Ruta a aplicar la regla |
|
103 | + * |
|
104 | + * @return float|null |
|
105 | + */ |
|
106 | 106 | final public function float_positive($ruta) { |
107 | 107 | return (is_numeric($ruta) && $ruta >= 0) ? (float) $ruta : null; |
108 | 108 | } |
@@ -19,20 +19,20 @@ discard block |
||
19 | 19 | |
20 | 20 | final class Functions extends \Twig_Extension { |
21 | 21 | |
22 | - /** |
|
23 | - * Verifica parte de una fecha, método privado usado en str_to_time |
|
24 | - * |
|
25 | - * @param int $index: Índice del arreglo |
|
26 | - * @param array $detail: Arreglo |
|
27 | - * @param int $max: Valor a comparar |
|
28 | - * |
|
29 | - * @return bool con el resultado de la comparación |
|
30 | - */ |
|
22 | + /** |
|
23 | + * Verifica parte de una fecha, método privado usado en str_to_time |
|
24 | + * |
|
25 | + * @param int $index: Índice del arreglo |
|
26 | + * @param array $detail: Arreglo |
|
27 | + * @param int $max: Valor a comparar |
|
28 | + * |
|
29 | + * @return bool con el resultado de la comparación |
|
30 | + */ |
|
31 | 31 | final private function check_str_to_time(int $index, array $detail, int $max) : bool { |
32 | 32 | return !array_key_exists($index,$detail) || !is_numeric($detail[$index]) || intval($detail[$index]) < $max; |
33 | 33 | } |
34 | 34 | |
35 | - //------------------------------------------------ |
|
35 | + //------------------------------------------------ |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Redirecciona a una URL |
@@ -84,55 +84,55 @@ discard block |
||
84 | 84 | //------------------------------------------------ |
85 | 85 | |
86 | 86 | /** |
87 | - * Retorna la URL de un gravatar, según el email |
|
88 | - * |
|
89 | - * @param string $email: El email del usuario a extraer el gravatar |
|
90 | - * @param int $size: El tamaño del gravatar |
|
91 | - * @return string con la URl |
|
92 | - */ |
|
93 | - final public function get_gravatar(string $email, int $size = 32) : string { |
|
94 | - return 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . (int) abs($size); |
|
95 | - } |
|
96 | - |
|
97 | - //------------------------------------------------ |
|
98 | - |
|
99 | - /** |
|
87 | + * Retorna la URL de un gravatar, según el email |
|
88 | + * |
|
89 | + * @param string $email: El email del usuario a extraer el gravatar |
|
90 | + * @param int $size: El tamaño del gravatar |
|
91 | + * @return string con la URl |
|
92 | + */ |
|
93 | + final public function get_gravatar(string $email, int $size = 32) : string { |
|
94 | + return 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . (int) abs($size); |
|
95 | + } |
|
96 | + |
|
97 | + //------------------------------------------------ |
|
98 | + |
|
99 | + /** |
|
100 | 100 | * Alias de Empty, más completo |
101 | 101 | * |
102 | 102 | * @param mixed $var: Variable a analizar |
103 | 103 | * |
104 | 104 | * @return bool con true si está vacío, false si no, un espacio en blanco cuenta como vacío |
105 | - */ |
|
106 | - final public function emp($var) : bool { |
|
107 | - return (null === $var || empty(trim(str_replace(' ','',$var)))); |
|
108 | - } |
|
105 | + */ |
|
106 | + final public function emp($var) : bool { |
|
107 | + return (null === $var || empty(trim(str_replace(' ','',$var)))); |
|
108 | + } |
|
109 | 109 | |
110 | - //------------------------------------------------ |
|
110 | + //------------------------------------------------ |
|
111 | 111 | |
112 | - /** |
|
112 | + /** |
|
113 | 113 | * Aanaliza que TODOS los elementos de un arreglo estén llenos, útil para analizar por ejemplo que todos los elementos de un formulario esté llenos |
114 | 114 | * pasando como parámetro $_POST |
115 | 115 | * |
116 | 116 | * @param array $array, arreglo a analizar |
117 | 117 | * |
118 | 118 | * @return bool con true si están todos llenos, false si al menos uno está vacío |
119 | - */ |
|
120 | - final public function all_full(array $array) : bool { |
|
121 | - foreach($array as $e) { |
|
122 | - if($this->emp($e) and $e != '0') { |
|
123 | - return false; |
|
124 | - } |
|
125 | - } |
|
126 | - return true; |
|
127 | - } |
|
128 | - |
|
129 | - //------------------------------------------------ |
|
130 | - |
|
131 | - /** |
|
119 | + */ |
|
120 | + final public function all_full(array $array) : bool { |
|
121 | + foreach($array as $e) { |
|
122 | + if($this->emp($e) and $e != '0') { |
|
123 | + return false; |
|
124 | + } |
|
125 | + } |
|
126 | + return true; |
|
127 | + } |
|
128 | + |
|
129 | + //------------------------------------------------ |
|
130 | + |
|
131 | + /** |
|
132 | 132 | * Alias de Empty() pero soporta más de un parámetro (infinitos) |
133 | 133 | * |
134 | 134 | * @return bool con true si al menos uno está vacío, false si todos están llenos |
135 | - */ |
|
135 | + */ |
|
136 | 136 | final public function e() : bool { |
137 | 137 | for ($i = 0, $nargs = func_num_args(); $i < $nargs; $i++) { |
138 | 138 | if($this->emp(func_get_arg($i)) && func_get_arg($i) != '0') { |
@@ -145,58 +145,58 @@ discard block |
||
145 | 145 | //------------------------------------------------ |
146 | 146 | |
147 | 147 | /** |
148 | - * Alias de date() pero devuele días y meses en español |
|
149 | - * |
|
150 | - * @param string $format: Formato de salida (igual que en date()) |
|
151 | - * @param int $time: Tiempo, por defecto es time() (igual que en date()) |
|
152 | - * |
|
153 | - * @return string con la fecha en formato humano (y en español) |
|
154 | - */ |
|
148 | + * Alias de date() pero devuele días y meses en español |
|
149 | + * |
|
150 | + * @param string $format: Formato de salida (igual que en date()) |
|
151 | + * @param int $time: Tiempo, por defecto es time() (igual que en date()) |
|
152 | + * |
|
153 | + * @return string con la fecha en formato humano (y en español) |
|
154 | + */ |
|
155 | 155 | final public function fecha(string $format, int $time = 0) : string { |
156 | - $date = date($format,$time == 0 ? time() : $time); |
|
157 | - $cambios = array( |
|
158 | - 'Monday'=> 'Lunes', |
|
159 | - 'Tuesday'=> 'Martes', |
|
160 | - 'Wednesday'=> 'Miércoles', |
|
161 | - 'Thursday'=> 'Jueves', |
|
162 | - 'Friday'=> 'Viernes', |
|
163 | - 'Saturday'=> 'Sábado', |
|
164 | - 'Sunday'=> 'Domingo', |
|
165 | - 'January'=> 'Enero', |
|
166 | - 'February'=> 'Febrero', |
|
167 | - 'March'=> 'Marzo', |
|
168 | - 'April'=> 'Abril', |
|
169 | - 'May'=> 'Mayo', |
|
170 | - 'June'=> 'Junio', |
|
171 | - 'July'=> 'Julio', |
|
172 | - 'August'=> 'Agosto', |
|
173 | - 'September'=> 'Septiembre', |
|
174 | - 'October'=> 'Octubre', |
|
175 | - 'November'=> 'Noviembre', |
|
176 | - 'December'=> 'Diciembre', |
|
177 | - 'Mon'=> 'Lun', |
|
178 | - 'Tue'=> 'Mar', |
|
179 | - 'Wed'=> 'Mie', |
|
180 | - 'Thu'=> 'Jue', |
|
181 | - 'Fri'=> 'Vie', |
|
182 | - 'Sat'=> 'Sab', |
|
183 | - 'Sun'=> 'Dom', |
|
184 | - 'Jan'=> 'Ene', |
|
185 | - 'Aug'=> 'Ago', |
|
186 | - 'Apr'=> 'Abr', |
|
187 | - 'Dec'=> 'Dic' |
|
188 | - ); |
|
189 | - return str_replace(array_keys($cambios), array_values($cambios), $date); |
|
190 | - } |
|
191 | - |
|
192 | - //------------------------------------------------ |
|
156 | + $date = date($format,$time == 0 ? time() : $time); |
|
157 | + $cambios = array( |
|
158 | + 'Monday'=> 'Lunes', |
|
159 | + 'Tuesday'=> 'Martes', |
|
160 | + 'Wednesday'=> 'Miércoles', |
|
161 | + 'Thursday'=> 'Jueves', |
|
162 | + 'Friday'=> 'Viernes', |
|
163 | + 'Saturday'=> 'Sábado', |
|
164 | + 'Sunday'=> 'Domingo', |
|
165 | + 'January'=> 'Enero', |
|
166 | + 'February'=> 'Febrero', |
|
167 | + 'March'=> 'Marzo', |
|
168 | + 'April'=> 'Abril', |
|
169 | + 'May'=> 'Mayo', |
|
170 | + 'June'=> 'Junio', |
|
171 | + 'July'=> 'Julio', |
|
172 | + 'August'=> 'Agosto', |
|
173 | + 'September'=> 'Septiembre', |
|
174 | + 'October'=> 'Octubre', |
|
175 | + 'November'=> 'Noviembre', |
|
176 | + 'December'=> 'Diciembre', |
|
177 | + 'Mon'=> 'Lun', |
|
178 | + 'Tue'=> 'Mar', |
|
179 | + 'Wed'=> 'Mie', |
|
180 | + 'Thu'=> 'Jue', |
|
181 | + 'Fri'=> 'Vie', |
|
182 | + 'Sat'=> 'Sab', |
|
183 | + 'Sun'=> 'Dom', |
|
184 | + 'Jan'=> 'Ene', |
|
185 | + 'Aug'=> 'Ago', |
|
186 | + 'Apr'=> 'Abr', |
|
187 | + 'Dec'=> 'Dic' |
|
188 | + ); |
|
189 | + return str_replace(array_keys($cambios), array_values($cambios), $date); |
|
190 | + } |
|
191 | + |
|
192 | + //------------------------------------------------ |
|
193 | 193 | |
194 | 194 | /** |
195 | - * Devuelve la etiqueta <base> html adecuada para que los assets carguen desde allí. |
|
196 | - * Se adapta a la configuración del dominio en general. |
|
197 | - * |
|
198 | - * @return string <base href="ruta" /> |
|
199 | - */ |
|
195 | + * Devuelve la etiqueta <base> html adecuada para que los assets carguen desde allí. |
|
196 | + * Se adapta a la configuración del dominio en general. |
|
197 | + * |
|
198 | + * @return string <base href="ruta" /> |
|
199 | + */ |
|
200 | 200 | final public function base_assets() : string { |
201 | 201 | global $config, $http; |
202 | 202 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @param int $anio: Año (1975 a 2xxx) |
225 | 225 | * |
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 | 229 | return date('d', (mktime(0,0,0,$mes + 1, 1, $anio) - 1)); |
230 | 230 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param int $num: cifra |
238 | 238 | * |
239 | 239 | * @return string cifra con cero a la izquirda |
240 | - */ |
|
240 | + */ |
|
241 | 241 | final public function cero_izq(int $num) : string { |
242 | 242 | if($num < 10) { |
243 | 243 | return '0' . $num; |
@@ -248,14 +248,14 @@ discard block |
||
248 | 248 | |
249 | 249 | //------------------------------------------------ |
250 | 250 | |
251 | - /** |
|
252 | - * Devuelve el timestamp de una fecha, y null si su formato es incorrecto. |
|
253 | - * |
|
254 | - * @param string|null $fecha: Fecha con formato dd/mm/yy |
|
255 | - * @param string $hora: Hora de inicio de la $fecha |
|
256 | - * |
|
257 | - * @return int|null con el timestamp |
|
258 | - */ |
|
251 | + /** |
|
252 | + * Devuelve el timestamp de una fecha, y null si su formato es incorrecto. |
|
253 | + * |
|
254 | + * @param string|null $fecha: Fecha con formato dd/mm/yy |
|
255 | + * @param string $hora: Hora de inicio de la $fecha |
|
256 | + * |
|
257 | + * @return int|null con el timestamp |
|
258 | + */ |
|
259 | 259 | final public function str_to_time($fecha, string $hora = '00:00:00') { |
260 | 260 | if(null == $fecha) { |
261 | 261 | return null; |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @param int $desde: Desde donde |
293 | 293 | * |
294 | 294 | * @return mixed |
295 | - */ |
|
295 | + */ |
|
296 | 296 | final public function desde_date(int $desde) { |
297 | 297 | # Obtener esta fecha |
298 | 298 | $hoy = date('d/m/Y/D',time()); |
@@ -300,19 +300,19 @@ discard block |
||
300 | 300 | |
301 | 301 | # Arreglo de condiciones y subcondiciones |
302 | 302 | $fecha = array( |
303 | - 1 => date('d/m/Y', time()), |
|
304 | - 2 => date('d/m/Y', time() - (60*60*24)), |
|
305 | - 3 => array( |
|
306 | - 'Mon' => $hoy[0], |
|
307 | - 'Tue' => intval($hoy[0]) - 1, |
|
308 | - 'Wed' => intval($hoy[0]) - 2, |
|
309 | - 'Thu' => intval($hoy[0]) - 3, |
|
310 | - 'Fri' => intval($hoy[0]) - 4, |
|
311 | - 'Sat' => intval($hoy[0]) - 5, |
|
312 | - 'Sun' => intval($hoy[0]) - 6 |
|
313 | - ), |
|
314 | - 4 => '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2], |
|
315 | - 5 => '01/01/' . $hoy[2] |
|
303 | + 1 => date('d/m/Y', time()), |
|
304 | + 2 => date('d/m/Y', time() - (60*60*24)), |
|
305 | + 3 => array( |
|
306 | + 'Mon' => $hoy[0], |
|
307 | + 'Tue' => intval($hoy[0]) - 1, |
|
308 | + 'Wed' => intval($hoy[0]) - 2, |
|
309 | + 'Thu' => intval($hoy[0]) - 3, |
|
310 | + 'Fri' => intval($hoy[0]) - 4, |
|
311 | + 'Sat' => intval($hoy[0]) - 5, |
|
312 | + 'Sun' => intval($hoy[0]) - 6 |
|
313 | + ), |
|
314 | + 4 => '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2], |
|
315 | + 5 => '01/01/' . $hoy[2] |
|
316 | 316 | ); |
317 | 317 | |
318 | 318 | if($desde == 3) { |
@@ -347,44 +347,44 @@ discard block |
||
347 | 347 | * Obtiene el tiempo actual |
348 | 348 | * |
349 | 349 | * @return int devuelve time() |
350 | - */ |
|
350 | + */ |
|
351 | 351 | final public function timestamp() : int { |
352 | - return time(); |
|
352 | + return time(); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | //------------------------------------------------ |
356 | 356 | |
357 | 357 | /** |
358 | 358 | * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
359 | - * |
|
359 | + * |
|
360 | 360 | * @return array con todas las funciones con sus respectivos nombres de acceso en plantillas twig |
361 | - */ |
|
361 | + */ |
|
362 | 362 | public function getFunctions() : array { |
363 | 363 | return array( |
364 | - new \Twig_Function('percent', array($this, 'percent')), |
|
365 | - new \Twig_Function('convert', array($this, 'convert')), |
|
366 | - new \Twig_Function('get_gravatar', array($this, 'get_gravatar')), |
|
367 | - new \Twig_Function('emp', array($this, 'emp')), |
|
368 | - new \Twig_Function('e_dynamic', array($this, 'e')), |
|
369 | - new \Twig_Function('all_full', array($this, 'all_full')), |
|
370 | - new \Twig_Function('fecha', array($this, 'fecha')), |
|
371 | - new \Twig_Function('base_assets', array($this, 'base_assets')), |
|
372 | - new \Twig_Function('timestamp', array($this, 'timestamp')), |
|
373 | - new \Twig_Function('desde_date', array($this, 'desde_date')), |
|
374 | - new \Twig_Function('cero_izq', array($this, 'cero_izq')), |
|
375 | - new \Twig_Function('last_day_month', array($this, 'last_day_month')), |
|
376 | - new \Twig_Function('str_to_time', array($this, 'str_to_time')), |
|
377 | - new \Twig_Function('desde_date', array($this, 'desde_date')) |
|
378 | - ); |
|
379 | - } |
|
380 | - |
|
381 | - //------------------------------------------------ |
|
364 | + new \Twig_Function('percent', array($this, 'percent')), |
|
365 | + new \Twig_Function('convert', array($this, 'convert')), |
|
366 | + new \Twig_Function('get_gravatar', array($this, 'get_gravatar')), |
|
367 | + new \Twig_Function('emp', array($this, 'emp')), |
|
368 | + new \Twig_Function('e_dynamic', array($this, 'e')), |
|
369 | + new \Twig_Function('all_full', array($this, 'all_full')), |
|
370 | + new \Twig_Function('fecha', array($this, 'fecha')), |
|
371 | + new \Twig_Function('base_assets', array($this, 'base_assets')), |
|
372 | + new \Twig_Function('timestamp', array($this, 'timestamp')), |
|
373 | + new \Twig_Function('desde_date', array($this, 'desde_date')), |
|
374 | + new \Twig_Function('cero_izq', array($this, 'cero_izq')), |
|
375 | + new \Twig_Function('last_day_month', array($this, 'last_day_month')), |
|
376 | + new \Twig_Function('str_to_time', array($this, 'str_to_time')), |
|
377 | + new \Twig_Function('desde_date', array($this, 'desde_date')) |
|
378 | + ); |
|
379 | + } |
|
380 | + |
|
381 | + //------------------------------------------------ |
|
382 | 382 | |
383 | 383 | /** |
384 | - * Identificador único para la extensión de twig |
|
385 | - * |
|
386 | - * @return string con el nombre de la extensión |
|
387 | - */ |
|
384 | + * Identificador único para la extensión de twig |
|
385 | + * |
|
386 | + * @return string con el nombre de la extensión |
|
387 | + */ |
|
388 | 388 | public function getName() : string { |
389 | 389 | return 'ocrend_framework_func_class'; |
390 | 390 | } |
@@ -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 |
@@ -40,25 +40,25 @@ |
||
40 | 40 | //------------------------------------------------ |
41 | 41 | |
42 | 42 | /** |
43 | - * Envía un correo electrónico utilizando PHPMailer |
|
44 | - * |
|
45 | - * @param array $dest: Arreglo con la forma array( |
|
46 | - * 'email destinatario 1' => 'nombre destinatario 1', |
|
47 | - * 'email destinatario 2' => 'nombre destinatario 2' |
|
48 | - * ) |
|
49 | - * @param array $content: sArreglo con el contenido por seciones con la forma |
|
50 | - * array( |
|
51 | - * '{{title}}' => 'Titulo', |
|
52 | - * '{{content}}' => '<p>Contenido</p><p>Etc...</p>' |
|
53 | - * ) |
|
54 | - * @param int $template: Template elegido, por defecto es el primero (0) |
|
55 | - * @param array $adj: Arreglo con direccion local de los adjuntos a enviar, con la forma array( |
|
56 | - * 'ruta archivo 1', |
|
57 | - * 'ruta archivo 2' |
|
58 | - * ) |
|
59 | - * @throws \RuntimeException en caso de algúnproblema |
|
60 | - * @return string|bool true si fue enviado correctamente, false si no |
|
61 | - */ |
|
43 | + * Envía un correo electrónico utilizando PHPMailer |
|
44 | + * |
|
45 | + * @param array $dest: Arreglo con la forma array( |
|
46 | + * 'email destinatario 1' => 'nombre destinatario 1', |
|
47 | + * 'email destinatario 2' => 'nombre destinatario 2' |
|
48 | + * ) |
|
49 | + * @param array $content: sArreglo con el contenido por seciones con la forma |
|
50 | + * array( |
|
51 | + * '{{title}}' => 'Titulo', |
|
52 | + * '{{content}}' => '<p>Contenido</p><p>Etc...</p>' |
|
53 | + * ) |
|
54 | + * @param int $template: Template elegido, por defecto es el primero (0) |
|
55 | + * @param array $adj: Arreglo con direccion local de los adjuntos a enviar, con la forma array( |
|
56 | + * 'ruta archivo 1', |
|
57 | + * 'ruta archivo 2' |
|
58 | + * ) |
|
59 | + * @throws \RuntimeException en caso de algúnproblema |
|
60 | + * @return string|bool true si fue enviado correctamente, false si no |
|
61 | + */ |
|
62 | 62 | final public static function send(array $dest, array $content, int $template = 0, array $adj = array()) { |
63 | 63 | global $config; |
64 | 64 |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | $message = new \Swift_Message(); |
76 | 76 | $message->setSubject(array_key_exists('{{title}}', $content) ? $content['{{title}}'] : $config['site']['name']); |
77 | 77 | $message->setBody(self::loadTemplate($content, $template), 'text/html'); |
78 | - $message->setFrom([ $config['mailer']['user'] => $config['site']['name'] ]); |
|
78 | + $message->setFrom([$config['mailer']['user'] => $config['site']['name']]); |
|
79 | 79 | $message->setTo($dest); |
80 | 80 | |
81 | 81 | if (sizeof($adj)) { |
82 | 82 | foreach ($adj as $ruta) { |
83 | - $message->attach( \Swift_Attachment::fromPath($ruta) ); |
|
83 | + $message->attach(\Swift_Attachment::fromPath($ruta)); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | final public static function setTemplateRoute(string $new_route) { |
130 | 130 | # Verificar que exista el nuevo directorio |
131 | 131 | if (!is_dir($new_route)) { |
132 | - throw new \RuntimeException('la ruta '.$new_route .' no existe'); |
|
132 | + throw new \RuntimeException('la ruta ' . $new_route . ' no existe'); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | # Cambiamos el directorio de los template |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | final class Strings extends \Twig_Extension { |
21 | 21 | //------------------------------------------------ |
22 | 22 | /** |
23 | - * Convierte un tiempo dado al formato hace 1 minuto, hace 2 horas, hace 1 año ... |
|
24 | - * |
|
25 | - * @param int $from: Tiempo en segundo desde donde se desea contar |
|
26 | - * @param int $to: Tiempo en segundo hasta donde se desea contar, si no se pasa por defecto es el tiempo actual |
|
27 | - * |
|
28 | - * @return string con la forma: hace 20 segundos, hace 1 minuto, hace 2 horas, hace 4 días, hace 1 semana, hace 3 meses, hace 1 año ... |
|
29 | - */ |
|
23 | + * Convierte un tiempo dado al formato hace 1 minuto, hace 2 horas, hace 1 año ... |
|
24 | + * |
|
25 | + * @param int $from: Tiempo en segundo desde donde se desea contar |
|
26 | + * @param int $to: Tiempo en segundo hasta donde se desea contar, si no se pasa por defecto es el tiempo actual |
|
27 | + * |
|
28 | + * @return string con la forma: hace 20 segundos, hace 1 minuto, hace 2 horas, hace 4 días, hace 1 semana, hace 3 meses, hace 1 año ... |
|
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 | 32 | $duraciones = array("60","60","24","7","4.35","12"); |
@@ -59,39 +59,39 @@ discard block |
||
59 | 59 | } |
60 | 60 | //------------------------------------------------ |
61 | 61 | /** |
62 | - * Compara un string hash con un string sin hash, si el string sin hash al encriptar posee la misma llave que hash, son iguales |
|
63 | - * |
|
64 | - * @param string $hash: Hash con la forma $2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G |
|
65 | - * @param string $s2: Cadena de texto a comparar |
|
66 | - * |
|
67 | - * @example Strings::chash('$2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G','123456'); //return true |
|
68 | - * |
|
69 | - * @return bool true si $s2 contiene la misma llave que $hash, por tanto el contenido de $hash es $s2, de lo contrario false |
|
70 | - */ |
|
62 | + * Compara un string hash con un string sin hash, si el string sin hash al encriptar posee la misma llave que hash, son iguales |
|
63 | + * |
|
64 | + * @param string $hash: Hash con la forma $2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G |
|
65 | + * @param string $s2: Cadena de texto a comparar |
|
66 | + * |
|
67 | + * @example Strings::chash('$2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G','123456'); //return true |
|
68 | + * |
|
69 | + * @return bool true si $s2 contiene la misma llave que $hash, por tanto el contenido de $hash es $s2, de lo contrario false |
|
70 | + */ |
|
71 | 71 | final public static function chash(string $hash, string $s2) : bool { |
72 | 72 | return $hash == crypt($s2, substr($hash, 0, 29)); |
73 | - } |
|
74 | - //------------------------------------------------ |
|
73 | + } |
|
74 | + //------------------------------------------------ |
|
75 | 75 | /** |
76 | - * Devuelve un hash DINÁMICO, para comparar un hash con un elemento se utiliza chash |
|
77 | - * |
|
78 | - * @param string $p: Cadena de texto a encriptar |
|
79 | - * |
|
80 | - * @return string Hash, con la forma $2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G |
|
81 | - */ |
|
76 | + * Devuelve un hash DINÁMICO, para comparar un hash con un elemento se utiliza chash |
|
77 | + * |
|
78 | + * @param string $p: Cadena de texto a encriptar |
|
79 | + * |
|
80 | + * @return string Hash, con la forma $2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G |
|
81 | + */ |
|
82 | 82 | final public static function hash(string $p) : string { |
83 | 83 | return crypt($p, '$2a$10$' . substr(sha1(mt_rand()), 0, 22)); |
84 | 84 | } |
85 | 85 | //------------------------------------------------ |
86 | 86 | /** |
87 | - * Calcula el tiempo de diferencia entre dos fechas |
|
88 | - * |
|
89 | - * @param string $ini: Fecha menor con el formato d-m-Y ó d/m/Y |
|
90 | - * @param string $fin: Fecha mayor con el formato d-m-Y ó d/m/Y |
|
91 | - * |
|
92 | - * @return int con la diferencia de tiempo en días |
|
93 | - * |
|
94 | - */ |
|
87 | + * Calcula el tiempo de diferencia entre dos fechas |
|
88 | + * |
|
89 | + * @param string $ini: Fecha menor con el formato d-m-Y ó d/m/Y |
|
90 | + * @param string $fin: Fecha mayor con el formato d-m-Y ó d/m/Y |
|
91 | + * |
|
92 | + * @return int con la diferencia de tiempo en días |
|
93 | + * |
|
94 | + */ |
|
95 | 95 | final public static function date_difference(string $ini, string $fin) : int { |
96 | 96 | $ini_i = explode('-',str_replace('/','-',$ini)); |
97 | 97 | $fin_i = explode('-',str_replace('/','-',$fin)); |
@@ -99,90 +99,90 @@ discard block |
||
99 | 99 | } |
100 | 100 | //------------------------------------------------ |
101 | 101 | /** |
102 | - * Calcula la edad de una persona segun la fecha de nacimiento |
|
103 | - * |
|
104 | - * @param string $cumple: Fecha de nacimiento con el formato d-m-Y ó d/m/Y |
|
105 | - * |
|
106 | - * @return int con la edad |
|
107 | - * |
|
108 | - */ |
|
102 | + * Calcula la edad de una persona segun la fecha de nacimiento |
|
103 | + * |
|
104 | + * @param string $cumple: Fecha de nacimiento con el formato d-m-Y ó d/m/Y |
|
105 | + * |
|
106 | + * @return int con la edad |
|
107 | + * |
|
108 | + */ |
|
109 | 109 | final public static function calculate_age(string $cumple) : int { |
110 | 110 | $age = explode('.', (string) (self::date_difference($cumple, date('d-m-Y', time()))/365)); |
111 | 111 | return (int) $age[0]; |
112 | 112 | } |
113 | 113 | //------------------------------------------------ |
114 | 114 | /** |
115 | - * Calcula cuántos días tiene el mes actual |
|
116 | - * |
|
117 | - * @return integer con la cantidad de días del mes |
|
118 | - * |
|
119 | - */ |
|
115 | + * Calcula cuántos días tiene el mes actual |
|
116 | + * |
|
117 | + * @return integer con la cantidad de días del mes |
|
118 | + * |
|
119 | + */ |
|
120 | 120 | final public static function days_of_month() : int { |
121 | 121 | return cal_days_in_month(CAL_GREGORIAN, (int) date('m',time()), (int) date('Y',time())); |
122 | 122 | } |
123 | 123 | //------------------------------------------------ |
124 | 124 | /** |
125 | - * Verifica si una cadena de texto tiene forma de email |
|
126 | - * |
|
127 | - * @param string $address: Cadena de texto con el email |
|
128 | - * |
|
129 | - * @return mixed devuelve TRUE si es un email y FALSE si no lo es |
|
130 | - */ |
|
125 | + * Verifica si una cadena de texto tiene forma de email |
|
126 | + * |
|
127 | + * @param string $address: Cadena de texto con el email |
|
128 | + * |
|
129 | + * @return mixed devuelve TRUE si es un email y FALSE si no lo es |
|
130 | + */ |
|
131 | 131 | final public static function is_email(string $address) { |
132 | 132 | return filter_var($address, FILTER_VALIDATE_EMAIL); |
133 | 133 | } |
134 | 134 | //------------------------------------------------ |
135 | 135 | /** |
136 | - * Remueve todos los espacios en blanco de un string |
|
137 | - * |
|
138 | - * @param string $s: Cadena de texto a convertir |
|
139 | - * |
|
140 | - * @return string del texto sin espacios |
|
141 | - */ |
|
136 | + * Remueve todos los espacios en blanco de un string |
|
137 | + * |
|
138 | + * @param string $s: Cadena de texto a convertir |
|
139 | + * |
|
140 | + * @return string del texto sin espacios |
|
141 | + */ |
|
142 | 142 | final public static function remove_spaces(string $s) : string { |
143 | 143 | return trim(str_replace(' ', '', $s)); |
144 | 144 | } |
145 | 145 | //------------------------------------------------ |
146 | 146 | /** |
147 | - * Analiza si una cadena de texto es alfanumérica |
|
148 | - * |
|
149 | - * @param string $s: Cadena de texto a verificar |
|
150 | - * |
|
151 | - * @return bool, verdadero si es alfanumerica, falso si no |
|
152 | - */ |
|
147 | + * Analiza si una cadena de texto es alfanumérica |
|
148 | + * |
|
149 | + * @param string $s: Cadena de texto a verificar |
|
150 | + * |
|
151 | + * @return bool, verdadero si es alfanumerica, falso si no |
|
152 | + */ |
|
153 | 153 | final public static function alphanumeric(string $s) : bool { |
154 | 154 | return ctype_alnum(self::remove_spaces($s)); |
155 | 155 | } |
156 | 156 | //------------------------------------------------ |
157 | 157 | /** |
158 | - * Analiza si una cadena de texto verificando si sólamente tiene letras |
|
159 | - * |
|
160 | - * @param string $s: Cadena de texto a verificar |
|
161 | - * |
|
162 | - * @return bool, verdadero si sólamente tiene letras, falso si no |
|
163 | - */ |
|
158 | + * Analiza si una cadena de texto verificando si sólamente tiene letras |
|
159 | + * |
|
160 | + * @param string $s: Cadena de texto a verificar |
|
161 | + * |
|
162 | + * @return bool, verdadero si sólamente tiene letras, falso si no |
|
163 | + */ |
|
164 | 164 | final public static function only_letters(string $s) : bool { |
165 | 165 | return ctype_alpha(self::remove_spaces($s)); |
166 | 166 | } |
167 | 167 | //------------------------------------------------ |
168 | 168 | /** |
169 | - * Analiza si una cadena de texto contiene sólamente letras y números |
|
170 | - * |
|
171 | - * @param string $s: Cadena de texto a verificar |
|
172 | - * |
|
173 | - * @return bool, verdadero si sólamente contiene letras y números, falso si no |
|
174 | - */ |
|
169 | + * Analiza si una cadena de texto contiene sólamente letras y números |
|
170 | + * |
|
171 | + * @param string $s: Cadena de texto a verificar |
|
172 | + * |
|
173 | + * @return bool, verdadero si sólamente contiene letras y números, falso si no |
|
174 | + */ |
|
175 | 175 | final public static function letters_and_numbers(string $s) : bool { |
176 | 176 | return (boolean) preg_match('/^[\w.]*$/', self::remove_spaces($s)); |
177 | 177 | } |
178 | 178 | //------------------------------------------------ |
179 | 179 | /** |
180 | - * Convierte una expresión de texto, a una compatible con url amigables |
|
181 | - * |
|
182 | - * @param string $url: Cadena de texto a convertir |
|
183 | - * |
|
184 | - * @return string Cadena de texto con formato de url amigable |
|
185 | - */ |
|
180 | + * Convierte una expresión de texto, a una compatible con url amigables |
|
181 | + * |
|
182 | + * @param string $url: Cadena de texto a convertir |
|
183 | + * |
|
184 | + * @return string Cadena de texto con formato de url amigable |
|
185 | + */ |
|
186 | 186 | final public static function url_amigable(string $url) : string { |
187 | 187 | $url = str_replace(['á', 'é', 'í', 'ó', 'ú', 'ñ'], ['a', 'e', 'i', 'o', 'u', 'n'], $url); |
188 | 188 | $url = str_replace([' ', '&', '\r\n', '\n', '+', '%'], '-', $url); |
@@ -243,58 +243,58 @@ discard block |
||
243 | 243 | } |
244 | 244 | //------------------------------------------------ |
245 | 245 | /** |
246 | - * Dice si un string comienza con un caracter especificado |
|
247 | - * |
|
248 | - * @param string $sx: Caracter de inicio |
|
249 | - * @param string $str: String a evaluar |
|
250 | - * @param bool $case_sensitive: Boolean para definir si será seible a mayúsculas o no |
|
251 | - * |
|
252 | - * @return bool True si comienza con el caracter especificado, False si no |
|
253 | - */ |
|
246 | + * Dice si un string comienza con un caracter especificado |
|
247 | + * |
|
248 | + * @param string $sx: Caracter de inicio |
|
249 | + * @param string $str: String a evaluar |
|
250 | + * @param bool $case_sensitive: Boolean para definir si será seible a mayúsculas o no |
|
251 | + * |
|
252 | + * @return bool True si comienza con el caracter especificado, False si no |
|
253 | + */ |
|
254 | 254 | final public static function begin_with(string $sx, string $str) : bool { |
255 | 255 | return (bool) (strlen($str) > 0 and $str[0] == $sx); |
256 | 256 | } |
257 | 257 | //------------------------------------------------ |
258 | 258 | /** |
259 | - * Dice si un string termina con una caracter especificado |
|
260 | - * |
|
261 | - * @param string $sx: Caracter del final |
|
262 | - * @param string $str: String a evaluar |
|
263 | - * |
|
264 | - * @return bool True si termina con el caracter especificado, False si no |
|
265 | - */ |
|
259 | + * Dice si un string termina con una caracter especificado |
|
260 | + * |
|
261 | + * @param string $sx: Caracter del final |
|
262 | + * @param string $str: String a evaluar |
|
263 | + * |
|
264 | + * @return bool True si termina con el caracter especificado, False si no |
|
265 | + */ |
|
266 | 266 | final public static function end_with(string $sx, string $str) : bool { |
267 | 267 | return (bool) (strlen($str) > 0 and $str[strlen($str) - 1] == $sx); |
268 | 268 | } |
269 | 269 | //------------------------------------------------ |
270 | 270 | /** |
271 | - * Ver si un string está contenido en otro |
|
272 | - * |
|
273 | - * @param $s: String contenido en $str |
|
274 | - * @param $str: String a evaluar |
|
275 | - * |
|
276 | - * @return bool True si $s está dentro de $str, False si no |
|
277 | - */ |
|
271 | + * Ver si un string está contenido en otro |
|
272 | + * |
|
273 | + * @param $s: String contenido en $str |
|
274 | + * @param $str: String a evaluar |
|
275 | + * |
|
276 | + * @return bool True si $s está dentro de $str, False si no |
|
277 | + */ |
|
278 | 278 | final public static function contain(string $s, string $str) : bool { |
279 | 279 | return (bool) (strpos($str, $s) !== false); |
280 | 280 | } |
281 | 281 | //------------------------------------------------ |
282 | 282 | /** |
283 | - * Devuelve la cantidad de palabras en un string |
|
284 | - * |
|
285 | - * @param $str: String a evaluar |
|
286 | - * |
|
287 | - * @return int Cantidad de palabras |
|
288 | - */ |
|
283 | + * Devuelve la cantidad de palabras en un string |
|
284 | + * |
|
285 | + * @param $str: String a evaluar |
|
286 | + * |
|
287 | + * @return int Cantidad de palabras |
|
288 | + */ |
|
289 | 289 | final public static function count_words(string $s) : int { |
290 | 290 | return (int) str_word_count($s,0,'0..9_'); |
291 | 291 | } |
292 | 292 | //------------------------------------------------ |
293 | 293 | /** |
294 | - * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
|
295 | - * |
|
296 | - * @return array Todas las funciones con sus respectivos nombres de acceso en plantillas twig |
|
297 | - */ |
|
294 | + * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
|
295 | + * |
|
296 | + * @return array Todas las funciones con sus respectivos nombres de acceso en plantillas twig |
|
297 | + */ |
|
298 | 298 | public function getFunctions() : array { |
299 | 299 | return array( |
300 | 300 | new \Twig_Function('amigable_time', array($this, 'amigable_time')), |
@@ -318,10 +318,10 @@ discard block |
||
318 | 318 | } |
319 | 319 | //------------------------------------------------ |
320 | 320 | /** |
321 | - * Identificador único para la extensión de twig |
|
322 | - * |
|
323 | - * @return string Nombre de la extensión |
|
324 | - */ |
|
321 | + * Identificador único para la extensión de twig |
|
322 | + * |
|
323 | + * @return string Nombre de la extensión |
|
324 | + */ |
|
325 | 325 | public function getName() : string { |
326 | 326 | return 'ocrend_framework_helper_strings'; |
327 | 327 | } |
@@ -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 | /** |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @return int Cantidad de palabras |
288 | 288 | */ |
289 | 289 | final public static function count_words(string $s) : int { |
290 | - return (int) str_word_count($s,0,'0..9_'); |
|
290 | + return (int) str_word_count($s, 0, '0..9_'); |
|
291 | 291 | } |
292 | 292 | //------------------------------------------------ |
293 | 293 | /** |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | //------------------------------------------------ |
103 | 103 | |
104 | 104 | /** |
105 | - * Evalúa si un arreglo es de tipo asociativo o no |
|
106 | - * |
|
107 | - * @param array $a: Arreglo a evaluar |
|
108 | - * |
|
109 | - * @return bool false si no lo es, true si lo es |
|
110 | - */ |
|
105 | + * Evalúa si un arreglo es de tipo asociativo o no |
|
106 | + * |
|
107 | + * @param array $a: Arreglo a evaluar |
|
108 | + * |
|
109 | + * @return bool false si no lo es, true si lo es |
|
110 | + */ |
|
111 | 111 | final public static function is_assoc(array $a) : bool { |
112 | 112 | if (sizeof($a) === 0) { |
113 | 113 | return false; |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | //------------------------------------------------ |
120 | 120 | |
121 | 121 | /** |
122 | - * Evalúa si un arreglo es secuencial (de índices numéricos) |
|
123 | - * |
|
124 | - * @param array $a: Arreglo a evaluar |
|
125 | - * |
|
126 | - * @return bool false si no lo es, true si lo es |
|
127 | - */ |
|
122 | + * Evalúa si un arreglo es secuencial (de índices numéricos) |
|
123 | + * |
|
124 | + * @param array $a: Arreglo a evaluar |
|
125 | + * |
|
126 | + * @return bool false si no lo es, true si lo es |
|
127 | + */ |
|
128 | 128 | final public static function is_numeric_array(array $a) : bool { |
129 | 129 | return !self::is_assoc($a); |
130 | 130 | } |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | //------------------------------------------------ |
133 | 133 | |
134 | 134 | /** |
135 | - * Obtiene de forma random un elemento de un arreglo |
|
136 | - * |
|
137 | - * @param array $a: Arreglo a evaluar |
|
138 | - * |
|
139 | - * @return mixed elemento random dentro del arreglo |
|
140 | - */ |
|
135 | + * Obtiene de forma random un elemento de un arreglo |
|
136 | + * |
|
137 | + * @param array $a: Arreglo a evaluar |
|
138 | + * |
|
139 | + * @return mixed elemento random dentro del arreglo |
|
140 | + */ |
|
141 | 141 | final public static function array_random_element(array $a) { |
142 | 142 | return $a[array_rand($a)]; |
143 | 143 | } |
@@ -145,14 +145,14 @@ discard block |
||
145 | 145 | //------------------------------------------------ |
146 | 146 | |
147 | 147 | /** |
148 | - * Ordena una matriz de mayor a menor, o menor a mayor por el valor de un campo específico |
|
149 | - * |
|
150 | - * @param array $toOrderArray : Arreglo a evaluar |
|
151 | - * @param string $field: Campo por el que se va a ordenar |
|
152 | - * @param bool $inverse: Por defecto falso, cambia el orden |
|
153 | - * |
|
154 | - * @return mixed elemento random dentro del arreglo |
|
155 | - */ |
|
148 | + * Ordena una matriz de mayor a menor, o menor a mayor por el valor de un campo específico |
|
149 | + * |
|
150 | + * @param array $toOrderArray : Arreglo a evaluar |
|
151 | + * @param string $field: Campo por el que se va a ordenar |
|
152 | + * @param bool $inverse: Por defecto falso, cambia el orden |
|
153 | + * |
|
154 | + * @return mixed elemento random dentro del arreglo |
|
155 | + */ |
|
156 | 156 | final public static function order_multi_dimensional(array $toOrderArray, string $field, bool $inverse = false) : array { |
157 | 157 | $position = array(); |
158 | 158 | $newRow = array(); |
@@ -173,10 +173,10 @@ discard block |
||
173 | 173 | //------------------------------------------------ |
174 | 174 | |
175 | 175 | /** |
176 | - * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
|
177 | - * |
|
178 | - * @return array con todas las funciones con sus respectivos nombres de acceso en plantillas twig |
|
179 | - */ |
|
176 | + * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
|
177 | + * |
|
178 | + * @return array con todas las funciones con sus respectivos nombres de acceso en plantillas twig |
|
179 | + */ |
|
180 | 180 | public function getFunctions() : array { |
181 | 181 | return array( |
182 | 182 | new \Twig_Function('get_key_by_index', array($this, 'get_key_by_index')), |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | //------------------------------------------------ |
192 | 192 | |
193 | 193 | /** |
194 | - * Identificador único para la extensión de twig |
|
195 | - * |
|
196 | - * @return string con el nombre de la extensión |
|
197 | - */ |
|
194 | + * Identificador único para la extensión de twig |
|
195 | + * |
|
196 | + * @return string con el nombre de la extensión |
|
197 | + */ |
|
198 | 198 | public function getName() : string { |
199 | 199 | return 'ocrend_framework_helper_arrays'; |
200 | 200 | } |
@@ -50,12 +50,12 @@ discard block |
||
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 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $position = array(); |
158 | 158 | $newRow = array(); |
159 | 159 | foreach ($toOrderArray as $key => $row) { |
160 | - $position[$key] = $row[$field]; |
|
160 | + $position[$key] = $row[$field]; |
|
161 | 161 | $newRow[$key] = $row; |
162 | 162 | } |
163 | 163 | $inverse ? arsort($position) : asort($position); |