|
4 | 4 |
|
5 | 5 | namespace Assets\ImageCreation\LegacyV2Intervention; |
6 | 6 |
|
7 | | -use Assets\Error\InvalidArgumentException; |
8 | 7 | use Assets\Error\ModificationFailedException; |
9 | 8 | use Assets\ImageCreation\ImageInterface; |
10 | 9 | use Intervention\Image\Image; |
11 | 10 | use Intervention\Image\MediaType; |
12 | | -use Intervention\Image\Interfaces as Intervention; |
13 | 11 | use Nette\Utils\FileSystem; |
14 | 12 |
|
15 | 13 | final class InterventionImageFacade implements ImageInterface |
16 | 14 | { |
17 | | - /** |
18 | | - * @param array<string, string|callable> $legacyMdifiersMap |
19 | | - */ |
20 | 15 | public function __construct( |
21 | 16 | private Image $interventionImage, |
22 | | - private array $legacyMdifiersMap, |
23 | | - ) { |
| 17 | + ) { |
24 | 18 | } |
25 | 19 |
|
26 | 20 | public function width(): int |
@@ -62,55 +56,30 @@ public function modify(string $modifier, array $params): ImageInterface |
62 | 56 | throw new ModificationFailedException('Empty params given'); |
63 | 57 | } |
64 | 58 |
|
65 | | - $modify = function (string $modifier, array $params, ?string $legacyModifier = null) { |
66 | | - try { |
| 59 | + try { |
| 60 | + if (method_exists($this->interventionImage, $modifier)) { |
67 | 61 | $this->interventionImage->{$modifier}(...$params); |
68 | | - } catch (\Throwable $throwable) { |
69 | | - |
70 | | - if ($legacyModifier === null) { |
71 | | - $callback = $this->legacyMdifiersMap[$modifier] ?? null; |
72 | | - if ($callback !== null && is_callable($callback)) { |
73 | | - $callback($this->interventionImage, ...$params); |
74 | | - return $this->interventionImage; |
75 | | - } |
76 | | - } |
77 | | - |
78 | | - throw new ModificationFailedException( |
79 | | - sprintf( |
80 | | - 'Modification `%s` failed with params: %s.%s', |
81 | | - $modifier, |
82 | | - var_export($params, true), |
83 | | - $legacyModifier !== null ? ' Legacy: ' . $legacyModifier : '', |
84 | | - ), |
85 | | - previous: $throwable, |
86 | | - ); |
87 | 62 | } |
88 | | - }; |
89 | | - |
90 | | - if (method_exists($this->interventionImage, $modifier)) { |
91 | | - $modify($modifier, $params); |
92 | | - return $this; |
93 | | - } |
94 | | - |
95 | | - $mappedFromLegacy = $this->legacyMdifiersMap[$modifier] ?? null; |
96 | | - |
97 | | - if ( |
98 | | - $mappedFromLegacy !== null |
99 | | - && method_exists($this->interventionImage, $mappedFromLegacy) |
100 | | - ) { |
101 | | - $modify($mappedFromLegacy, $params, $modifier); |
102 | | - return $this; |
| 63 | + } catch (\Throwable $throwable) { |
| 64 | + throw new ModificationFailedException( |
| 65 | + sprintf( |
| 66 | + 'Modification `%s` failed with params: %s.', |
| 67 | + $modifier, |
| 68 | + var_export($params, true), |
| 69 | + ), |
| 70 | + previous: $throwable, |
| 71 | + ); |
103 | 72 | } |
104 | 73 |
|
105 | 74 | throw new ModificationFailedException(sprintf('Modifier `%s` does not exist', $modifier)); |
106 | 75 | } |
107 | 76 |
|
108 | | - public function getInterventionImage(): Intervention\ImageInterface |
| 77 | + public function getInterventionImage(): Image |
109 | 78 | { |
110 | | - return $this->requireInterventionImage(); |
| 79 | + return $this->interventionImage; |
111 | 80 | } |
112 | 81 |
|
113 | | - public function requireInterventionImage(): Intervention\ImageInterface |
| 82 | + public function requireInterventionImage(): Image |
114 | 83 | { |
115 | 84 | return $this->interventionImage; |
116 | 85 | } |
|
0 commit comments