@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace PSFS\services; |
3 | 3 | |
4 | 4 | use Propel\Runtime\Map\ColumnMap; |
5 | -use Propel\Runtime\Map\TableMap; |
|
6 | 5 | use PSFS\base\config\Config; |
7 | 6 | use PSFS\base\Logger; |
8 | 7 | use PSFS\base\Request; |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | if (!preg_match('/^ROOT/i', $module) && $module == $requestModule) { |
44 | 44 | $modules = [ |
45 | 45 | 'name' => $module, |
46 | - 'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'), |
|
46 | + 'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'), |
|
47 | 47 | ]; |
48 | 48 | } |
49 | - } catch (\Exception $e) { |
|
49 | + }catch (\Exception $e) { |
|
50 | 50 | $modules[] = $e->getMessage(); |
51 | 51 | } |
52 | 52 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function extractApiEndpoints(array $module) |
66 | 66 | { |
67 | - $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api'; |
|
67 | + $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api'; |
|
68 | 68 | $module_name = $module['name']; |
69 | 69 | $endpoints = []; |
70 | 70 | if (file_exists($module_path)) { |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | if (count($finder)) { |
74 | 74 | /** @var \SplFileInfo $file */ |
75 | 75 | foreach ($finder as $file) { |
76 | - $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename()); |
|
76 | + $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename()); |
|
77 | 77 | $info = $this->extractApiInfo($namespace, $module_name); |
78 | 78 | if (!empty($info)) { |
79 | 79 | $endpoints[$namespace] = $info; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | if (NULL !== $mInfo) { |
103 | 103 | $info[] = $mInfo; |
104 | 104 | } |
105 | - } catch (\Exception $e) { |
|
105 | + }catch (\Exception $e) { |
|
106 | 106 | Logger::getInstance()->errorLog($e->getMessage()); |
107 | 107 | } |
108 | 108 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
316 | 316 | $payload = $this->extractDtoProperties($namespace); |
317 | 317 | } |
318 | - } catch (\Exception $e) { |
|
318 | + }catch (\Exception $e) { |
|
319 | 319 | Logger::getInstance()->errorLog($e->getMessage()); |
320 | 320 | } |
321 | 321 | |
@@ -354,18 +354,18 @@ discard block |
||
354 | 354 | unset($methodInfo['return']['objects']); |
355 | 355 | if (in_array($methodInfo['method'], ['POST', 'PUT'])) { |
356 | 356 | $methodInfo['payload'] = $this->extractPayload($modelNamespace, $docComments); |
357 | - } elseif($method->getNumberOfParameters() > 0) { |
|
357 | + } elseif ($method->getNumberOfParameters() > 0) { |
|
358 | 358 | $methodInfo['parameters'] = []; |
359 | - foreach($method->getParameters() as $parameter) { |
|
359 | + foreach ($method->getParameters() as $parameter) { |
|
360 | 360 | $parameterName = $parameter->getName(); |
361 | 361 | $types = []; |
362 | 362 | preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types); |
363 | - if(count($types) > 1) { |
|
363 | + if (count($types) > 1) { |
|
364 | 364 | $methodInfo['parameters'][$parameterName] = $types[1][0]; |
365 | 365 | } |
366 | 366 | } |
367 | 367 | } |
368 | - } catch (\Exception $e) { |
|
368 | + }catch (\Exception $e) { |
|
369 | 369 | jpre($e->getMessage()); |
370 | 370 | Logger::getInstance()->errorLog($e->getMessage()); |
371 | 371 | } |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | private static function swaggerResponses() { |
462 | 462 | $codes = [200, 400, 404, 500]; |
463 | 463 | $responses = []; |
464 | - foreach($codes as $code) { |
|
465 | - switch($code) { |
|
464 | + foreach ($codes as $code) { |
|
465 | + switch ($code) { |
|
466 | 466 | default: |
467 | 467 | case 200: |
468 | 468 | $message = _('Successful response'); |
@@ -514,10 +514,10 @@ discard block |
||
514 | 514 | $formatted = [ |
515 | 515 | "swagger" => "2.0", |
516 | 516 | "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)), |
517 | - "basePath" => '/' . $module['name'] . '/api', |
|
517 | + "basePath" => '/'.$module['name'].'/api', |
|
518 | 518 | "schemes" => [Request::getInstance()->getServer('HTTPS') == 'on' ? "https" : "http"], |
519 | 519 | "info" => [ |
520 | - "title" => _('Documentación API módulo ') . $module['name'], |
|
520 | + "title" => _('Documentación API módulo ').$module['name'], |
|
521 | 521 | "version" => Config::getParam('api.version', '1.0'), |
522 | 522 | "contact" => [ |
523 | 523 | "name" => Config::getParam("author", "Fran López"), |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | $endpoints = DocumentorService::getInstance()->extractApiEndpoints($module); |
530 | 530 | foreach ($endpoints as $model) { |
531 | 531 | foreach ($model as $endpoint) { |
532 | - if(!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) { |
|
532 | + if (!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) { |
|
533 | 533 | $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']); |
534 | 534 | $description = $endpoint['description']; |
535 | 535 | $method = strtolower($endpoint['method']); |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | 'responses' => self::swaggerResponses(), |
541 | 541 | 'parameters' => [], |
542 | 542 | ]; |
543 | - if(array_key_exists('parameters', $endpoint)) { |
|
544 | - foreach($endpoint['parameters'] as $parameter => $type) { |
|
543 | + if (array_key_exists('parameters', $endpoint)) { |
|
544 | + foreach ($endpoint['parameters'] as $parameter => $type) { |
|
545 | 545 | list($type, $format) = self::translateSwaggerFormats($type); |
546 | 546 | $paths[$url][$method]['parameters'][] = [ |
547 | 547 | 'in' => 'path', |
@@ -553,19 +553,19 @@ discard block |
||
553 | 553 | } |
554 | 554 | |
555 | 555 | } |
556 | - foreach($endpoint['objects'] as $name => $object) { |
|
557 | - if(class_exists($name)) { |
|
556 | + foreach ($endpoint['objects'] as $name => $object) { |
|
557 | + if (class_exists($name)) { |
|
558 | 558 | $class = GeneratorHelper::extractClassFromNamespace($name); |
559 | 559 | $classDefinition = [ |
560 | 560 | 'type' => 'object', |
561 | - '$ref' => '#/definitions/' . $class, |
|
561 | + '$ref' => '#/definitions/'.$class, |
|
562 | 562 | ]; |
563 | 563 | $paths[$url][$method]['responses'][200]['schema']['properties']['data'] = $classDefinition; |
564 | 564 | $dtos += self::extractSwaggerDefinition($class, $object); |
565 | - if(!isset($paths[$url][$method]['tags']) || !in_array($class, $paths[$url][$method]['tags'])) { |
|
565 | + if (!isset($paths[$url][$method]['tags']) || !in_array($class, $paths[$url][$method]['tags'])) { |
|
566 | 566 | $paths[$url][$method]['tags'][] = $class; |
567 | 567 | } |
568 | - if(array_key_exists('payload', $endpoint)) { |
|
568 | + if (array_key_exists('payload', $endpoint)) { |
|
569 | 569 | $paths[$url][$method]['parameters'][] = [ |
570 | 570 | 'in' => 'body', |
571 | 571 | 'name' => $class, |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | protected function extractDtoName($dto, $isArray = false) |
594 | 594 | { |
595 | 595 | $dto = explode('\\', $dto); |
596 | - $modelDto = array_pop($dto) . "Dto"; |
|
596 | + $modelDto = array_pop($dto)."Dto"; |
|
597 | 597 | if ($isArray) { |
598 | 598 | $modelDto .= "List"; |
599 | 599 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | header("Access-Control-Allow-Credentials: true"); |
43 | 43 | header("Access-Control-Allow-Origin: *"); |
44 | 44 | header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS"); |
45 | - header("Access-Control-Allow-Headers: " . implode(', ', self::getCorsHeaders())); |
|
45 | + header("Access-Control-Allow-Headers: ".implode(', ', self::getCorsHeaders())); |
|
46 | 46 | } |
47 | 47 | if (Request::getInstance()->getMethod() == 'OPTIONS') { |
48 | 48 | Logger::log('Returning OPTIONS header confirmation for CORS pre flight requests'); |