Completed
Pull Request — 2.0 (#1059)
by Nick
02:41
created

PathResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
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
class PathResolver implements PathResolverInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $webRoot;
20
21
    /**
22
     * @var string
23
     */
24
    protected $cachePrefix;
25
26
    /**
27
     * @var string
28
     */
29
    protected $cacheRoot;
30
31
    public function __construct(
32
        $webRootDir,
33
        $cachePrefix = 'media/cache'
34
    ) {
35
        $this->webRoot = rtrim(str_replace('//', '/', $webRootDir), '/');
36
        $this->cachePrefix = ltrim(str_replace('//', '/', $cachePrefix), '/');
37
        $this->cacheRoot = $this->webRoot.'/'.$this->cachePrefix;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getFilePath($path, $filter)
44
    {
45
        return $this->webRoot.'/'.$this->getFileUrl($path, $filter);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 View Code Duplication
    public function getFileUrl($path, $filter)
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...
52
    {
53
        // crude way of sanitizing URL scheme ("protocol") part
54
        $path = str_replace('://', '---', $path);
55
56
        return $this->cachePrefix.'/'.$filter.'/'.ltrim($path, '/');
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getCacheRoot()
63
    {
64
        return $this->cacheRoot;
65
    }
66
}
67