@@ -42,6 +42,10 @@ discard block |
||
42 | 42 | * @return Form |
43 | 43 | */ |
44 | 44 | public function setEncType($enctype) { $this->enctype = $enctype; return $this; } |
45 | + |
|
46 | + /** |
|
47 | + * @param string|null $action |
|
48 | + */ |
|
45 | 49 | public function setAction($action) { $this->action = $action; return $this; } |
46 | 50 | public function setMethod($method) { $this->method = $method; return $this; } |
47 | 51 | public function setAttrs(array $attrs) { $this->attrs = $attrs; return $this; } |
@@ -466,7 +470,7 @@ discard block |
||
466 | 470 | } |
467 | 471 | |
468 | 472 | /** |
469 | - * @param $token_field |
|
473 | + * @param string $token_field |
|
470 | 474 | * @return bool |
471 | 475 | */ |
472 | 476 | protected function existsFormToken($token_field) { |
@@ -494,7 +498,7 @@ discard block |
||
494 | 498 | /** |
495 | 499 | * Método que extrae el valor de un campo del formulario del modelo |
496 | 500 | * @param $field |
497 | - * @param $value |
|
501 | + * @param ObjectCollection $value |
|
498 | 502 | * @param $type |
499 | 503 | * @return mixed |
500 | 504 | */ |
@@ -156,7 +156,9 @@ discard block |
||
156 | 156 | //Validamos los campos del formulario |
157 | 157 | if ($valid && count($this->fields) > 0) { |
158 | 158 | foreach ($this->fields as $key => &$field) { |
159 | - if ($key === $token_field || $key === self::SEPARATOR) continue; |
|
159 | + if ($key === $token_field || $key === self::SEPARATOR) { |
|
160 | + continue; |
|
161 | + } |
|
160 | 162 | list($field, $valid) = $this->checkFieldValidation($field, $key); |
161 | 163 | } |
162 | 164 | } |
@@ -442,7 +444,7 @@ discard block |
||
442 | 444 | //Si es una relación múltiple |
443 | 445 | if ($value instanceof ObjectCollection) { |
444 | 446 | $field = $this->computeModelFieldValue($field, $value, $type); |
445 | - }else { //O una relación unitaria |
|
447 | + } else { //O una relación unitaria |
|
446 | 448 | if (method_exists($value, "__toString")) { |
447 | 449 | $field["value"] = $value; |
448 | 450 | } elseif ($value instanceof \DateTime) { |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use PSFS\base\Singleton; |
13 | 13 | use PSFS\base\types\interfaces\FormType; |
14 | 14 | |
15 | - abstract class Form extends Singleton implements FormType{ |
|
15 | + abstract class Form extends Singleton implements FormType { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Variables de formulario |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | public function __construct($model = null) |
33 | 33 | { |
34 | - if(null !== $model) { |
|
34 | + if (null !== $model) { |
|
35 | 35 | $this->model = $model; |
36 | 36 | } |
37 | 37 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getFieldValue($name) { |
124 | 124 | $value = null; |
125 | - if (null !== $this->getField($name)){ |
|
125 | + if (null !== $this->getField($name)) { |
|
126 | 126 | $field = $this->getField($name); |
127 | 127 | $value = (array_key_exists('value', $field) && null !== $field['value']) ? $field['value'] : null; |
128 | 128 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | $model->save(); |
322 | 322 | $save = true; |
323 | 323 | Logger::getInstance()->infoLog(get_class($this->model)." guardado con id ".$this->model->getPrimaryKey()); |
324 | - } catch (\Exception $e) { |
|
324 | + }catch (\Exception $e) { |
|
325 | 325 | Logger::getInstance()->errorLog($e->getMessage()); |
326 | 326 | throw new FormException($e->getMessage(), $e->getCode(), $e); |
327 | 327 | } |
@@ -336,13 +336,13 @@ discard block |
||
336 | 336 | protected function checkEmpty($value) { |
337 | 337 | $isEmpty = false; |
338 | 338 | // NULL check |
339 | - if(null === $value) { |
|
339 | + if (null === $value) { |
|
340 | 340 | $isEmpty = true; |
341 | 341 | // Empty Array check |
342 | - } else if(is_array($value) && 0 === count($value)) { |
|
342 | + }else if (is_array($value) && 0 === count($value)) { |
|
343 | 343 | $isEmpty = true; |
344 | 344 | // Empty string check |
345 | - } else if(0 === strlen(preg_replace('/(\ |\r|\n)/m', '', $value))) { |
|
345 | + }else if (0 === strlen(preg_replace('/(\ |\r|\n)/m', '', $value))) { |
|
346 | 346 | $isEmpty = true; |
347 | 347 | } |
348 | 348 | |
@@ -388,10 +388,10 @@ discard block |
||
388 | 388 | if (array_key_exists($key, $data[$form_name])) { |
389 | 389 | if (preg_match("/id/i", $key) && ($data[$form_name][$key] === 0 || $data[$form_name][$key] === "%" || $data[$form_name][$key] === "")) { |
390 | 390 | $field["value"] = null; |
391 | - } else { |
|
391 | + }else { |
|
392 | 392 | $field["value"] = $data[$form_name][$key]; |
393 | 393 | } |
394 | - } else { |
|
394 | + }else { |
|
395 | 395 | unset($field["value"]); |
396 | 396 | } |
397 | 397 | return array($data, $field); |
@@ -435,10 +435,10 @@ discard block |
||
435 | 435 | if (array_key_exists('class_id', $field) && method_exists($class, "get".$field["class_id"])) { |
436 | 436 | $method = "get".$field["class_id"]; |
437 | 437 | $data[] = $class->$method(); |
438 | - } else { |
|
438 | + }else { |
|
439 | 439 | $data[] = $class->getPrimaryKey(); |
440 | 440 | } |
441 | - } else { |
|
441 | + }else { |
|
442 | 442 | $data[] = $val; |
443 | 443 | } |
444 | 444 | |
@@ -468,11 +468,11 @@ discard block |
||
468 | 468 | $field["value"] = $value; |
469 | 469 | } elseif ($value instanceof \DateTime) { |
470 | 470 | $field["value"] = $value->format("Y-m-d H:i:s"); |
471 | - } else { |
|
471 | + }else { |
|
472 | 472 | $field["value"] = $value->getPrimaryKey(); |
473 | 473 | } |
474 | 474 | } |
475 | - } else { |
|
475 | + }else { |
|
476 | 476 | $field["value"] = $value; |
477 | 477 | } |
478 | 478 | } |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | { |
32 | 32 | $order = array(); |
33 | 33 | if (count($order) > 0) { |
34 | - foreach($this->fields as $field => $direction) { |
|
35 | - if(strtolower($fieldToRemove) === strtolower($field)) { |
|
34 | + foreach ($this->fields as $field => $direction) { |
|
35 | + if (strtolower($fieldToRemove) === strtolower($field)) { |
|
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | $order[$field] = $direction; |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public static function parseDirection($direction = Order::ASC) |
62 | 62 | { |
63 | - if(preg_match('/^asc$/i', $direction)) { |
|
63 | + if (preg_match('/^asc$/i', $direction)) { |
|
64 | 64 | return Order::ASC; |
65 | - } else { |
|
65 | + }else { |
|
66 | 66 | return Order::DESC; |
67 | 67 | } |
68 | 68 | } |
@@ -303,7 +303,7 @@ |
||
303 | 303 | $js = file_get_contents($file); |
304 | 304 | try { |
305 | 305 | $data .= ";\n".$js; |
306 | - }catch (\Exception $e) { |
|
306 | + } catch (\Exception $e) { |
|
307 | 307 | throw new ConfigException($e->getMessage()); |
308 | 308 | } |
309 | 309 | return $data; |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function setHash($hash) |
88 | 88 | { |
89 | - $cache = Config::getInstance()->get('cache.var') ?: ''; |
|
90 | - $this->hash = $hash . (strlen($cache) ? '.' : '') . $cache; |
|
89 | + $cache = Config::getInstance()->get('cache.var') ?: ''; |
|
90 | + $this->hash = $hash . (strlen($cache) ? '.' : '') . $cache; |
|
91 | 91 | return $this; |
92 | 92 | } |
93 | 93 | |
@@ -350,9 +350,9 @@ discard block |
||
350 | 350 | $file = ""; |
351 | 351 | $html_base = ""; |
352 | 352 | $debug = Config::getInstance()->getDebugMode(); |
353 | - $cache = Config::getInstance()->get('cache.var'); |
|
354 | - $cache = $cache ? '.'.$cache : ''; |
|
355 | - if (preg_match('/\.css$/i', $string)) { |
|
353 | + $cache = Config::getInstance()->get('cache.var'); |
|
354 | + $cache = $cache ? '.'.$cache : ''; |
|
355 | + if (preg_match('/\.css$/i', $string)) { |
|
356 | 356 | $file = "/".substr(md5($string), 0, 8)."$cache.css"; |
357 | 357 | $html_base = "css"; |
358 | 358 | if ($debug) { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | public function setHash($hash) |
88 | 88 | { |
89 | 89 | $cache = Config::getInstance()->get('cache.var') ?: ''; |
90 | - $this->hash = $hash . (strlen($cache) ? '.' : '') . $cache; |
|
90 | + $this->hash = $hash.(strlen($cache) ? '.' : '').$cache; |
|
91 | 91 | return $this; |
92 | 92 | } |
93 | 93 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | try { |
156 | 156 | $minifiedJs = Minifier::minify($data); |
157 | - } catch(\Exception $e) { |
|
157 | + }catch (\Exception $e) { |
|
158 | 158 | Logger::log($e->getMessage(), LOG_ERR); |
159 | 159 | $minifiedJs = false; |
160 | 160 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | foreach ($this->compiled_files as $file) { |
198 | 198 | echo "\t\t<script type='text/javascript' src='{$file}'></script>\n"; |
199 | 199 | } |
200 | - } else { |
|
200 | + }else { |
|
201 | 201 | echo "\t\t<script type='text/javascript' src='/js/".$this->hash.".js'></script>\n"; |
202 | 202 | } |
203 | 203 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | foreach ($this->compiled_files as $file) { |
212 | 212 | echo "\t\t<link href='{$file}' rel='stylesheet' media='screen, print'>"; |
213 | 213 | } |
214 | - } else { |
|
214 | + }else { |
|
215 | 215 | echo "\t\t<link href='/css/".$this->hash.".css' rel='stylesheet'>"; |
216 | 216 | } |
217 | 217 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | Logger::log("$orig copiado a $dest", LOG_INFO); |
237 | 237 | } |
238 | 238 | } |
239 | - } catch (\Exception $e) { |
|
239 | + }catch (\Exception $e) { |
|
240 | 240 | Logger::log($e->getMessage(), LOG_ERR); |
241 | 241 | } |
242 | 242 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | if ($this->debug) { |
265 | 265 | $data = file_get_contents($file); |
266 | 266 | $this->storeContents($base.$file_path, $data); |
267 | - } else { |
|
267 | + }else { |
|
268 | 268 | $data .= file_get_contents($file); |
269 | 269 | } |
270 | 270 | $this->compiled_files[] = "/css/".$file_path; |
@@ -135,7 +135,7 @@ |
||
135 | 135 | $tmp = array(); |
136 | 136 | if (NULL === $node) { |
137 | 137 | $node = $value; |
138 | - }else { |
|
138 | + } else { |
|
139 | 139 | $tmp = $this->getTmpAttribute($node); |
140 | 140 | } |
141 | 141 | $tmp[] = $value->getAttribute("value"); |
@@ -52,7 +52,7 @@ |
||
52 | 52 | $router = Router::getInstance(); |
53 | 53 | try { |
54 | 54 | return $router->getRoute($path, $absolute, $params); |
55 | - } catch (\Exception $e) |
|
55 | + }catch (\Exception $e) |
|
56 | 56 | { |
57 | 57 | return $router->getRoute('', $absolute, $params); |
58 | 58 | } |
@@ -136,7 +136,7 @@ |
||
136 | 136 | * @param string $path |
137 | 137 | * @param $domains |
138 | 138 | * |
139 | - * @return mixed |
|
139 | + * @return string |
|
140 | 140 | */ |
141 | 141 | private static function extractPathname($path, $domains) |
142 | 142 | { |
@@ -179,8 +179,11 @@ |
||
179 | 179 | private static function putResourceContent($name, $filename_path, $base, $file_path) |
180 | 180 | { |
181 | 181 | $data = file_get_contents($filename_path); |
182 | - if (!empty($name)) file_put_contents(WEB_DIR.DIRECTORY_SEPARATOR.$name, $data); |
|
183 | - else file_put_contents($base.$file_path, $data); |
|
182 | + if (!empty($name)) { |
|
183 | + file_put_contents(WEB_DIR.DIRECTORY_SEPARATOR.$name, $data); |
|
184 | + } else { |
|
185 | + file_put_contents($base.$file_path, $data); |
|
186 | + } |
|
184 | 187 | } |
185 | 188 | |
186 | 189 | /** |
@@ -31,14 +31,18 @@ |
||
31 | 31 | //Hidratamos con los comandos de PSFS |
32 | 32 | $commands = new Finder(); |
33 | 33 | $commands->in(__DIR__)->notName("PSFSConsole.php"); |
34 | - foreach ($commands as $com) include_once($com->getRealPath()); |
|
34 | + foreach ($commands as $com) { |
|
35 | + include_once($com->getRealPath()); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | //Hidratamos con los comandos de los módulos |
37 | 39 | if (file_exists(CORE_DIR)) |
38 | 40 | { |
39 | 41 | $commands = new Finder(); |
40 | 42 | $commands->in(CORE_DIR)->path("Command")->name("*.php"); |
41 | - foreach ($commands as $com) include_once($com->getRealPath()); |
|
43 | + foreach ($commands as $com) { |
|
44 | + include_once($com->getRealPath()); |
|
45 | + } |
|
42 | 46 | } |
43 | 47 | |
44 | 48 | $console->run(); |
@@ -21,7 +21,7 @@ |
||
21 | 21 | { |
22 | 22 | $array = array(); |
23 | 23 | $array['fields'] = array(); |
24 | - foreach($this->fields as $field) { |
|
24 | + foreach ($this->fields as $field) { |
|
25 | 25 | $array['fields'][] = $field->__toArray(); |
26 | 26 | } |
27 | 27 | return $array; |
@@ -26,13 +26,13 @@ |
||
26 | 26 | { |
27 | 27 | $namespace = explode('\\', $this->getModelTableMap()); |
28 | 28 | $module = strtolower($namespace[0]); |
29 | - $secret = Config::getInstance()->get($module . '.api.secret'); |
|
29 | + $secret = Config::getInstance()->get($module.'.api.secret'); |
|
30 | 30 | if (NULL === $secret) { |
31 | 31 | $secret = Config::getInstance()->get("api.secret"); |
32 | 32 | } |
33 | 33 | if (NULL === $secret) { |
34 | 34 | $auth = TRUE; |
35 | - } else { |
|
35 | + }else { |
|
36 | 36 | $token = Request::getInstance()->getHeader('X-API-SEC-TOKEN'); |
37 | 37 | if (array_key_exists('API_TOKEN', $this->query)) { |
38 | 38 | $token = $this->query['API_TOKEN']; |
@@ -422,7 +422,7 @@ |
||
422 | 422 | "type" => $type, |
423 | 423 | ]; |
424 | 424 | if (strlen($format)) { |
425 | - $dto['properties'][$field]['format'] = $format; |
|
425 | + $dto['properties'][$field]['format'] = $format; |
|
426 | 426 | } |
427 | 427 | } |
428 | 428 | } |
@@ -339,7 +339,7 @@ |
||
339 | 339 | * Translator from php types to swagger types |
340 | 340 | * @param string $format |
341 | 341 | * |
342 | - * @return array |
|
342 | + * @return string[] |
|
343 | 343 | */ |
344 | 344 | public static function translateSwaggerFormats($format) |
345 | 345 | { |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | if (!preg_match('/^ROOT/i', $module)) { |
38 | 38 | $modules[] = [ |
39 | 39 | 'name' => $module, |
40 | - 'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'), |
|
40 | + 'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'), |
|
41 | 41 | ]; |
42 | 42 | } |
43 | - } catch (\Exception $e) { |
|
43 | + }catch (\Exception $e) { |
|
44 | 44 | $modules[] = $e->getMessage(); |
45 | 45 | } |
46 | 46 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function extractApiEndpoints(array $module) |
60 | 60 | { |
61 | - $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api'; |
|
61 | + $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api'; |
|
62 | 62 | $module_name = $module['name']; |
63 | 63 | $endpoints = []; |
64 | 64 | if (file_exists($module_path)) { |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | if (count($finder)) { |
68 | 68 | /** @var \SplFileInfo $file */ |
69 | 69 | foreach ($finder as $file) { |
70 | - $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename()); |
|
70 | + $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename()); |
|
71 | 71 | $info = $this->extractApiInfo($namespace, $module_name); |
72 | - if(!empty($info)) { |
|
72 | + if (!empty($info)) { |
|
73 | 73 | $endpoints[$namespace] = $info; |
74 | 74 | } |
75 | 75 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | public function extractApiInfo($namespace, $module) |
89 | 89 | { |
90 | 90 | $info = []; |
91 | - if(class_exists($namespace)) { |
|
91 | + if (class_exists($namespace)) { |
|
92 | 92 | $reflection = new \ReflectionClass($namespace); |
93 | 93 | foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
94 | 94 | try { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | if (NULL !== $mInfo) { |
97 | 97 | $info[] = $mInfo; |
98 | 98 | } |
99 | - } catch (\Exception $e) { |
|
99 | + }catch (\Exception $e) { |
|
100 | 100 | Logger::getInstance()->errorLog($e->getMessage()); |
101 | 101 | } |
102 | 102 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | protected function extractReturn($model, $comments = '') |
256 | 256 | { |
257 | - $modelDto = []; |
|
257 | + $modelDto = []; |
|
258 | 258 | preg_match('/\@return\ (.*)\((.*)\)\n/i', $comments, $returnTypes); |
259 | 259 | if (count($returnTypes)) { |
260 | 260 | // Extract principal DTO information |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
308 | 308 | $payload = $this->extractDtoProperties($namespace); |
309 | 309 | } |
310 | - } catch (\Exception $e) { |
|
310 | + }catch (\Exception $e) { |
|
311 | 311 | Logger::getInstance()->errorLog($e->getMessage()); |
312 | 312 | } |
313 | 313 | |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | if (in_array($methodInfo['method'], ['POST', 'PUT'])) { |
345 | 345 | $methodInfo['payload'] = $this->extractPayload($modelNamespace, $docComments); |
346 | 346 | } |
347 | - } catch (\Exception $e) { |
|
347 | + }catch (\Exception $e) { |
|
348 | 348 | jpre($e->getMessage()); |
349 | 349 | Logger::getInstance()->errorLog($e->getMessage()); |
350 | 350 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public static function translateSwaggerFormats($format) |
364 | 364 | { |
365 | - switch(strtolower($format)) { |
|
365 | + switch (strtolower($format)) { |
|
366 | 366 | case 'bool': |
367 | 367 | case 'boolean': |
368 | 368 | $swaggerType = 'boolean'; |
@@ -423,13 +423,13 @@ discard block |
||
423 | 423 | ]]); |
424 | 424 | if (array_key_exists($subDtoName, $subDto)) { |
425 | 425 | $definitions = $subDto; |
426 | - } else { |
|
426 | + }else { |
|
427 | 427 | $definitions[$subDtoName] = $subDto; |
428 | 428 | } |
429 | 429 | $dto['properties'][$field] = [ |
430 | - '$ref' => "#/definitions/" . $subDtoName, |
|
430 | + '$ref' => "#/definitions/".$subDtoName, |
|
431 | 431 | ]; |
432 | - } else { |
|
432 | + }else { |
|
433 | 433 | list($type, $format) = self::translateSwaggerFormats($format); |
434 | 434 | $dto['properties'][$field] = [ |
435 | 435 | "type" => $type, |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | "url" => Router::getInstance()->getRoute(''), |
467 | 467 | ] |
468 | 468 | ]; |
469 | - foreach($endpoints as $model) { |
|
469 | + foreach ($endpoints as $model) { |
|
470 | 470 | foreach ($model as $endpoint) { |
471 | 471 | $dtos += self::extractSwaggerDefinition($endpoint); |
472 | 472 | } |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | protected function extractDtoName($dto, $isArray = false) |
486 | 486 | { |
487 | 487 | $dto = explode('\\', $dto); |
488 | - $modelDto = array_pop($dto) . "Dto"; |
|
488 | + $modelDto = array_pop($dto)."Dto"; |
|
489 | 489 | if ($isArray) { |
490 | 490 | $modelDto .= "List"; |
491 | 491 | } |