1 | <?php |
||
16 | class ImageTransformer |
||
17 | { |
||
18 | use Utils\BasePathTrait; |
||
19 | |||
20 | /** |
||
21 | * @var array Available sizes |
||
22 | */ |
||
23 | protected $sizes = []; |
||
24 | |||
25 | /** |
||
26 | * Define the available sizes, for example: |
||
27 | * [ |
||
28 | * 'small' => 'resizeCrop,50,50', |
||
29 | * 'medium' => 'resize,500', |
||
30 | * 'big' => 'resize,1000', |
||
31 | * ]. |
||
32 | * |
||
33 | * @param array $sizes |
||
34 | * |
||
35 | * @return self |
||
|
|||
36 | */ |
||
37 | public function __construct(array $sizes) |
||
43 | |||
44 | /** |
||
45 | * Execute the middleware. |
||
46 | * |
||
47 | * @param ServerRequestInterface $request |
||
48 | * @param ResponseInterface $response |
||
49 | * @param callable $next |
||
50 | * |
||
51 | * @return ResponseInterface |
||
52 | */ |
||
53 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
77 | |||
78 | /** |
||
79 | * Transform the image. |
||
80 | * |
||
81 | * @param ResponseInterface $response |
||
82 | * @param string $transform |
||
83 | * |
||
84 | * @return ResponseInterface |
||
85 | */ |
||
86 | private function transform(ResponseInterface $response, $transform) |
||
98 | |||
99 | /** |
||
100 | * Parses the path and return the file and transform values. |
||
101 | * For example, the path "/images/small.avatar.jpg" returns: |
||
102 | * ["/images/avatar.jpg", "resizeCrop,50,50"]. |
||
103 | * |
||
104 | * @param string $path |
||
105 | * |
||
106 | * @return null|array [file, transform] |
||
107 | */ |
||
108 | private function parsePath($path) |
||
129 | } |
||
130 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.