|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\Terminal; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Routing\Router; |
|
7
|
|
|
use Illuminate\Support\Arr; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider; |
|
9
|
|
|
|
|
10
|
|
|
class TerminalServiceProvider extends ServiceProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* namespace. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $namespace = 'Recca0120\Terminal\Http\Controllers'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Bootstrap any application services. |
|
21
|
|
|
* |
|
22
|
|
|
* @param \Illuminate\Http\Request $request |
|
23
|
|
|
* @param \Illuminate\Routing\Router $router |
|
24
|
|
|
*/ |
|
25
|
1 |
|
public function boot(Request $request, Router $router) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$config = $this->app['config']['terminal']; |
|
28
|
1 |
|
if (in_array($request->getClientIp(), Arr::get($config, 'whitelists', [])) === true || Arr::get($config, 'enabled') === true) { |
|
29
|
1 |
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'terminal'); |
|
30
|
|
|
$this->handleRoutes($router, $config); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($this->app->runningInConsole() === true) { |
|
34
|
|
|
$this->handlePublishes(); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Register any application services. |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function register() |
|
42
|
|
|
{ |
|
43
|
1 |
|
$this->mergeConfigFrom(__DIR__.'/../config/terminal.php', 'terminal'); |
|
44
|
|
|
|
|
45
|
|
|
$this->app->singleton(Application::class, function ($app) { |
|
46
|
|
|
$config = $app['config']['terminal']; |
|
47
|
|
|
$artisan = new Application($app, $app['events'], $app->version()); |
|
48
|
|
|
|
|
49
|
|
|
return $artisan->resolveCommands($config['commands']); |
|
50
|
1 |
|
}); |
|
51
|
|
|
|
|
52
|
|
|
$this->app->singleton(Kernel::class, function ($app) { |
|
53
|
|
|
$config = $app['config']['terminal']; |
|
54
|
|
|
|
|
55
|
|
|
return new Kernel($app[Application::class], array_merge($config, [ |
|
56
|
|
|
'basePath' => $app->basePath(), |
|
57
|
|
|
'environment' => $app->environment(), |
|
58
|
|
|
'version' => $app->version(), |
|
59
|
|
|
'endpoint' => $app['url']->route(Arr::get($config, 'route.as').'endpoint'), |
|
60
|
|
|
])); |
|
61
|
1 |
|
}); |
|
62
|
1 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* register routes. |
|
66
|
|
|
* |
|
67
|
|
|
* @param \Illuminate\Routing\Router $router |
|
68
|
|
|
* @param array $config |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function handleRoutes(Router $router, $config = []) |
|
71
|
|
|
{ |
|
72
|
|
|
if ($this->app->routesAreCached() === false) { |
|
73
|
|
|
$router->group(array_merge([ |
|
74
|
|
|
'namespace' => $this->namespace, |
|
75
|
|
|
], Arr::get($config, 'route', [])), function () { |
|
76
|
|
|
require __DIR__.'/../routes/web.php'; |
|
77
|
|
|
}); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* handle publishes. |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function handlePublishes() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->publishes([ |
|
87
|
|
|
__DIR__.'/../config/terminal.php' => config_path('terminal.php'), |
|
88
|
|
|
], 'config'); |
|
89
|
|
|
|
|
90
|
|
|
$this->publishes([ |
|
91
|
|
|
__DIR__.'/../resources/views' => base_path('resources/views/vendor/terminal'), |
|
92
|
|
|
], 'views'); |
|
93
|
|
|
|
|
94
|
|
|
$this->publishes([ |
|
95
|
|
|
__DIR__.'/../public' => public_path('vendor/terminal'), |
|
96
|
|
|
], 'public'); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|