Skip to content

Commit

Permalink
refactor: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Jun 15, 2023
1 parent 2742be0 commit ec69be1
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions Loaders/RoutesLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ trait RoutesLoaderTrait
*/
public function runRoutesAutoLoader(): void
{
$containersPaths = Apiato::getAllContainerPaths();
$allContainerPaths = Apiato::getAllContainerPaths();

foreach ($containersPaths as $containerPath) {
foreach ($allContainerPaths as $containerPath) {
$this->loadApiContainerRoutes($containerPath);
$this->loadWebContainerRoutes($containerPath);
}
Expand All @@ -33,7 +33,7 @@ public function runRoutesAutoLoader(): void
*/
private function loadApiContainerRoutes(string $containerPath): void
{
$apiRoutesPath = $this->getRoutesPathForUI($containerPath, 'API');
$apiRoutesPath = $this->getRoutePathsForUI($containerPath, 'API');

if (File::isDirectory($apiRoutesPath)) {
$files = $this->getFilesSortedByName($apiRoutesPath);
Expand All @@ -43,7 +43,7 @@ private function loadApiContainerRoutes(string $containerPath): void
}
}

private function getRoutesPathForUI(string $containerPath, string $ui): string
private function getRoutePathsForUI(string $containerPath, string $ui): string
{
return $this->getUIPathForContainer($containerPath, $ui) . DIRECTORY_SEPARATOR . 'Routes';
}
Expand Down Expand Up @@ -80,7 +80,8 @@ public function getApiRouteGroup(SplFileInfo|string $endpointFileOrPrefixString)
return [
'middleware' => $this->getMiddlewares(),
'domain' => $this->getApiUrl(),
// If $endpointFileOrPrefixString is a file then get the version name from the file name, else if string use that string as prefix
// If $endpointFileOrPrefixString is a string, use that string as prefix
// else, if it is a file then get the version name from the file name, and use it as prefix
'prefix' => is_string($endpointFileOrPrefixString) ? $endpointFileOrPrefixString : $this->getApiVersionPrefix($endpointFileOrPrefixString),
];
}
Expand Down Expand Up @@ -126,14 +127,8 @@ private function getRouteFileVersionFromFileName(SplFileInfo $file): string|bool

end($fileNameWithoutExtensionExploded);

$apiVersion = prev($fileNameWithoutExtensionExploded); // get the array before the last one

// Skip versioning the API's root route
if ($apiVersion === 'ApisRoot') {
$apiVersion = '';
}

return $apiVersion;
// get the array before the last one
return prev($fileNameWithoutExtensionExploded);
}

private function getRouteFileNameWithoutExtension(SplFileInfo $file): string
Expand All @@ -148,7 +143,7 @@ private function getRouteFileNameWithoutExtension(SplFileInfo $file): string
*/
private function loadWebContainerRoutes($containerPath): void
{
$webRoutesPath = $this->getRoutesPathForUI($containerPath, 'WEB');
$webRoutesPath = $this->getRoutePathsForUI($containerPath, 'WEB');

if (File::isDirectory($webRoutesPath)) {
$files = $this->getFilesSortedByName($webRoutesPath);
Expand Down

0 comments on commit ec69be1

Please sign in to comment.