| @@ -53,10 +53,10 @@ discard block | ||
| 53 | 53 |                      if (!preg_match('/^ROOT/i', $module) && $module == $requestModule) { | 
| 54 | 54 | $modules = [ | 
| 55 | 55 | 'name' => $module, | 
| 56 | - 'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'), | |
| 56 | + 'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'), | |
| 57 | 57 | ]; | 
| 58 | 58 | } | 
| 59 | -                } catch (\Exception $e) { | |
| 59 | +                }catch (\Exception $e) { | |
| 60 | 60 | $modules[] = $e->getMessage(); | 
| 61 | 61 | } | 
| 62 | 62 | } | 
| @@ -74,7 +74,7 @@ discard block | ||
| 74 | 74 | */ | 
| 75 | 75 | public function extractApiEndpoints(array $module) | 
| 76 | 76 |      { | 
| 77 | - $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api'; | |
| 77 | + $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api'; | |
| 78 | 78 | $module_name = $module['name']; | 
| 79 | 79 | $endpoints = []; | 
| 80 | 80 |          if (file_exists($module_path)) { | 
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 |              if (count($finder)) { | 
| 84 | 84 | /** @var \SplFileInfo $file */ | 
| 85 | 85 |                  foreach ($finder as $file) { | 
| 86 | -                    $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename()); | |
| 86 | +                    $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename()); | |
| 87 | 87 | $info = $this->extractApiInfo($namespace, $module_name); | 
| 88 | 88 |                      if (!empty($info)) { | 
| 89 | 89 | $endpoints[$namespace] = $info; | 
| @@ -112,7 +112,7 @@ discard block | ||
| 112 | 112 |                      if (NULL !== $mInfo) { | 
| 113 | 113 | $info[] = $mInfo; | 
| 114 | 114 | } | 
| 115 | -                } catch (\Exception $e) { | |
| 115 | +                }catch (\Exception $e) { | |
| 116 | 116 | Logger::getInstance()->errorLog($e->getMessage()); | 
| 117 | 117 | } | 
| 118 | 118 | } | 
| @@ -325,7 +325,7 @@ discard block | ||
| 325 | 325 |              } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { | 
| 326 | 326 | $payload = $this->extractDtoProperties($namespace); | 
| 327 | 327 | } | 
| 328 | -        } catch (\Exception $e) { | |
| 328 | +        }catch (\Exception $e) { | |
| 329 | 329 | Logger::getInstance()->errorLog($e->getMessage()); | 
| 330 | 330 | } | 
| 331 | 331 | |
| @@ -356,7 +356,7 @@ discard block | ||
| 356 | 356 | $return = $this->extractReturn($modelNamespace, $docComments); | 
| 357 | 357 | $url = array_pop($route); | 
| 358 | 358 | $methodInfo = [ | 
| 359 | -                        'url' => str_replace("/" . $module . "/api", '', $url), | |
| 359 | +                        'url' => str_replace("/".$module."/api", '', $url), | |
| 360 | 360 | 'method' => $info['http'], | 
| 361 | 361 | 'description' => $info['label'], | 
| 362 | 362 | 'return' => $return, | 
| @@ -367,7 +367,7 @@ discard block | ||
| 367 | 367 | $this->setRequestParams($method, $methodInfo, $modelNamespace, $docComments); | 
| 368 | 368 | $this->setQueryParams($method, $methodInfo); | 
| 369 | 369 | $this->setRequestHeaders($reflection, $methodInfo); | 
| 370 | -                } catch (\Exception $e) { | |
| 370 | +                }catch (\Exception $e) { | |
| 371 | 371 | jpre($e->getMessage()); | 
| 372 | 372 | Logger::getInstance()->errorLog($e->getMessage()); | 
| 373 | 373 | } | 
| @@ -517,10 +517,10 @@ discard block | ||
| 517 | 517 | $formatted = [ | 
| 518 | 518 | "swagger" => "2.0", | 
| 519 | 519 |              "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)), | 
| 520 | - "basePath" => '/' . $module['name'] . '/api', | |
| 520 | + "basePath" => '/'.$module['name'].'/api', | |
| 521 | 521 |              "schemes" => [Request::getInstance()->getServer('HTTPS') == 'on' ? "https" : "http"], | 
| 522 | 522 | "info" => [ | 
| 523 | -                "title" => _('Documentación API módulo ') . $module['name'], | |
| 523 | +                "title" => _('Documentación API módulo ').$module['name'], | |
| 524 | 524 |                  "version" => Config::getParam('api.version', '1.0'), | 
| 525 | 525 | "contact" => [ | 
| 526 | 526 |                      "name" => Config::getParam("author", "Fran López"), | 
| @@ -533,7 +533,7 @@ discard block | ||
| 533 | 533 |          foreach ($endpoints as $model) { | 
| 534 | 534 |              foreach ($model as $endpoint) { | 
| 535 | 535 |                  if (!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) { | 
| 536 | -                    $url = preg_replace('/\/' . $module['name'] . '\/api/i', '', $endpoint['url']); | |
| 536 | +                    $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']); | |
| 537 | 537 | $description = $endpoint['description']; | 
| 538 | 538 | $method = strtolower($endpoint['method']); | 
| 539 | 539 | $paths[$url][$method] = [ | 
| @@ -570,7 +570,7 @@ discard block | ||
| 570 | 570 | $class = GeneratorHelper::extractClassFromNamespace($name); | 
| 571 | 571 | $classDefinition = [ | 
| 572 | 572 | 'type' => 'object', | 
| 573 | - '$ref' => '#/definitions/' . $class, | |
| 573 | + '$ref' => '#/definitions/'.$class, | |
| 574 | 574 | ]; | 
| 575 | 575 | $paths[$url][$method]['responses'][200]['schema']['properties']['data'] = $classDefinition; | 
| 576 | 576 | $dtos += self::extractSwaggerDefinition($class, $object); | 
| @@ -605,7 +605,7 @@ discard block | ||
| 605 | 605 | protected function extractDtoName($dto, $isArray = false) | 
| 606 | 606 |      { | 
| 607 | 607 |          $dto = explode('\\', $dto); | 
| 608 | - $modelDto = array_pop($dto) . "Dto"; | |
| 608 | + $modelDto = array_pop($dto)."Dto"; | |
| 609 | 609 |          if ($isArray) { | 
| 610 | 610 | $modelDto .= "List"; | 
| 611 | 611 | } | 
| @@ -655,10 +655,10 @@ discard block | ||
| 655 | 655 |      { | 
| 656 | 656 | |
| 657 | 657 | $methodInfo['headers'] = []; | 
| 658 | -        foreach($reflection->getProperties() as $property) { | |
| 658 | +        foreach ($reflection->getProperties() as $property) { | |
| 659 | 659 | $doc = $property->getDocComment(); | 
| 660 | 660 |              preg_match('/@header\ (.*)\n/i', $doc, $headers); | 
| 661 | -            if(count($headers)) { | |
| 661 | +            if (count($headers)) { | |
| 662 | 662 | $header = [ | 
| 663 | 663 | "name" => $headers[1], | 
| 664 | 664 | "in" => "header", | 
| @@ -667,19 +667,19 @@ discard block | ||
| 667 | 667 | |
| 668 | 668 | // Extract var type | 
| 669 | 669 |                  preg_match('/@var\ (.*)\n/i', $doc, $type); | 
| 670 | -                if(count($type)) { | |
| 670 | +                if (count($type)) { | |
| 671 | 671 | $header['type'] = $type[1]; | 
| 672 | 672 | } | 
| 673 | 673 | |
| 674 | 674 | // Extract description | 
| 675 | 675 |                  preg_match('/@label\ (.*)\n/i', $doc, $label); | 
| 676 | -                if(count($label)) { | |
| 676 | +                if (count($label)) { | |
| 677 | 677 | $header['description'] = _($label[1]); | 
| 678 | 678 | } | 
| 679 | 679 | |
| 680 | 680 | // Extract default value | 
| 681 | 681 |                  preg_match('/@default\ (.*)\n/i', $doc, $default); | 
| 682 | -                if(count($default)) { | |
| 682 | +                if (count($default)) { | |
| 683 | 683 | $header['default'] = $default[1]; | 
| 684 | 684 | } | 
| 685 | 685 | $methodInfo['headers'][] = $header; | 
| @@ -706,7 +706,7 @@ discard block | ||
| 706 | 706 |              foreach ($method->getParameters() as $parameter) { | 
| 707 | 707 | $parameterName = $parameter->getName(); | 
| 708 | 708 | $types = []; | 
| 709 | -                preg_match_all('/\@param\ (.*)\ \$' . $parameterName . '$/im', $docComments, $types); | |
| 709 | +                preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types); | |
| 710 | 710 |                  if (count($types) > 1) { | 
| 711 | 711 | $methodInfo['parameters'][$parameterName] = $types[1][0]; | 
| 712 | 712 | } | 
| @@ -65,21 +65,21 @@ discard block | ||
| 65 | 65 |          if (count($pks) == 1) { | 
| 66 | 66 | $pks = array_keys($pks); | 
| 67 | 67 | return [ | 
| 68 | - $tableMap::TABLE_NAME . '.' . $pks[0] => Api::API_MODEL_KEY_FIELD | |
| 68 | + $tableMap::TABLE_NAME.'.'.$pks[0] => Api::API_MODEL_KEY_FIELD | |
| 69 | 69 | ]; | 
| 70 | 70 |          } elseif (count($pks) > 1) { | 
| 71 | 71 | $apiPks = []; | 
| 72 | 72 | $principal = ''; | 
| 73 | 73 |              $sep = 'CONCAT('; | 
| 74 | 74 |              foreach ($pks as $pk) { | 
| 75 | - $apiPks[$tableMap::TABLE_NAME . '.' . $pk->getName()] = $pk->getPhpName(); | |
| 76 | - $principal .= $sep . $tableMap::TABLE_NAME . '.' . $pk->getName(); | |
| 77 | - $sep = ', "' . Api::API_PK_SEPARATOR . '", '; | |
| 75 | + $apiPks[$tableMap::TABLE_NAME.'.'.$pk->getName()] = $pk->getPhpName(); | |
| 76 | + $principal .= $sep.$tableMap::TABLE_NAME.'.'.$pk->getName(); | |
| 77 | + $sep = ', "'.Api::API_PK_SEPARATOR.'", '; | |
| 78 | 78 | } | 
| 79 | 79 | $principal .= ')'; | 
| 80 | 80 | $apiPks[$principal] = Api::API_MODEL_KEY_FIELD; | 
| 81 | 81 | return $apiPks; | 
| 82 | -        } else { | |
| 82 | +        }else { | |
| 83 | 83 |              throw new ApiException(_('El modelo de la API no está debidamente mapeado, no hay Primary Key o es compuesta')); | 
| 84 | 84 | } | 
| 85 | 85 | } | 
| @@ -102,10 +102,10 @@ discard block | ||
| 102 | 102 | $pks = ''; | 
| 103 | 103 | $sep = ''; | 
| 104 | 104 |          foreach ($tableMap->getPrimaryKeys() as $pk) { | 
| 105 | - $pks .= $sep . $pk->getFullyQualifiedName(); | |
| 105 | + $pks .= $sep.$pk->getFullyQualifiedName(); | |
| 106 | 106 | $sep = ', "|", '; | 
| 107 | 107 | } | 
| 108 | -        $this->extraColumns['CONCAT("' . $tableMap->getPhpName() . ' #", ' . $pks . ')'] = Api::API_LIST_NAME_FIELD; | |
| 108 | +        $this->extraColumns['CONCAT("'.$tableMap->getPhpName().' #", '.$pks.')'] = Api::API_LIST_NAME_FIELD; | |
| 109 | 109 | } | 
| 110 | 110 | |
| 111 | 111 | /** | 
| @@ -127,7 +127,7 @@ discard block | ||
| 127 | 127 | } | 
| 128 | 128 |              if (null !== $column) { | 
| 129 | 129 | $this->extraColumns[$column->getFullyQualifiedName()] = Api::API_LIST_NAME_FIELD; | 
| 130 | -            } else { | |
| 130 | +            }else { | |
| 131 | 131 | $this->addClassListName($tableMap); | 
| 132 | 132 | } | 
| 133 | 133 | } | 
| @@ -139,7 +139,7 @@ discard block | ||
| 139 | 139 | * @param ModelCriteria $query | 
| 140 | 140 | * @param string $action | 
| 141 | 141 | */ | 
| 142 | - private function addExtraColumns(ModelCriteria &$query, $action) | |
| 142 | + private function addExtraColumns(ModelCriteria & $query, $action) | |
| 143 | 143 |      { | 
| 144 | 144 |          if (Api::API_ACTION_LIST === $action) { | 
| 145 | 145 | $this->addDefaultListField(); | 
| @@ -173,21 +173,21 @@ discard block | ||
| 173 | 173 | /** | 
| 174 | 174 | * @param ModelCriteria $query | 
| 175 | 175 | */ | 
| 176 | - protected function checkI18n(ModelCriteria &$query) | |
| 176 | + protected function checkI18n(ModelCriteria & $query) | |
| 177 | 177 |      { | 
| 178 | 178 | $this->extractApiLang(); | 
| 179 | 179 | $model = $this->getModelNamespace(); | 
| 180 | - $modelI18n = $model . 'I18n'; | |
| 180 | + $modelI18n = $model.'I18n'; | |
| 181 | 181 |          if (method_exists($query, 'useI18nQuery')) { | 
| 182 | 182 | $query->useI18nQuery($this->lang); | 
| 183 | -            $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n) . 'TableMap'; | |
| 183 | +            $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n).'TableMap'; | |
| 184 | 184 | /** @var TableMap $modelI18nTableMap */ | 
| 185 | 185 | $modelI18nTableMap = $modelI18nTableMapClass::getTableMap(); | 
| 186 | -            foreach($modelI18nTableMap->getColumns() as $columnMap) { | |
| 187 | -                if(!$columnMap->isPrimaryKey()) { | |
| 188 | - $query->withColumn($modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName(), $columnMap->getPhpName()); | |
| 189 | -                } elseif(!$columnMap->isForeignKey()) { | |
| 190 | -                    $query->withColumn('IFNULL(' . $modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName() . ', "'.$this->lang.'")', $columnMap->getPhpName()); | |
| 186 | +            foreach ($modelI18nTableMap->getColumns() as $columnMap) { | |
| 187 | +                if (!$columnMap->isPrimaryKey()) { | |
| 188 | + $query->withColumn($modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName(), $columnMap->getPhpName()); | |
| 189 | +                } elseif (!$columnMap->isForeignKey()) { | |
| 190 | +                    $query->withColumn('IFNULL('.$modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName().', "'.$this->lang.'")', $columnMap->getPhpName()); | |
| 191 | 191 | } | 
| 192 | 192 | } | 
| 193 | 193 | } | 
| @@ -197,23 +197,23 @@ discard block | ||
| 197 | 197 | * @param ActiveRecordInterface $model | 
| 198 | 198 | * @param array $data | 
| 199 | 199 | */ | 
| 200 | -    protected function hydrateModelFromRequest(ActiveRecordInterface &$model, array $data = []) { | |
| 200 | +    protected function hydrateModelFromRequest(ActiveRecordInterface & $model, array $data = []) { | |
| 201 | 201 | $model->fromArray($data); | 
| 202 | 202 | $tableMap = $this->getTableMap(); | 
| 203 | 203 |          try { | 
| 204 | - $relateI18n = $tableMap->getRelation($tableMap->getPhpName() . 'I18n'); | |
| 205 | -            if(null !== $relateI18n) { | |
| 204 | + $relateI18n = $tableMap->getRelation($tableMap->getPhpName().'I18n'); | |
| 205 | +            if (null !== $relateI18n) { | |
| 206 | 206 | $i18NTableMap = $relateI18n->getLocalTable(); | 
| 207 | -                foreach($i18NTableMap->getColumns() as $columnMap) { | |
| 208 | - $method = 'set' . $columnMap->getPhpName(); | |
| 209 | - if(!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) | |
| 207 | +                foreach ($i18NTableMap->getColumns() as $columnMap) { | |
| 208 | + $method = 'set'.$columnMap->getPhpName(); | |
| 209 | + if (!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) | |
| 210 | 210 | &&array_key_exists($columnMap->getPhpName(), $data) | 
| 211 | 211 |                          && method_exists($model, $method)) { | 
| 212 | 212 | $model->$method($data[$columnMap->getPhpName()]); | 
| 213 | 213 | } | 
| 214 | 214 | } | 
| 215 | 215 | } | 
| 216 | -        } catch(\Exception $e) { | |
| 216 | +        }catch (\Exception $e) { | |
| 217 | 217 | Logger::log($e->getMessage(), LOG_WARNING); | 
| 218 | 218 | } | 
| 219 | 219 | } |