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

MediaPath::getUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Modules\Media\ValueObjects;
2
3
use Modules\Media\UrlResolvers\BaseUrlResolver;
4
5
class MediaPath
6
{
7
    /**
8
     * @var string
9
     */
10
    private $path;
11
12
    public function __construct($path)
13
    {
14
        if (! is_string($path)) {
15
            throw new \InvalidArgumentException('The path must be a string');
16
        }
17
        $this->path = $path;
18
    }
19
20
    /**
21
     * Get the URL depending on configured disk
22
     * @return string
23
     */
24
    public function getUrl()
25
    {
26
        return (new BaseUrlResolver())->resolve($this->path);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getRelativeUrl()
33
    {
34
        return $this->path;
35
    }
36
37
    public function __toString()
38
    {
39
        try {
40
            return $this->getUrl();
41
        } catch (\Exception $e) {
42
            return '';
43
        }
44
    }
45
}
46