| 1 | <?php |
||
| 8 | abstract class BaseGenerator implements ImageGenerator |
||
| 9 | { |
||
| 10 | public function canConvert(Media $media): bool |
||
| 11 | { |
||
| 12 | if (! $this->requirementsAreInstalled()) { |
||
| 13 | return false; |
||
| 14 | } |
||
| 15 | |||
| 16 | if ($this->supportedExtensions()->contains(strtolower($media->extension))) { |
||
| 17 | return true; |
||
| 18 | } |
||
| 19 | |||
| 20 | if ($this->supportedMimetypes()->contains(strtolower($media->mime_type))) { |
||
| 21 | return true; |
||
| 22 | } |
||
| 23 | |||
| 24 | return false; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function canHandleMime(string $mime = ''): bool |
||
| 28 | { |
||
| 29 | return $this->supportedMimetypes()->contains($mime); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function canHandleExtension(string $extension = ''): bool |
||
| 33 | { |
||
| 34 | return $this->supportedExtensions()->contains($extension); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function getType(): string |
||
| 38 | { |
||
| 39 | return strtolower(class_basename(static::class)); |
||
| 40 | } |
||
| 41 | |||
| 42 | abstract public function requirementsAreInstalled(): bool; |
||
| 43 | |||
| 44 | abstract public function supportedExtensions(): Collection; |
||
| 45 | |||
| 46 | abstract public function supportedMimetypes(): Collection; |
||
| 47 | } |
||
| 48 |