refactor: susun semula struktur folder — Laravel source ke src/

This commit is contained in:
Saufi
2026-05-19 15:58:35 +08:00
parent f052251b94
commit bf53c71b45
10806 changed files with 1385379 additions and 121 deletions

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Intervention\Gif\Traits;
use Intervention\Gif\Decoders\AbstractDecoder;
use Intervention\Gif\Exceptions\DecoderException;
trait CanDecode
{
/**
* Decode current instance.
*
* @throws DecoderException
*/
public static function decode(mixed $source, ?int $length = null): mixed
{
return self::decoder($source, $length)->decode();
}
/**
* Get decoder for current instance.
*
* @throws DecoderException
*/
protected static function decoder(mixed $source, ?int $length = null): AbstractDecoder
{
$classname = sprintf('Intervention\Gif\Decoders\%sDecoder', self::shortClassname());
if (!class_exists($classname)) {
throw new DecoderException('Decoder for "' . static::class . '" not found');
}
$decoder = new $classname($source, $length);
if (!($decoder instanceof AbstractDecoder)) {
throw new DecoderException('Decoder for "' . static::class . '" not found');
}
return $decoder;
}
}

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Intervention\Gif\Traits;
use Intervention\Gif\Encoders\AbstractEncoder;
use Intervention\Gif\Exceptions\EncoderException;
trait CanEncode
{
/**
* Encode current entity.
*
* @throws EncoderException
*/
public function encode(): string
{
return $this->encoder()->encode();
}
/**
* Get encoder object for current entity.
*
* @throws EncoderException
*/
protected function encoder(): AbstractEncoder
{
$classname = sprintf('Intervention\Gif\Encoders\%sEncoder', self::shortClassname());
if (!class_exists($classname)) {
throw new EncoderException('Encoder for "' . $this::class . '" not found');
}
$encoder = new $classname($this);
if (!($encoder instanceof AbstractEncoder)) {
throw new EncoderException('Encoder for "' . $this::class . '" not found');
}
return $encoder;
}
}

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Intervention\Gif\Traits;
use Intervention\Gif\Exceptions\StreamException;
trait CanHandleFiles
{
/**
* Determines if input is file path.
*/
private static function isFilePath(mixed $input): bool
{
return is_string($input) && !self::hasNullBytes($input) && @is_file($input) === true;
}
/**
* Determine if given string contains null bytes.
*/
private static function hasNullBytes(string $string): bool
{
return str_contains($string, chr(0));
}
/**
* Create stream resource from given gif image data.
*
* @throws StreamException
*/
private static function streamFromData(string $data): mixed
{
$stream = fopen('php://temp', 'r+');
if ($stream === false) {
throw new StreamException('Failed to create tempory stream resource');
}
$result = fwrite($stream, $data);
if ($result === false) {
fclose($stream);
throw new StreamException('Failed to write tempory stream resource');
}
$result = rewind($stream);
if ($result === false) {
fclose($stream);
throw new StreamException('Failed to rewind tempory stream resource');
}
return $stream;
}
/**
* Create stream resource from given file path.
*
* @throws StreamException
*/
private static function streamFromFilePath(string $path): mixed
{
$stream = fopen($path, 'rb');
if ($stream === false) {
throw new StreamException('Failed to create stream resource from path');
}
return $stream;
}
}