refactor: susun semula struktur folder — Laravel source ke src/
This commit is contained in:
43
vendor/intervention/gif/src/Traits/CanDecode.php
vendored
Normal file
43
vendor/intervention/gif/src/Traits/CanDecode.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
43
vendor/intervention/gif/src/Traits/CanEncode.php
vendored
Normal file
43
vendor/intervention/gif/src/Traits/CanEncode.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
70
vendor/intervention/gif/src/Traits/CanHandleFiles.php
vendored
Normal file
70
vendor/intervention/gif/src/Traits/CanHandleFiles.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user