-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHubIssuesServiceProvider.php
More file actions
69 lines (58 loc) · 2.19 KB
/
Copy pathGitHubIssuesServiceProvider.php
File metadata and controls
69 lines (58 loc) · 2.19 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
<?php
namespace Codexpedite\LaravelGithubIssues;
use Illuminate\Support\ServiceProvider;
use Codexpedite\LaravelGithubIssues\Commands\MonitorLogsCommand;
use Codexpedite\LaravelGithubIssues\Services\LogMonitorService;
use Codexpedite\LaravelGithubIssues\Services\GitHubClient;
use Codexpedite\LaravelGithubIssues\Services\ErrorProcessor;
class GitHubIssuesServiceProvider extends ServiceProvider
{
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/config/github-issues.php', 'github-issues'
);
}
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/config/github-issues.php' => config_path('github-issues.php'),
], 'config');
$this->commands([
MonitorLogsCommand::class,
]);
}
if (config('github-issues.enabled') && $this->isConfigured()) {
$this->app->booted(function () {
$this->registerServices();
$this->app[LogMonitorService::class]->start();
});
}
}
private function registerServices(): void
{
$this->app->singleton(GitHubClient::class, function ($app) {
$token = $app['config']['github-issues.github.token'] ?? '';
$owner = $app['config']['github-issues.github.owner'] ?? '';
$repository = $app['config']['github-issues.github.repository'] ?? '';
return new GitHubClient($token, $owner, $repository);
});
$this->app->singleton(ErrorProcessor::class, function ($app) {
return new ErrorProcessor($app['config']['github-issues']);
});
$this->app->singleton(LogMonitorService::class, function ($app) {
return new LogMonitorService(
$app[GitHubClient::class],
$app[ErrorProcessor::class],
$app['config']['github-issues']
);
});
}
private function isConfigured(): bool
{
return config('github-issues.github.token') &&
config('github-issues.github.owner') &&
config('github-issues.github.repository');
}
}