mirror of
https://github.com/Intervention/image.git
synced 2025-08-31 01:29:51 +02:00
Add ability to read instances of EncodedImaged::class (#1386)
* Implement EncodedImageObjectDecoder::class * Add tests for EncodedImageObjectDecoder::class
This commit is contained in:
11
src/Decoders/EncodedImageObjectDecoder.php
Normal file
11
src/Decoders/EncodedImageObjectDecoder.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Decoders;
|
||||
|
||||
use Intervention\Image\Drivers\SpecializableDecoder;
|
||||
|
||||
class EncodedImageObjectDecoder extends SpecializableDecoder
|
||||
{
|
||||
}
|
27
src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php
Normal file
27
src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
|
||||
class EncodedImageObjectDecoder extends BinaryImageDecoder
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DecoderInterface::decode()
|
||||
*/
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_a($input, EncodedImage::class)) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
}
|
||||
|
||||
return parent::decode($input->toString());
|
||||
}
|
||||
}
|
27
src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php
Normal file
27
src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
|
||||
class EncodedImageObjectDecoder extends BinaryImageDecoder
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DecoderInterface::decode()
|
||||
*/
|
||||
public function decode(mixed $input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (!is_a($input, EncodedImage::class)) {
|
||||
throw new DecoderException('Unable to decode input');
|
||||
}
|
||||
|
||||
return parent::decode($input->toString());
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ use Intervention\Image\Decoders\Base64ImageDecoder;
|
||||
use Intervention\Image\Decoders\BinaryImageDecoder;
|
||||
use Intervention\Image\Decoders\ColorObjectDecoder;
|
||||
use Intervention\Image\Decoders\DataUriImageDecoder;
|
||||
use Intervention\Image\Decoders\EncodedImageObjectDecoder;
|
||||
use Intervention\Image\Decoders\FilePathImageDecoder;
|
||||
use Intervention\Image\Decoders\FilePointerImageDecoder;
|
||||
use Intervention\Image\Decoders\ImageObjectDecoder;
|
||||
@@ -53,6 +54,7 @@ class InputHandler implements InputHandlerInterface
|
||||
BinaryImageDecoder::class,
|
||||
DataUriImageDecoder::class,
|
||||
Base64ImageDecoder::class,
|
||||
EncodedImageObjectDecoder::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders;
|
||||
|
||||
use Intervention\Image\Drivers\Gd\Decoders\EncodedImageObjectDecoder;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\ImagickTestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
|
||||
#[RequiresPhpExtension('gd')]
|
||||
#[CoversClass(EncodedImageObjectDecoder::class)]
|
||||
class EncodedImageObjectDecoderTest extends ImagickTestCase
|
||||
{
|
||||
protected EncodedImageObjectDecoder $decoder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->decoder = new EncodedImageObjectDecoder();
|
||||
$this->decoder->setDriver(new Driver());
|
||||
}
|
||||
|
||||
public function testDecode(): void
|
||||
{
|
||||
$result = $this->decoder->decode(new EncodedImage($this->getTestResourceData()));
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders;
|
||||
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\EncodedImageObjectDecoder;
|
||||
use Intervention\Image\Drivers\Imagick\Driver;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Tests\ImagickTestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
|
||||
#[RequiresPhpExtension('imagick')]
|
||||
#[CoversClass(EncodedImageObjectDecoder::class)]
|
||||
class EncodedImageObjectDecoderTest extends ImagickTestCase
|
||||
{
|
||||
protected EncodedImageObjectDecoder $decoder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->decoder = new EncodedImageObjectDecoder();
|
||||
$this->decoder->setDriver(new Driver());
|
||||
}
|
||||
|
||||
public function testDecode(): void
|
||||
{
|
||||
$result = $this->decoder->decode(new EncodedImage($this->getTestResourceData()));
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user