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
|
|
|
/** |
22
|
|
|
* @final since sonata-project/media-bundle 3.21.0 |
23
|
|
|
*/ |
24
|
|
|
class LiipImagineThumbnail implements ThumbnailInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @deprecated since sonata-project/media-bundle 3.3, will be removed in 4.0. |
28
|
|
|
* |
29
|
|
|
* @var RouterInterface |
30
|
|
|
*/ |
31
|
|
|
protected $router; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var CacheManager |
35
|
|
|
*/ |
36
|
|
|
private $cacheManager; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param RouterInterface|CacheManager $cacheManager |
40
|
|
|
*/ |
41
|
|
|
public function __construct($cacheManager) |
42
|
|
|
{ |
43
|
|
|
if ($cacheManager instanceof RouterInterface) { |
44
|
|
|
@trigger_error(sprintf( |
|
|
|
|
45
|
|
|
'Using an instance of %s is deprecated since version 3.3 and will be removed in 4.0. Use %s.', |
46
|
|
|
RouterInterface::class, |
47
|
|
|
CacheManager::class |
48
|
|
|
), E_USER_DEPRECATED); |
49
|
|
|
$this->router = $cacheManager; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
$this->cacheManager = $cacheManager; |
|
|
|
|
52
|
|
|
} |
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
|
|
|
public function generatePrivateUrl(MediaProviderInterface $provider, MediaInterface $media, $format) |
77
|
|
|
{ |
78
|
|
|
if (MediaProviderInterface::FORMAT_REFERENCE !== $format) { |
79
|
|
|
throw new \RuntimeException('No private url for LiipImagineThumbnail'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$path = $provider->getReferenceImage($media); |
83
|
|
|
|
84
|
|
|
return $path; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function generate(MediaProviderInterface $provider, MediaInterface $media): void |
88
|
|
|
{ |
89
|
|
|
// nothing to generate, as generated on demand |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function delete(MediaProviderInterface $provider, MediaInterface $media, $formats = null): void |
93
|
|
|
{ |
94
|
|
|
// feature not available |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: