mirror of
https://github.com/Intervention/image.git
synced 2025-09-03 10:53:01 +02:00
Move method from trait to AbstractDecoder
This commit is contained in:
@@ -60,4 +60,13 @@ abstract class AbstractDecoder implements DecoderInterface
|
|||||||
|
|
||||||
return is_array($data) ? $data : [];
|
return is_array($data) ? $data : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isValidBase64($input): bool
|
||||||
|
{
|
||||||
|
if (!is_string($input)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base64_encode(base64_decode($input)) === str_replace(["\n", "\r"], '', $input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,12 +6,9 @@ use Intervention\Image\Exceptions\DecoderException;
|
|||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanValidateBase64;
|
|
||||||
|
|
||||||
class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
use CanValidateBase64;
|
|
||||||
|
|
||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! $this->isValidBase64($input)) {
|
if (! $this->isValidBase64($input)) {
|
||||||
|
@@ -6,12 +6,9 @@ use Intervention\Image\Exceptions\DecoderException;
|
|||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanValidateBase64;
|
|
||||||
|
|
||||||
class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
use CanValidateBase64;
|
|
||||||
|
|
||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! $this->isValidBase64($input)) {
|
if (! $this->isValidBase64($input)) {
|
||||||
|
@@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Intervention\Image\Traits;
|
|
||||||
|
|
||||||
trait CanValidateBase64
|
|
||||||
{
|
|
||||||
protected function isValidBase64($input): bool
|
|
||||||
{
|
|
||||||
if (! is_string($input)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return base64_encode(base64_decode($input)) === str_replace(["\n", "\r"], '', $input);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user