SelectelServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace ArgentCrusade\Flysystem\Selectel;
4
5
use League\Flysystem\Filesystem;
6
use Illuminate\Support\Facades\Storage;
7
use Illuminate\Support\ServiceProvider;
8
use ArgentCrusade\Selectel\CloudStorage\CloudStorage;
9
use ArgentCrusade\Selectel\CloudStorage\Api\ApiClient;
10
11
class SelectelServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16
    public function boot()
17
    {
18
        Storage::extend('selectel', function ($app, $config) {
19
            $api = new ApiClient($config['username'], $config['password']);
20
            $api->authenticate();
21
22
            $storage = new CloudStorage($api);
23
            $container = $storage->getContainer($config['container']);
24
25
            if (isset($config['container_url'])) {
26
                $container->setUrl($config['container_url']);
27
            }
28
29
            return new Filesystem(new SelectelAdapter($container));
30
        });
31
    }
32
33
    /**
34
     * Register the application services.
35
     */
36
    public function register()
37
    {
38
        //
39
    }
40
}
41