Completed
Push — master ( 70df6c...4c9ad9 )
by Jasper
11:34
created

EncryptedDataServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Swis\Laravel\Encrypted;
4
5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Storage;
8
use Illuminate\Support\ServiceProvider;
9
use League\Flysystem\Adapter\Local as LocalAdapter;
10
use League\Flysystem\Filesystem;
11
use Swis\Flysystem\Encrypted\EncryptedAdapter;
12
13
class EncryptedDataServiceProvider extends ServiceProvider
14
{
15
    public function register(): void
16
    {
17
        $this->registerEncrypter();
18
    }
19
20 87
    protected function registerEncrypter(): void
21
    {
22 87
        $this->app->alias('encrypter', 'encrypted-data.encrypter');
23 87
    }
24 87
25
    public function boot(): void
26 87
    {
27
        $this->setupStorageDriver();
28 87
    }
29 87
30 58
    protected function setupStorageDriver(): void
31 3
    {
32
        Storage::extend(
33 3
            'local-encrypted',
34
            function (Application $app, array $config) {
35 3
                $permissions = $config['permissions'] ?? [];
36
37 3
                $links = ($config['links'] ?? null) === 'skip'
38 3
                    ? LocalAdapter::SKIP_LINKS
39 3
                    : LocalAdapter::DISALLOW_LINKS;
40 3
41 3
                return new Filesystem(
42 1
                    new EncryptedAdapter(
43 1
                        new LocalAdapter(
44
                            $config['root'],
45 3
                            $config['lock'] ?? LOCK_EX,
46
                            $links,
47 3
                            $permissions
48
                        ),
49 87
                        $app->make('encrypted-data.encrypter')
50
                    ),
51 87
                    Arr::only($config, ['visibility', 'disable_asserts', 'url'])
52
                );
53 87
            }
54
        );
55 87
    }
56
}
57