Completed
Push — 2.0 ( 9e2b8d )
by Nicolas
03:40
created

BaseUrlResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A resolve() 0 7 1
A getConfiguredFilesystem() 0 4 1
1
<?php namespace Modules\Media\UrlResolvers;
2
3
use Illuminate\Contracts\Filesystem\Factory;
4
use League\Flysystem\Adapter\Ftp;
5
use League\Flysystem\Adapter\Local;
6
use League\Flysystem\AwsS3v3\AwsS3Adapter;
7
8
class BaseUrlResolver
9
{
10
    /**
11
     * @var array
12
     */
13
    private $resolvers = [];
14
15
    public function __construct()
16
    {
17
        $this->resolvers = [
18
            Local::class => new LocalUrlResolver(),
19
            AwsS3Adapter::class => new AwsS3UrlResolver(),
20
            Ftp::class => new FtpUrlResolver(),
21
        ];
22
    }
23
24
    /**
25
     * Resolve the given path based on the set filesystem
26
     * @param string $path
27
     * @return string
28
     */
29
    public function resolve($path)
30
    {
31
        $factory = app(Factory::class);
32
        $adapter = $factory->disk($this->getConfiguredFilesystem())->getDriver()->getAdapter();
33
34
        return $this->resolvers[get_class($adapter)]->resolve($adapter, $path);
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    private function getConfiguredFilesystem()
41
    {
42
        return config('asgard.media.config.filesystem');
43
    }
44
}
45