Skip to content

Commit

Permalink
Added extra routes feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
gentritabazi committed Oct 26, 2020
1 parent 6741f99 commit 08a3fde
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Config/larapi-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,18 @@
'auth:api'
],

'extra_routes' => [
'routes_v1' => [
'middleware' => [],
'namespace' => 'Controllers\V1',
'prefix' => 'v1'
],
'routes_v2' => [
'middleware' => [],
'namespace' => 'Controllers\V2',
'prefix' => 'v2'
]
],

'slack_formatter' => '\Infrastructure\Formatters\SlackFormatter'
];
23 changes: 23 additions & 0 deletions src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function boot()
public function map(Router $router)
{
$middleware = config('larapi-components.protection_middleware');
$extraRoutes = config('larapi-components.extra_routes');

$highLevelParts = array_map(function ($namespace) {
return glob(sprintf('%s%s*', $namespace, DIRECTORY_SEPARATOR), GLOB_ONLYDIR);
Expand Down Expand Up @@ -65,6 +66,28 @@ public function map(Router $router)
require $path;
});
}

foreach ($extraRoutes as $routeName => $route) {
$path = sprintf('%s/%s.php', $componentRoot, $routeName);

if (!file_exists($path)) {
continue;
}

$namespace = sprintf(
'%s\\%s\\'. $route['namespace'],
$part,
$component
);

$router->group([
'middleware' => $route['middleware'],
'namespace' => $namespace,
'prefix' => $route['prefix']
], function ($router) use ($path) {
require $path;
});
}
}
}
}
Expand Down

0 comments on commit 08a3fde

Please sign in to comment.