koel/app/Providers/RouteServiceProvider.php

33 lines
900 B
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
2016-09-26 06:30:00 +00:00
use Illuminate\Support\Facades\Route;
2022-06-10 10:47:46 +00:00
use Webmozart\Assert\Assert;
2015-12-13 04:42:28 +00:00
class RouteServiceProvider extends ServiceProvider
{
protected $namespace = 'App\Http\Controllers';
2020-12-22 20:11:22 +00:00
public function map(): void
2016-09-26 06:30:00 +00:00
{
2022-06-10 10:47:46 +00:00
self::loadVersionAwareRoutes('web');
self::loadVersionAwareRoutes('api');
2016-09-26 06:30:00 +00:00
}
2016-09-26 07:33:53 +00:00
2022-06-10 10:47:46 +00:00
private static function loadVersionAwareRoutes(string $type): void
2016-09-26 06:30:00 +00:00
{
2022-06-10 10:47:46 +00:00
Assert::oneOf($type, ['web', 'api']);
2016-09-26 07:33:53 +00:00
2022-06-10 10:47:46 +00:00
Route::group([], base_path(sprintf('routes/%s.base.php', $type)));
$apiVersion = request()->header('X-Api-Version');
$routeFile = $apiVersion ? base_path(sprintf('routes/%s.%s.php', $type, $apiVersion)) : null;
if ($routeFile && file_exists($routeFile)) {
Route::group([], $routeFile);
}
2015-12-13 04:42:28 +00:00
}
}