CentrifugeServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 18 2
1
<?php
2
3
namespace LaraComponents\Centrifuge;
4
5
use Predis\Client as RedisClient;
6
use GuzzleHttp\Client as HttpClient;
7
use Illuminate\Support\ServiceProvider;
8
use Illuminate\Broadcasting\BroadcastManager;
9
10
class CentrifugeServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Add centrifuge broadcaster.
14
     *
15
     * @param \Illuminate\Broadcasting\BroadcastManager $broadcastManager
16
     */
17
    public function boot(BroadcastManager $broadcastManager)
18
    {
19
        $broadcastManager->extend('centrifuge', function ($app) {
20
            return new CentrifugeBroadcaster($app->make('centrifuge'));
21
        });
22
    }
23
24
    /**
25
     * Register the service provider.
26
     *
27
     * @return void
28
     */
29
    public function register()
30
    {
31
        $this->app->singleton('centrifuge', function ($app) {
32
            $config = $app->make('config')->get('broadcasting.connections.centrifuge');
33
            $http = new HttpClient();
34
            $redis = $app->make('redis')->connection($config['redis_connection']);
35
36
            // for laravel 5.4
37
            if (! ($redis instanceof RedisClient)) {
38
                $redis = $redis->client();
39
            }
40
41
            return new Centrifuge($config, $http, $redis);
42
        });
43
44
        $this->app->alias('centrifuge', 'LaraComponents\Centrifuge\Centrifuge');
45
        $this->app->alias('centrifuge', 'LaraComponents\Centrifuge\Contracts\Centrifuge');
46
    }
47
}
48