ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 18
rs 9.9332
1
<?php
2
3
4
namespace SirSova\Webhooks;
5
6
use GuzzleHttp\Client;
7
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
8
use Illuminate\Contracts\Container\Container;
9
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
10
use Illuminate\Database\Connection;
11
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
12
use SirSova\Webhooks\Contracts\Channel;
13
use SirSova\Webhooks\Contracts\MessageProcessor as MessageProcessorContract;
14
use SirSova\Webhooks\Contracts\SubscriberRepository;
15
use SirSova\Webhooks\Repositories\DatabaseSubscriberRepository;
16
17
class ServiceProvider extends BaseServiceProvider
18
{
19
    public function register(): void
20
    {
21
        $this->app->bind(SubscriberRepository::class, function (Container $container) {
22
            return new DatabaseSubscriberRepository(
23
                $container->get(Connection::class),
24
                $container->get(ValidationFactory::class),
25
                config('webhooks.subscribers_table', 'webhook_subscribers')
26
            );
27
        });
28
        
29
        $this->app->bind(Channel::class, function () {
30
            return new WebhookChannel(new Client());
31
        });
32
        
33
        $this->app->bind(MessageProcessorContract::class, function (Container $container) {
34
            return new MessageProcessor(
35
                $container->get(SubscriberRepository::class),
36
                $container->get(BusDispatcher::class),
37
                config('webhooks.webhook-queue')
38
            );
39
        });
40
    }
41
    
42
    public function boot(): void
43
    {
44
        if ($this->app->runningInConsole()) {
45
            //config
46
            $this->publishes([
47
                __DIR__ . '/../config/webhooks.php' => config_path('webhooks.php'),
48
            ], 'webhooks-config');
49
            
50
            //migrations
51
            $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
52
            
53
            $this->publishes([
54
                __DIR__ . '/../database/migrations' => database_path('migrations'),
55
            ], 'webhooks-migrations');
56
            
57
            //console commands
58
            $this->commands([
59
                Console\CreateSubscriber::class
60
            ]);
61
        }
62
    }
63
}
64