-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoolifyServiceProvider.php
More file actions
163 lines (142 loc) · 4.4 KB
/
CoolifyServiceProvider.php
File metadata and controls
163 lines (142 loc) · 4.4 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace Stumason\Coolify;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Foundation\CachesRoutes;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
class CoolifyServiceProvider extends ServiceProvider
{
use EventMap;
use ServiceBindings;
/**
* Bootstrap any application services.
*/
public function boot(): void
{
$this->registerEvents();
$this->registerRoutes();
$this->registerResources();
$this->registerCommands();
$this->offerPublishing();
}
/**
* Register the Coolify events and listeners.
*/
protected function registerEvents(): void
{
$dispatcher = $this->app->make(Dispatcher::class);
foreach ($this->events as $event => $listeners) {
foreach ($listeners as $listener) {
$dispatcher->listen($event, $listener);
}
}
foreach ($this->subscribers as $subscriber) {
$dispatcher->subscribe($subscriber);
}
}
/**
* Register any application services.
*/
public function register(): void
{
if (! defined('COOLIFY_PATH')) {
define('COOLIFY_PATH', realpath(__DIR__.'/../'));
}
$this->configure();
$this->registerServices();
}
/**
* Setup the configuration for Coolify.
*/
protected function configure(): void
{
$this->mergeConfigFrom(
__DIR__.'/../config/coolify.php',
'coolify'
);
}
/**
* Register the Coolify routes.
*/
protected function registerRoutes(): void
{
if ($this->app instanceof CachesRoutes && $this->app->routesAreCached()) {
return;
}
Route::group([
'domain' => config('coolify.domain'),
'prefix' => config('coolify.path'),
'namespace' => 'Stumason\Coolify\Http\Controllers',
'middleware' => config('coolify.middleware', 'web'),
], function () {
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
});
Coolify::$registeredRoutes = true;
}
/**
* Register the Coolify resources.
*/
protected function registerResources(): void
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'coolify');
}
/**
* Register the Coolify Artisan commands.
*/
protected function registerCommands(): void
{
if ($this->app->runningInConsole()) {
$this->commands([
Console\DeployCommand::class,
Console\DestroyCommand::class,
Console\InstallCommand::class,
Console\LogsCommand::class,
Console\ProvisionCommand::class,
Console\RestartCommand::class,
Console\RollbackCommand::class,
Console\SetupCiCommand::class,
Console\StatusCommand::class,
]);
}
}
/**
* Register Coolify's services in the container.
*/
protected function registerServices(): void
{
// Register the HTTP client
$this->app->singleton(CoolifyClient::class, function ($app) {
return new CoolifyClient(
config('coolify.url'),
config('coolify.token'),
config('coolify.team_id')
);
});
// Register repository bindings
foreach ($this->serviceBindings as $key => $value) {
is_numeric($key)
? $this->app->singleton($value)
: $this->app->singleton($key, $value);
}
}
/**
* Setup the resource publishing groups for Coolify.
*/
protected function offerPublishing(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../stubs/CoolifyServiceProvider.stub' => app_path('Providers/CoolifyServiceProvider.php'),
], 'coolify-provider');
$this->publishes([
__DIR__.'/../config/coolify.php' => config_path('coolify.php'),
], 'coolify-config');
$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/coolify'),
], 'coolify-views');
$this->publishes([
__DIR__.'/../dist' => public_path('vendor/coolify'),
], 'coolify-assets');
}
}
}