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 resolve path for the image and filter to apply. |
46
|
|
|
*/ |
47
|
|
|
public function filterResolve( |
48
|
|
|
string $path, |
49
|
|
|
string $filter, |
50
|
|
|
array $config = [], |
51
|
|
|
?string $resolver = null, |
52
|
|
|
int $referenceType = UrlGeneratorInterface::ABSOLUTE_URL |
53
|
|
|
): string { |
54
|
|
|
$path = parse_url($path, PHP_URL_PATH); |
55
|
|
|
|
56
|
|
|
return $this->cache->generateUrl($path, $filter, $config, $resolver, $referenceType); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Gets the cache path for the image and filter to apply. |
61
|
|
|
*/ |
62
|
|
|
public function filterCache( |
63
|
|
|
string $path, |
64
|
|
|
string $filter, |
65
|
|
|
array $config = [], |
66
|
|
|
?string $resolver = null |
67
|
|
|
): string { |
68
|
|
|
$path = parse_url($path, PHP_URL_PATH); |
69
|
|
|
|
70
|
|
|
if (!empty($config)) { |
71
|
|
|
$path = $this->cache->getRuntimePath($path, $config); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->cache->resolve($path, $filter, $resolver); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function getName(): string |
81
|
|
|
{ |
82
|
|
|
return 'liip_imagine'; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|