1 | <?php |
||
10 | class ImageGenerator |
||
11 | { |
||
12 | /** |
||
13 | * @var Server |
||
14 | */ |
||
15 | private $server; |
||
16 | |||
17 | /** |
||
18 | * @var FilenameGeneratorInterface |
||
19 | */ |
||
20 | private $filenameGenerator; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $defaultImageParameters; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $tmpPath; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $tmpPrefix; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $fallbackImage; |
||
41 | |||
42 | /** |
||
43 | * @param Server $server |
||
44 | * @param FilenameGeneratorInterface $filenameGenerator |
||
45 | * @param array $defaultImageParameters |
||
46 | * @param null $fallbackImage |
||
47 | * @param null $tmpPath |
||
48 | * @param null $tmpPrefix |
||
49 | */ |
||
50 | 1 | public function __construct( |
|
51 | Server $server, |
||
52 | FilenameGeneratorInterface $filenameGenerator, |
||
53 | $defaultImageParameters = [], |
||
54 | $fallbackImage = null, |
||
55 | $tmpPath = null, |
||
56 | $tmpPrefix = null |
||
57 | ) { |
||
58 | 1 | $this->server = $server; |
|
59 | 1 | $this->filenameGenerator = $filenameGenerator; |
|
60 | 1 | $this->defaultImageParameters = $defaultImageParameters; |
|
61 | 1 | $this->fallbackImage = $fallbackImage; |
|
62 | 1 | $this->tmpPath = $tmpPath; |
|
63 | 1 | $this->tmpPrefix = $tmpPrefix; |
|
64 | 1 | } |
|
65 | |||
66 | /** |
||
67 | * @param MediaInterface $media |
||
68 | * @param ParameterBag $parameterBag |
||
69 | * @return mixed |
||
70 | */ |
||
71 | 1 | public function generate(MediaInterface $media, ParameterBag $parameterBag) |
|
72 | { |
||
73 | 1 | $parameterBag->setDefaults($this->defaultImageParameters); |
|
74 | |||
75 | 1 | $filename = $this->filenameGenerator->generate($media, $parameterBag); |
|
76 | |||
77 | 1 | if (!$this->server->getSource()->has($filename)) { |
|
78 | $this->generateImage($media, $parameterBag, $filename); |
||
79 | } |
||
80 | |||
81 | 1 | return $filename; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param MediaInterface $media |
||
86 | * @param ParameterBag $parameterBag |
||
87 | * @param $filename |
||
88 | * @throws FilesystemException |
||
89 | * @throws \Exception |
||
90 | */ |
||
91 | protected function generateImage(MediaInterface $media, ParameterBag $parameterBag, $filename) |
||
112 | |||
113 | /** |
||
114 | * @param MediaInterface $media |
||
115 | * @return string |
||
116 | * @throws FilesystemException |
||
117 | */ |
||
118 | protected function getImageData(MediaInterface $media) |
||
130 | |||
131 | /** |
||
132 | * @param MediaInterface $media |
||
133 | * @param $tmp |
||
134 | * @param ParameterBag $parameterBag |
||
135 | * @return string |
||
136 | */ |
||
137 | protected function doGenerateImage(MediaInterface $media, $tmp, ParameterBag $parameterBag) |
||
145 | |||
146 | /** |
||
147 | * @return string |
||
148 | */ |
||
149 | protected function getTemporaryFile() |
||
160 | |||
161 | /** |
||
162 | * @return Server |
||
163 | */ |
||
164 | public function getServer() |
||
168 | |||
169 | /** |
||
170 | * @return FilenameGeneratorInterface |
||
171 | */ |
||
172 | public function getFilenameGenerator() |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getTmpPath() |
||
184 | |||
185 | /** |
||
186 | * @return string |
||
187 | */ |
||
188 | public function getTmpPrefix() |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getFallbackImage() |
||
200 | } |
||
201 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.