1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-17 12:18:14 +01:00

Refactor InputHandler decoder resolving

Makes it possible that decoders of InputHandler do not necessarily
have to have a driver-specific version of "Inter". If the decoder
class cannot be resolved by the driver and is therefore not
available, it is simply ignored and the next decoder will be tried.
This commit is contained in:
Oliver Vogel 2024-06-23 17:15:42 +02:00
parent bb0e9284a3
commit c199536eac
No known key found for this signature in database
GPG Key ID: 1B19D214C02D69BB
2 changed files with 10 additions and 7 deletions

View File

@ -11,10 +11,11 @@ use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\AlignRotationModifier;
use Intervention\Image\Modifiers\RemoveAnimationModifier;
class NativeObjectDecoder extends SpecializableDecoder
class NativeObjectDecoder extends SpecializableDecoder implements SpecializedInterface
{
public function decode(mixed $input): ImageInterface|ColorInterface
{

View File

@ -95,17 +95,19 @@ class InputHandler implements InputHandlerInterface
public function handle($input): ImageInterface|ColorInterface
{
foreach ($this->decoders as $decoder) {
// resolve driver specialized decoder
$decoder = $this->resolve($decoder);
try {
return $decoder->decode($input);
} catch (DecoderException $e) {
// decode with driver specialized decoder
return $this->resolve($decoder)->decode($input);
} catch (DecoderException | NotSupportedException $e) {
// try next decoder
}
}
throw new DecoderException(isset($e) ? $e->getMessage() : '');
if (isset($e)) {
throw new ($e::class)($e->getMessage());
}
throw new DecoderException('Unable to decode input.');
}
/**