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

BaseUrlResolver::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 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