Completed
Pull Request — master (#1233)
by
unknown
01:32
created

PathResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Utility\Path;
13
14
use Liip\ImagineBundle\Imagine\Cache\Helper\PathHelper;
15
16
class PathResolver implements PathResolverInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $webRoot;
22
23
    /**
24
     * @var string
25
     */
26
    protected $cachePrefix;
27
28
    /**
29
     * @var string
30
     */
31
    protected $cacheRoot;
32
33
    public function __construct(
34
        $webRootDir,
35
        $cachePrefix = 'media/cache'
36
    ) {
37
        $this->webRoot = rtrim(str_replace('//', '/', $webRootDir), '/');
38
        $this->cachePrefix = ltrim(str_replace('//', '/', $cachePrefix), '/');
39
        $this->cacheRoot = $this->webRoot.'/'.$this->cachePrefix;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getFilePath($path, $filter): string
46
    {
47
        return $this->webRoot.'/'.$this->getFullPath($path, $filter);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getFileUrl($path, $filter): string
54
    {
55
        return PathHelper::filePathToUrlPath($this->getFullPath($path, $filter));
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getCacheRoot(): string
62
    {
63
        return $this->cacheRoot;
64
    }
65
66 View Code Duplication
    private function getFullPath($path, $filter): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        // crude way of sanitizing URL scheme ("protocol") part
69
        $path = str_replace('://', '---', $path);
70
71
        return $this->cachePrefix.'/'.$filter.'/'.ltrim($path, '/');
72
    }
73
}
74