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:
parent
bb0e9284a3
commit
c199536eac
@ -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
|
||||
{
|
||||
|
@ -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.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user