FlysystemServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A registerDrivers() 0 10 2
1
<?php
2
/**
3
 * @link https://github.com/phpviet/laravel-flysystem
4
 * @copyright (c) PHP Viet
5
 * @license [MIT](http://www.opensource.org/licenses/MIT)
6
 */
7
8
namespace PHPViet\Laravel\Flysystem;
9
10
use Closure;
11
use Illuminate\Support\ServiceProvider;
12
use Illuminate\Filesystem\FilesystemManager;
13
use PHPViet\Laravel\Flysystem\Drivers\Viettel\Driver as ViettelDriver;
14
15
/**
16
 * @author Vuong Minh <[email protected]>
17
 * @since 1.0.0
18
 */
19
class FlysystemServiceProvider extends ServiceProvider
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $driversMap = [
25
        'viettel' => ViettelDriver::class,
26
    ];
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function register(): void
32
    {
33
        $this->registerDrivers();
34
    }
35
36
    /**
37
     * Đăng ký các storage drivers của package.
38
     */
39
    protected function registerDrivers(): void
40
    {
41
        $this->app->extend('filesystem', function (FilesystemManager $manager) {
42
            foreach ($this->driversMap as $driver => $class) {
43
                $manager->extend($driver, Closure::fromCallable(new $class()));
44
            }
45
46
            return $manager;
47
        });
48
    }
49
}
50