-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouteServiceProvider.php
48 lines (42 loc) · 1.58 KB
/
RouteServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace MorningMedley\Route;
use Illuminate\Filesystem\Filesystem;
use MorningMedley\Facades\Rest as RestFacade;
use MorningMedley\Route\Classes\Rest\CallbackHandler;
use MorningMedley\Route\Classes\Rest\Router as RestRouter;
use MorningMedley\Route\Classes\Rewrite\Router as RewriteRouter;
use MorningMedley\Facades\Route as RouteFacade;
use Symfony\Component\Finder\SplFileInfo;
class RouteServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
$this->mergeConfigFrom(__DIR__ . "/config/config.php", 'route');
RouteFacade::setFacadeApplication($this->app);
$this->app->singleton('rewrite-router', RewriteRouter::class);
}
public function boot()
{
if (! $this->app->configurationIsCached()) {
$files = [];
foreach ($this->app['config']->get('route.paths') as $path) {
if (! is_dir($path)) {
$path = $this->app->basePath($path);
if (! is_dir($path)) {
continue;
}
}
$filesystem = $this->app->make(Filesystem::class);
/** @var Filesystem $filesystem */
$files = [
...$files,
...array_map(fn(SplFileInfo $file) => $file->getRealPath(), $filesystem->allFiles($path)),
];
}
$this->app['config']->set('route.files', $files);
}
foreach ($this->app['config']->get('route.files') as $file) {
require_once $file;
}
}
}