forked from sonata-project/SonataMediaBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiipImagineThumbnail.php
81 lines (69 loc) · 2.06 KB
/
LiipImagineThumbnail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
* This file is part of the Sonata project.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\MediaBundle\Thumbnail;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Provider\MediaProviderInterface;
use Symfony\Component\Routing\RouterInterface;
class LiipImagineThumbnail implements ThumbnailInterface
{
/**
* @var \Symfony\Component\Routing\RouterInterface
*/
protected $router;
/**
* @param \Symfony\Component\Routing\RouterInterface $router
*/
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
/**
* {@inheritdoc}
*/
public function generatePublicUrl(MediaProviderInterface $provider, MediaInterface $media, $format)
{
if ($format == 'reference') {
$path = $provider->getReferenceImage($media);
} else {
$path = $this->router->generate(
sprintf('_imagine_%s', $format),
array('path' => sprintf('%s/%s_%s.jpg', $provider->generatePath($media), $media->getId(), $format))
);
}
return $provider->getCdnPath($path, $media->getCdnIsFlushable());
}
/**
* {@inheritdoc}
*/
public function generatePrivateUrl(MediaProviderInterface $provider, MediaInterface $media, $format)
{
if ($format != 'reference') {
throw new \RuntimeException('No private url for LiipImagineThumbnail');
}
$path = $provider->getReferenceImage($media);
return $path;
}
/**
* {@inheritdoc}
*/
public function generate(MediaProviderInterface $provider, MediaInterface $media)
{
// nothing to generate, as generated on demand
return;
}
/**
* {@inheritdoc}
*/
public function delete(MediaProviderInterface $provider, MediaInterface $media)
{
// feature not available
return;
}
}