1 | <?php |
||
10 | class LocalImage implements Image |
||
11 | { |
||
12 | private string $path; |
||
|
|||
13 | private string $filename; |
||
14 | |||
15 | 4 | public function __construct(string $path, ?string $filename = null) |
|
16 | { |
||
17 | 4 | if (!file_exists($path)) { |
|
18 | 1 | throw new LogicException(sprintf('Image %s does not exist.', $path)); |
|
19 | } |
||
20 | |||
21 | 3 | if (exif_imagetype($path) !== IMAGETYPE_PNG) { |
|
22 | 1 | throw new LogicException('Image should be of type PNG.'); |
|
23 | } |
||
24 | |||
25 | 2 | $this->path = $path; |
|
26 | 2 | $this->filename = $filename ?? basename($path); |
|
27 | 2 | } |
|
28 | |||
29 | 1 | public function setFilename(string $filename): void |
|
30 | { |
||
31 | 1 | $this->filename = $filename; |
|
32 | 1 | } |
|
33 | |||
34 | public function getContents(): string |
||
35 | { |
||
36 | return (string) file_get_contents($this->path); |
||
37 | } |
||
38 | |||
39 | 2 | public function getPath(): string |
|
40 | { |
||
41 | 2 | return $this->path; |
|
42 | } |
||
43 | |||
44 | 2 | public function getFilename(): string |
|
45 | { |
||
46 | 2 | return $this->filename; |
|
47 | } |
||
48 | } |
||
49 |