|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\MediaBundle\Thumbnail; |
|
15
|
|
|
|
|
16
|
|
|
use Liip\ImagineBundle\Imagine\Cache\CacheManager; |
|
17
|
|
|
use Sonata\MediaBundle\Model\MediaInterface; |
|
18
|
|
|
use Sonata\MediaBundle\Provider\MediaProviderInterface; |
|
19
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
20
|
|
|
|
|
21
|
|
|
class LiipImagineThumbnail implements ThumbnailInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @deprecated Since version 3.3, will be removed in 4.0. |
|
25
|
|
|
* |
|
26
|
|
|
* @var RouterInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $router; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var CacheManager |
|
32
|
|
|
*/ |
|
33
|
|
|
private $cacheManager; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param RouterInterface|CacheManager $cacheManager |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct($cacheManager) |
|
39
|
|
|
{ |
|
40
|
|
|
if ($cacheManager instanceof RouterInterface) { |
|
41
|
|
|
@trigger_error(sprintf( |
|
|
|
|
|
|
42
|
|
|
'Using an instance of %s is deprecated since version 3.3 and will be removed in 4.0. Use %s.', |
|
43
|
|
|
RouterInterface::class, |
|
44
|
|
|
CacheManager::class |
|
45
|
|
|
), E_USER_DEPRECATED); |
|
46
|
|
|
$this->router = $cacheManager; |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
$this->cacheManager = $cacheManager; |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function generatePublicUrl(MediaProviderInterface $provider, MediaInterface $media, $format) |
|
55
|
|
|
{ |
|
56
|
|
|
$path = $provider->getReferenceImage($media); |
|
57
|
|
|
|
|
58
|
|
|
if (MediaProviderInterface::FORMAT_ADMIN === $format || MediaProviderInterface::FORMAT_REFERENCE === $format) { |
|
59
|
|
|
return $path; |
|
60
|
|
|
} |
|
61
|
|
|
if ($this->router instanceof RouterInterface && !($this->cacheManager instanceof CacheManager)) { |
|
|
|
|
|
|
62
|
|
|
$path = $this->router->generate( |
|
|
|
|
|
|
63
|
|
|
sprintf('_imagine_%s', $format), |
|
64
|
|
|
['path' => sprintf('%s/%s_%s.jpg', $provider->generatePath($media), $media->getId(), $format)] |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$path = $provider->getCdnPath($path, $media->getCdnIsFlushable()); |
|
69
|
|
|
if ($this->cacheManager instanceof CacheManager) { |
|
70
|
|
|
$path = $this->cacheManager->getBrowserPath($path, $format); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $path; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function generatePrivateUrl(MediaProviderInterface $provider, MediaInterface $media, $format) |
|
80
|
|
|
{ |
|
81
|
|
|
if (MediaProviderInterface::FORMAT_REFERENCE !== $format) { |
|
82
|
|
|
throw new \RuntimeException('No private url for LiipImagineThumbnail'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$path = $provider->getReferenceImage($media); |
|
86
|
|
|
|
|
87
|
|
|
return $path; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
public function generate(MediaProviderInterface $provider, MediaInterface $media): void |
|
94
|
|
|
{ |
|
95
|
|
|
// nothing to generate, as generated on demand |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
|
|
public function delete(MediaProviderInterface $provider, MediaInterface $media, $formats = null): void |
|
102
|
|
|
{ |
|
103
|
|
|
// feature not available |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: