Completed
Push — master ( ffbaba...99b42b )
by Elf
03:27
created

AgentServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ElfSundae\Laravel\Agent;
4
5
use Jenssegers\Agent\Agent;
6
use Illuminate\Support\ServiceProvider;
7
8
class AgentServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the service provider.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        $this->app['view']->share('client', $this->app->make('client'));
18
    }
19
20
    /**
21
     * Register the service provider.
22
     *
23
     * @return void
24
     */
25
    public function register()
26
    {
27
        $this->registerAgent();
28
29
        $this->registerClient();
30
    }
31
32
    /**
33
     * Register the Agent.
34
     *
35
     * @return void
36
     */
37
    protected function registerAgent()
38
    {
39
        $this->app->register(\Jenssegers\Agent\AgentServiceProvider::class);
40
41
        if (! $this->app->bound('agent')) {
42
            $this->app->alias('agent', Agent::class);
43
        }
44
    }
45
46
    /**
47
     * Register the Client.
48
     *
49
     * @return void
50
     */
51
    protected function registerClient()
52
    {
53
        $this->app->singleton('client', function ($app) {
54
            return (new Client)->setAgent($app->make('agent'));
55
        });
56
57
        $this->app->alias('client', Client::class);
58
    }
59
}
60