1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Recca0120\Terminal; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Routing\Router; |
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
|
1 |
|
$this->handleRoutes($router, $config); |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
if ($this->app->runningInConsole() === true) { |
34
|
1 |
|
$this->handlePublishes(); |
35
|
|
|
} |
36
|
1 |
|
} |
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
|
1 |
|
$this->app->singleton(Application::class, function ($app) { |
46
|
1 |
|
$config = $app['config']['terminal']; |
47
|
1 |
|
$artisan = new Application($app, $app['events'], $app->version()); |
48
|
1 |
|
$artisan->resolveCommands($config['commands']); |
49
|
|
|
|
50
|
1 |
|
return $artisan; |
51
|
1 |
|
}); |
52
|
|
|
|
53
|
1 |
|
$this->app->singleton(Kernel::class, function ($app) { |
54
|
1 |
|
$config = $app['config']['terminal']; |
55
|
|
|
|
56
|
1 |
|
return new Kernel($app[Application::class], array_merge($config, [ |
57
|
1 |
|
'basePath' => $app->basePath(), |
58
|
1 |
|
'environment' => $app->environment(), |
59
|
1 |
|
'version' => $app->version(), |
60
|
1 |
|
'endpoint' => $app['url']->route(Arr::get($config, 'route.as').'endpoint'), |
61
|
|
|
])); |
62
|
1 |
|
}); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* register routes. |
67
|
|
|
* |
68
|
|
|
* @param \Illuminate\Routing\Router $router |
69
|
|
|
* @param array $config |
70
|
|
|
*/ |
71
|
1 |
|
protected function handleRoutes(Router $router, $config = []) |
72
|
|
|
{ |
73
|
1 |
|
if ($this->app->routesAreCached() === false) { |
74
|
1 |
|
$router->group(array_merge([ |
75
|
1 |
|
'namespace' => $this->namespace, |
76
|
1 |
|
], Arr::get($config, 'route', [])), function (Router $router) { |
77
|
|
|
require __DIR__.'/../routes/web.php'; |
78
|
1 |
|
}); |
79
|
|
|
} |
80
|
1 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* handle publishes. |
84
|
|
|
*/ |
85
|
1 |
|
protected function handlePublishes() |
86
|
|
|
{ |
87
|
1 |
|
$this->publishes([ |
88
|
1 |
|
__DIR__.'/../config/terminal.php' => config_path('terminal.php'), |
89
|
1 |
|
], 'config'); |
90
|
|
|
|
91
|
1 |
|
$this->publishes([ |
92
|
1 |
|
__DIR__.'/../resources/views' => base_path('resources/views/vendor/terminal'), |
93
|
1 |
|
], 'views'); |
94
|
|
|
|
95
|
1 |
|
$this->publishes([ |
96
|
1 |
|
__DIR__.'/../public' => public_path('vendor/terminal'), |
97
|
1 |
|
], 'public'); |
98
|
1 |
|
} |
99
|
|
|
} |
100
|
|
|
|