|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Laravel Paket. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Anton Komarev <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Cog\Laravel\Paket; |
|
15
|
|
|
|
|
16
|
|
|
use Cog\Contracts\Paket\Job\Repositories\Job as JobRepositoryContract; |
|
17
|
|
|
use Cog\Laravel\Paket\Console\Commands\Setup; |
|
18
|
|
|
use Cog\Laravel\Paket\Job\Events\JobHasBeenCreated; |
|
19
|
|
|
use Cog\Laravel\Paket\Job\Listeners\JobListener; |
|
20
|
|
|
use Cog\Laravel\Paket\Job\Repositories\JobFileRepository; |
|
21
|
|
|
use Cog\Laravel\Paket\Support\Composer; |
|
22
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
23
|
|
|
use Illuminate\Support\Facades\Event; |
|
24
|
|
|
use Illuminate\Support\Facades\Route; |
|
25
|
|
|
use Illuminate\Support\ServiceProvider; |
|
26
|
|
|
|
|
27
|
|
|
final class PaketServiceProvider extends ServiceProvider |
|
28
|
|
|
{ |
|
29
|
|
|
public function register(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->configure(); |
|
32
|
|
|
$this->registerConsoleCommands(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function boot(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->registerPublishes(); |
|
38
|
|
|
$this->registerResources(); |
|
39
|
|
|
$this->registerRoutes(); |
|
40
|
|
|
$this->registerBindings(); |
|
41
|
|
|
$this->registerListeners(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function getRouteConfiguration(): array |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
'namespace' => 'Cog\Laravel\Paket\Http\Controllers', |
|
48
|
|
|
'prefix' => config('paket.uri'), |
|
49
|
|
|
'middleware' => 'web', |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Merge Paket configuration with the application configuration. |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
private function configure(): void |
|
59
|
|
|
{ |
|
60
|
|
|
if (!$this->app->configurationIsCached()) { |
|
61
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/paket.php', 'paket'); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function registerResources(): void |
|
66
|
|
|
{ |
|
67
|
|
|
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'paket'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function registerPublishes(): void |
|
71
|
|
|
{ |
|
72
|
|
|
if ($this->app->runningInConsole()) { |
|
73
|
|
|
$this->publishes([ |
|
74
|
|
|
__DIR__ . '/../public' => public_path('vendor/paket'), |
|
75
|
|
|
], 'paket-assets'); |
|
76
|
|
|
|
|
77
|
|
|
$this->publishes([ |
|
78
|
|
|
__DIR__ . '/../config/paket.php' => config_path('paket.php'), |
|
79
|
|
|
], 'paket-config'); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private function registerRoutes(): void |
|
84
|
|
|
{ |
|
85
|
|
|
Route::group($this->getRouteConfiguration(), function () { |
|
86
|
|
|
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); |
|
87
|
|
|
}); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
private function registerConsoleCommands(): void |
|
91
|
|
|
{ |
|
92
|
|
|
$this->commands([ |
|
93
|
|
|
Setup::class, |
|
94
|
|
|
]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
private function registerBindings(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$this->app->singleton(Composer::class, function () { |
|
100
|
|
|
return new Composer( |
|
101
|
|
|
$this->app->make(Filesystem::class), |
|
102
|
|
|
base_path(), |
|
103
|
|
|
storage_path('paket/jobs') |
|
104
|
|
|
); |
|
105
|
|
|
}); |
|
106
|
|
|
|
|
107
|
|
|
$this->app->singleton(JobRepositoryContract::class, function () { |
|
108
|
|
|
return new JobFileRepository( |
|
109
|
|
|
$this->app->make(Filesystem::class), |
|
110
|
|
|
storage_path('paket') |
|
111
|
|
|
); |
|
112
|
|
|
}); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
private function registerListeners(): void |
|
116
|
|
|
{ |
|
117
|
|
|
Event::listen(JobHasBeenCreated::class, JobListener::class); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|