From 27fd48170b56d56429c7c5c5df72194abc14cdb7 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 25 May 2024 10:34:15 +0200 Subject: [PATCH] Move ColorObjectDecoder & ImageObjectDecoder Move ColorObjectDecoder & ImageObjectDecoder from drivers context because they can operate without any specific drivers information must not be specialized. --- src/Decoders/ColorObjectDecoder.php | 20 +++++++++++++++-- src/Decoders/ImageObjectDecoder.php | 20 +++++++++++++++-- .../Gd/Decoders/ColorObjectDecoder.php | 22 ------------------- .../Gd/Decoders/ImageObjectDecoder.php | 22 ------------------- .../Imagick/Decoders/ColorObjectDecoder.php | 22 ------------------- .../Imagick/Decoders/ImageObjectDecoder.php | 22 ------------------- .../Gd/Decoders/ImageObjectDecoderTest.php | 4 ++-- .../Decoders/ImageObjectDecoderTest.php | 4 ++-- 8 files changed, 40 insertions(+), 96 deletions(-) delete mode 100644 src/Drivers/Gd/Decoders/ColorObjectDecoder.php delete mode 100644 src/Drivers/Gd/Decoders/ImageObjectDecoder.php delete mode 100644 src/Drivers/Imagick/Decoders/ColorObjectDecoder.php delete mode 100644 src/Drivers/Imagick/Decoders/ImageObjectDecoder.php diff --git a/src/Decoders/ColorObjectDecoder.php b/src/Decoders/ColorObjectDecoder.php index f81f7170..60480361 100644 --- a/src/Decoders/ColorObjectDecoder.php +++ b/src/Decoders/ColorObjectDecoder.php @@ -4,8 +4,24 @@ declare(strict_types=1); namespace Intervention\Image\Decoders; -use Intervention\Image\Drivers\SpecializableDecoder; +use Intervention\Image\Drivers\AbstractDecoder; +use Intervention\Image\Exceptions\DecoderException; +use Intervention\Image\Interfaces\ColorInterface; +use Intervention\Image\Interfaces\ImageInterface; -class ColorObjectDecoder extends SpecializableDecoder +class ColorObjectDecoder extends AbstractDecoder { + /** + * {@inheritdoc} + * + * @see DecoderInterface::decode() + */ + public function decode(mixed $input): ImageInterface|ColorInterface + { + if (!is_a($input, ColorInterface::class)) { + throw new DecoderException('Unable to decode input'); + } + + return $input; + } } diff --git a/src/Decoders/ImageObjectDecoder.php b/src/Decoders/ImageObjectDecoder.php index ea01091c..2a98c2e8 100644 --- a/src/Decoders/ImageObjectDecoder.php +++ b/src/Decoders/ImageObjectDecoder.php @@ -4,8 +4,24 @@ declare(strict_types=1); namespace Intervention\Image\Decoders; -use Intervention\Image\Drivers\SpecializableDecoder; +use Intervention\Image\Drivers\AbstractDecoder; +use Intervention\Image\Exceptions\DecoderException; +use Intervention\Image\Interfaces\ImageInterface; +use Intervention\Image\Interfaces\ColorInterface; -class ImageObjectDecoder extends SpecializableDecoder +class ImageObjectDecoder extends AbstractDecoder { + /** + * {@inheritdoc} + * + * @see DecoderInterface::decode() + */ + public function decode(mixed $input): ImageInterface|ColorInterface + { + if (!is_a($input, ImageInterface::class)) { + throw new DecoderException('Unable to decode input'); + } + + return $input; + } } diff --git a/src/Drivers/Gd/Decoders/ColorObjectDecoder.php b/src/Drivers/Gd/Decoders/ColorObjectDecoder.php deleted file mode 100644 index 51abb3c0..00000000 --- a/src/Drivers/Gd/Decoders/ColorObjectDecoder.php +++ /dev/null @@ -1,22 +0,0 @@ -