mirror of
https://github.com/Intervention/image.git
synced 2025-08-05 13:27:29 +02: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:
@@ -11,10 +11,11 @@ use Intervention\Image\Exceptions\DecoderException;
|
|||||||
use Intervention\Image\Image;
|
use Intervention\Image\Image;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
use Intervention\Image\Interfaces\SpecializedInterface;
|
||||||
use Intervention\Image\Modifiers\AlignRotationModifier;
|
use Intervention\Image\Modifiers\AlignRotationModifier;
|
||||||
use Intervention\Image\Modifiers\RemoveAnimationModifier;
|
use Intervention\Image\Modifiers\RemoveAnimationModifier;
|
||||||
|
|
||||||
class NativeObjectDecoder extends SpecializableDecoder
|
class NativeObjectDecoder extends SpecializableDecoder implements SpecializedInterface
|
||||||
{
|
{
|
||||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
|
@@ -95,17 +95,19 @@ class InputHandler implements InputHandlerInterface
|
|||||||
public function handle($input): ImageInterface|ColorInterface
|
public function handle($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
foreach ($this->decoders as $decoder) {
|
foreach ($this->decoders as $decoder) {
|
||||||
// resolve driver specialized decoder
|
|
||||||
$decoder = $this->resolve($decoder);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $decoder->decode($input);
|
// decode with driver specialized decoder
|
||||||
} catch (DecoderException $e) {
|
return $this->resolve($decoder)->decode($input);
|
||||||
|
} catch (DecoderException | NotSupportedException $e) {
|
||||||
// try next decoder
|
// 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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user