Completed
Pull Request — 2.x (#1348)
by Peter
02:07
created

FilterTrait::filterCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 4
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\Templating;
13
14
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
15
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
16
17
trait FilterTrait
18
{
19
    /**
20
     * @var CacheManager
21
     */
22
    private $cache;
23
24
    public function __construct(CacheManager $cache)
25
    {
26
        $this->cache = $cache;
27
    }
28
29
    /**
30
     * Gets the browser path for the image and filter to apply.
31
     */
32
    public function filter(
33
        string $path,
34
        string $filter,
35
        array $config = [],
36
        ?string $resolver = null,
37
        int $referenceType = UrlGeneratorInterface::ABSOLUTE_URL
38
    ): string {
39
        $path = parse_url($path, PHP_URL_PATH);
40
41
        return $this->cache->getBrowserPath($path, $filter, $config, $resolver, $referenceType);
42
    }
43
44
    /**
45
     * Gets the cache path for the image and filter to apply.
46
     */
47
    public function filterCache(
48
        string $path,
49
        string $filter,
50
        array $config = [],
51
        ?string $resolver = null
52
    ): string {
53
        $path = parse_url($path, PHP_URL_PATH);
54
55
        if (!empty($config)) {
56
            $path = $this->cache->getRuntimePath($path, $config);
57
        }
58
59
        return $this->cache->resolve($path, $filter, $resolver);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getName(): string
66
    {
67
        return 'liip_imagine';
68
    }
69
}
70