AsanaServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Helix\Asana\Api\Laravel;
4
5
use Helix\Asana\Api;
6
use Helix\Asana\Api\Laravel\Command\AsanaCall;
7
use Helix\Asana\Api\Laravel\Command\AsanaGet;
8
use Helix\Asana\Api\Laravel\Command\AsanaTest;
9
use Helix\Asana\Api\SimpleCachePool;
10
use Illuminate\Contracts\Foundation\Application;
11
use Illuminate\Contracts\Support\DeferrableProvider;
12
use Illuminate\Support\Facades\Cache;
13
use Illuminate\Support\Facades\Log;
14
use Illuminate\Support\ServiceProvider;
15
16
class AsanaServiceProvider extends ServiceProvider implements DeferrableProvider {
17
18
    const NAME = 'asana';
19
20
    public function boot () {
21
        $this->publishes([
22
            __DIR__ . '/config/asana.php' => $this->app->configPath('asana.php')
23
        ]);
24
        if ($this->app->runningInConsole()) {
25
            $this->commands([
26
                AsanaTest::class,
27
                AsanaGet::class,
28
                AsanaCall::class,
29
            ]);
30
        }
31
    }
32
33
    public function provides () {
34
        return [self::NAME];
35
    }
36
37
    public function register () {
38
        $this->app->singleton(self::NAME, function(Application $app) {
39
            $config = $app['config'][self::NAME];
40
            $pool = null;
41
            if ($config['cache']) {
42
                $pool = new SimpleCachePool(Cache::store());
43
                $pool->setTtl($config['cache_ttl']);
44
            }
45
            $api = new Api($config['token'], $pool);
46
            $api->setLog(Log::getFacadeRoot());
47
            return $api;
48
        });
49
    }
50
}