1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\ServerMonitor; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Spatie\Blink\Blink; |
8
|
|
|
use Spatie\ServerMonitor\Commands\AddHost; |
9
|
|
|
use Spatie\ServerMonitor\Commands\DeleteHost; |
10
|
|
|
use Spatie\ServerMonitor\Commands\DumpChecks; |
11
|
|
|
use Spatie\ServerMonitor\Commands\ListChecks; |
12
|
|
|
use Spatie\ServerMonitor\Commands\ListHosts; |
13
|
|
|
use Spatie\ServerMonitor\Commands\RunChecks; |
14
|
|
|
use Spatie\ServerMonitor\Commands\SyncFile; |
15
|
|
|
use Spatie\ServerMonitor\Manipulators\Manipulator; |
16
|
|
|
use Spatie\ServerMonitor\Notifications\EventHandler; |
17
|
|
|
|
18
|
|
|
class ServerMonitorServiceProvider extends ServiceProvider |
19
|
|
|
{ |
20
|
|
|
public function boot() |
21
|
|
|
{ |
22
|
|
|
if ($this->app->runningInConsole()) { |
23
|
|
|
$this->publishes([ |
24
|
|
|
__DIR__.'/../config/server-monitor.php' => config_path('server-monitor.php'), |
25
|
|
|
], 'config'); |
26
|
|
|
|
27
|
|
|
$this->publishesMigration('CreateHostsTable', 'create_hosts_table', 1); |
28
|
|
|
$this->publishesMigration('CreateChecksTable', 'create_checks_table', 2); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function register() |
33
|
|
|
{ |
34
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/server-monitor.php', 'server-monitor'); |
35
|
|
|
|
36
|
|
|
$this->app->bind(Manipulator::class, config('server-monitor.process_manipulator')); |
37
|
|
|
|
38
|
|
|
$this->app['events']->subscribe(EventHandler::class); |
39
|
|
|
|
40
|
|
|
$this->app->bind('command.server-monitor:run-checks', RunChecks::class); |
41
|
|
|
$this->app->bind('command.server-monitor:add-host', AddHost::class); |
42
|
|
|
$this->app->bind('command.server-monitor:delete-host', DeleteHost::class); |
43
|
|
|
$this->app->bind('command.server-monitor:sync-file', SyncFile::class); |
44
|
|
|
$this->app->bind('command.server-monitor:list', ListHosts::class); |
45
|
|
|
$this->app->bind('command.server-monitor:list-checks', ListChecks::class); |
46
|
|
|
$this->app->bind('command.server-monitor:dump-checks', DumpChecks::class); |
47
|
|
|
$this->app->singleton('blink', Blink::class); |
48
|
|
|
|
49
|
|
|
$this->commands([ |
50
|
|
|
'command.server-monitor:run-checks', |
51
|
|
|
'command.server-monitor:add-host', |
52
|
|
|
'command.server-monitor:delete-host', |
53
|
|
|
'command.server-monitor:sync-file', |
54
|
|
|
'command.server-monitor:list', |
55
|
|
|
'command.server-monitor:list-checks', |
56
|
|
|
'command.server-monitor:dump-checks', |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function publishesMigration(string $className, string $fileName, int $timestampSuffix) |
61
|
|
|
{ |
62
|
|
|
if (! class_exists($className)) { |
63
|
|
|
$timestamp = (new DateTime())->format('Y_m_d_His').$timestampSuffix; |
64
|
|
|
|
65
|
|
|
$this->publishes([ |
66
|
|
|
__DIR__."/../database/migrations/{$fileName}.php.stub" => database_path('migrations/'.$timestamp."_{$fileName}.php"), |
67
|
|
|
], 'migrations'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|