1 | <?php |
||
16 | class ImageTransformer |
||
17 | { |
||
18 | use Utils\CacheMessageTrait; |
||
19 | |||
20 | /** |
||
21 | * @var array|false Enable client hints |
||
22 | */ |
||
23 | private $clientHints = false; |
||
24 | |||
25 | /** |
||
26 | * @var array Available sizes |
||
27 | */ |
||
28 | private $sizes = []; |
||
29 | |||
30 | /** |
||
31 | * Define the available sizes, for example: |
||
32 | * [ |
||
33 | * 'small' => 'resizeCrop,50,50', |
||
34 | * 'medium' => 'resize,500', |
||
35 | * 'big' => 'resize,1000', |
||
36 | * ]. |
||
37 | * |
||
38 | * @param array $sizes |
||
39 | */ |
||
40 | public function __construct(array $sizes) |
||
44 | |||
45 | /** |
||
46 | * To save the transformed images in the cache. |
||
47 | * |
||
48 | * @param CacheItemPoolInterface $cache |
||
49 | * |
||
50 | * @return self |
||
51 | */ |
||
52 | public function cache(CacheItemPoolInterface $cache) |
||
58 | |||
59 | /** |
||
60 | * Enable the client hints. |
||
61 | * |
||
62 | * @param array $clientHints |
||
63 | * |
||
64 | * @return self |
||
65 | */ |
||
66 | public function clientHints($clientHints = ['Dpr', 'Viewport-Width', 'Width']) |
||
72 | |||
73 | /** |
||
74 | * Execute the middleware. |
||
75 | * |
||
76 | * @param ServerRequestInterface $request |
||
77 | * @param ResponseInterface $response |
||
78 | * @param callable $next |
||
79 | * |
||
80 | * @return ResponseInterface |
||
81 | */ |
||
82 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
135 | |||
136 | /** |
||
137 | * Transform the image. |
||
138 | * |
||
139 | * @param ServerRequestInterface $request |
||
140 | * @param ResponseInterface $response |
||
141 | * @param string $transform |
||
142 | * |
||
143 | * @return ResponseInterface |
||
144 | */ |
||
145 | private function transform(ServerRequestInterface $request, ResponseInterface $response, $transform) |
||
164 | |||
165 | /** |
||
166 | * Parses the path and return the file and transform values. |
||
167 | * For example, the path "/images/small.avatar.jpg" returns: |
||
168 | * ["/images/avatar.jpg", "resizeCrop,50,50"]. |
||
169 | * |
||
170 | * @param string $path |
||
171 | * |
||
172 | * @return false|array [file, transform] |
||
173 | */ |
||
174 | private function parsePath($path) |
||
196 | |||
197 | /** |
||
198 | * Returns the client hints sent. |
||
199 | * |
||
200 | * @param ServerRequestInterface $request |
||
201 | * |
||
202 | * @return array|null |
||
203 | */ |
||
204 | private function getClientHints(ServerRequestInterface $request) |
||
218 | |||
219 | /** |
||
220 | * Generates the key used to save the image in cache. |
||
221 | * |
||
222 | * @param ServerRequestInterface $request |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | private function getCacheKey(ServerRequestInterface $request) |
||
237 | } |
||
238 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..