CentrifugoServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 9
c 2
b 1
f 0
dl 0
loc 30
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Opekunov\Centrifugo;
6
7
use GuzzleHttp\Client as HttpClient;
8
use Illuminate\Broadcasting\BroadcastManager;
9
use Illuminate\Support\ServiceProvider;
10
use Opekunov\Centrifugo\Contracts\CentrifugoInterface;
11
12
class CentrifugoServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Add centrifugo broadcaster.
16
     *
17
     * @param \Illuminate\Broadcasting\BroadcastManager $broadcastManager
18
     */
19
    public function boot(BroadcastManager $broadcastManager)
20
    {
21
        $broadcastManager->extend('centrifugo', function ($app) {
22
            return new CentrifugoBroadcaster($app->make('centrifugo'));
23
        });
24
    }
25
26
    /**
27
     * Register the service provider.
28
     *
29
     * @return void
30
     */
31
    public function register()
32
    {
33
        $this->app->singleton('centrifugo', function ($app) {
34
            $config = $app->make('config')->get('broadcasting.connections.centrifugo');
35
            $http = new HttpClient();
36
37
            return new Centrifugo($config, $http);
38
        });
39
40
        $this->app->alias('centrifugo', Centrifugo::class);
41
        $this->app->alias('centrifugo', CentrifugoInterface::class);
42
    }
43
}
44