Passed
Pull Request — master (#407)
by Kirill
09:14 queued 02:20
created

UriResolvableTrait::toUriFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Storage\File;
13
14
use Psr\Http\Message\UriInterface;
15
use Spiral\Distribution\ResolverInterface;
16
17
/**
18
 * @mixin UriResolvableInterface
19
 */
20
trait UriResolvableTrait
21
{
22
    /**
23
     * {@see EntryInterface::getPathname()}
24
     */
25
    abstract public function getPathname(): string;
26
27
    /**
28
     * {@see UriResolvableInterface::toUri()}
29
     */
30
    public function toUri(): UriInterface
31
    {
32
        $resolver = $this->getResolver();
33
34
        if ($resolver === null) {
35
            throw new \LogicException('Can not generate public url: File not accessible by HTTP');
36
        }
37
38
        return $this->toUriFrom($resolver);
39
    }
40
41
    /**
42
     * {@see UriResolvableInterface::toUriFrom()}
43
     */
44
    public function toUriFrom(ResolverInterface $resolver): UriInterface
45
    {
46
        return $resolver->resolve($this->getPathname());
47
    }
48
49
    /**
50
     * @return ResolverInterface|null
51
     */
52
    abstract protected function getResolver(): ?ResolverInterface;
53
}
54