Completed
Push — master ( d6d8a1...fab734 )
by Elf
04:41
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
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ElfSundae\Laravel\Support\Services\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['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
        if (! $this->app->bound('agent')) {
40
            $this->app->singleton('agent', function () {
41
                return new Agent;
42
            });
43
44
            $this->app->alias('agent', Agent::class);
45
        }
46
    }
47
48
    /**
49
     * Register the Client.
50
     *
51
     * @return void
52
     */
53
    protected function registerClient()
54
    {
55
        $this->app->singleton('client', function ($app) {
56
            return (new Client)->setAgent($app->make('agent'));
57
        });
58
59
        $this->app->alias('client', Client::class);
60
    }
61
}
62