1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 09:31:53 +02:00

Move method from trait to AbstractDecoder

This commit is contained in:
Oliver Vogel
2023-11-03 15:46:05 +01:00
parent 8041ae6329
commit ce7b640ab9
4 changed files with 10 additions and 22 deletions

View File

@@ -44,7 +44,7 @@ abstract class AbstractDecoder implements DecoderInterface
protected function decodeExifData(string $image_data): array
{
if (! function_exists('exif_read_data')) {
if (!function_exists('exif_read_data')) {
return [];
}
@@ -60,4 +60,13 @@ abstract class AbstractDecoder implements DecoderInterface
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);
}
}

View File

@@ -6,12 +6,9 @@ use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanValidateBase64;
class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
use CanValidateBase64;
public function decode($input): ImageInterface|ColorInterface
{
if (! $this->isValidBase64($input)) {

View File

@@ -6,12 +6,9 @@ use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanValidateBase64;
class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
use CanValidateBase64;
public function decode($input): ImageInterface|ColorInterface
{
if (! $this->isValidBase64($input)) {

View File

@@ -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);
}
}