-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to read instances of EncodedImaged::class (#1386)
* Implement EncodedImageObjectDecoder::class * Add tests for EncodedImageObjectDecoder::class
- Loading branch information
1 parent
4a614dd
commit 31779d0
Showing
6 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Intervention\Image\Decoders; | ||
|
||
use Intervention\Image\Drivers\SpecializableDecoder; | ||
|
||
class EncodedImageObjectDecoder extends SpecializableDecoder | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 27 additions & 0 deletions
27
src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |