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,25 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
class AutoEncoder extends MediaTypeEncoder
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImageInterface
{
return $image->encode(
$this->encoderByMediaType(
$image->origin()->mediaType()
)
);
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class AvifEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*
* @param null|bool $strip Strip EXIF metadata
* @throws InvalidArgumentException
*/
public function __construct(
public int $quality = self::DEFAULT_QUALITY,
public ?bool $strip = null
) {
if ($quality < 0 || $quality > 100) {
throw new InvalidArgumentException('Quality must be in range 0 to 100');
}
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
class BmpEncoder extends SpecializableEncoder
{
public function __construct()
{
//
}
}

View File

@@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Error;
use Intervention\Image\Exceptions\InvalidArgumentException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\FileExtension;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class FileExtensionEncoder extends AutoEncoder
{
/**
* Encoder options.
*
* @var array<int|string, mixed>
*/
protected array $options = [];
/**
* Create new encoder instance to encode to format of given file extension.
*
* @param null|string|FileExtension $extension Target file extension for example "png"
* @throws InvalidArgumentException
* @throws NotSupportedException
*/
public function __construct(public null|string|FileExtension $extension = null, mixed ...$options)
{
if ($extension === '') {
throw new InvalidArgumentException('Unable to find file extension from empty string');
}
$mediaType = null;
if (is_string($extension)) {
try {
$mediaType = FileExtension::from(strtolower($extension))->mediaType();
} catch (Error) {
throw new NotSupportedException(
'Unable to find encoder for unknown file extension "' . $extension . '"',
);
}
}
if ($extension instanceof FileExtension) {
$mediaType = $extension->mediaType();
}
parent::__construct($mediaType, ...$options);
}
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*
* @throws NotSupportedException
* @throws InvalidArgumentException
*/
public function encode(ImageInterface $image): EncodedImageInterface
{
$extension = is_null($this->extension) ? $image->origin()->fileExtension() : $this->extension;
if ($extension === null) {
throw new NotSupportedException('Unable to find encoder by unknown origin file extension');
}
return $image->encode(
$this->encoderByFileExtension(
$extension
)
);
}
/**
* Create matching encoder for given file extension
*
* @throws InvalidArgumentException
* @throws NotSupportedException
*/
protected function encoderByFileExtension(string|FileExtension $extension): EncoderInterface
{
if ($extension === '') {
throw new InvalidArgumentException('Argument $extension must not be an empty string');
}
try {
$extension = is_string($extension) ? FileExtension::from(strtolower($extension)) : $extension;
} catch (Error) {
throw new NotSupportedException(
'Unable to find encoder for unknown image file extension "' . $extension . '"',
);
}
return $extension->format()->encoder(...$this->options);
}
}

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Exceptions\InvalidArgumentException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\EncodedImageInterface;
class FilePathEncoder extends FileExtensionEncoder
{
/**
* Create new encoder instance to encode to format of file extension in given path.
*/
public function __construct(protected ?string $path = null, mixed ...$options)
{
parent::__construct(
is_null($path) ? $path : pathinfo($path, PATHINFO_EXTENSION),
...$options
);
}
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*
* @throws InvalidArgumentException
* @throws NotSupportedException
*/
public function encode(ImageInterface $image): EncodedImageInterface
{
$extension = is_null($this->path) ?
$image->origin()->fileExtension() :
pathinfo($this->path, PATHINFO_EXTENSION);
if ($extension === null || $extension === '') {
throw new InvalidArgumentException(
'Unable to extract file extension from path "' . $this->path . '"',
);
}
return $image->encode(
$this->encoderByFileExtension(
$extension
)
);
}
}

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\AbstractEncoder;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Format;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
class FormatEncoder extends AbstractEncoder
{
/**
* Encoder options.
*
* @var array<int|string, mixed>
*/
protected array $options = [];
/**
* Create new encoder instance to encode to given format.
*/
public function __construct(protected ?Format $format = null, mixed ...$options)
{
$this->options = $options;
}
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*
* @throws NotSupportedException
*/
public function encode(ImageInterface $image): EncodedImageInterface
{
try {
$format = is_null($this->format) ? $image->origin()->format() : $this->format;
} catch (NotSupportedException $e) {
throw new NotSupportedException('Unable to find encoder by unknown origin image format', previous: $e);
}
return $format->encoder(...$this->options)->encode($image);
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
class GifEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*/
public function __construct(public bool $interlaced = false)
{
//
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class HeicEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*
* @param null|bool $strip Strip EXIF metadata
* @throws InvalidArgumentException
*/
public function __construct(
public int $quality = self::DEFAULT_QUALITY,
public ?bool $strip = null
) {
if ($quality < 0 || $quality > 100) {
throw new InvalidArgumentException('Quality must be in range 0 to 100');
}
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
class IcoEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*/
public function __construct()
{
//
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class Jpeg2000Encoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*
* @param null|bool $strip Strip EXIF metadata
* @throws InvalidArgumentException
*/
public function __construct(
public int $quality = self::DEFAULT_QUALITY,
public ?bool $strip = null
) {
if ($quality < 0 || $quality > 100) {
throw new InvalidArgumentException('Quality must be in range 0 to 100');
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class JpegEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*
* @param null|bool $strip Strip EXIF metadata
* @throws InvalidArgumentException
*/
public function __construct(
public int $quality = self::DEFAULT_QUALITY,
public bool $progressive = false,
public ?bool $strip = null
) {
if ($quality < 0 || $quality > 100) {
throw new InvalidArgumentException('Quality must be in range 0 to 100');
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Error;
use Intervention\Image\Drivers\AbstractEncoder;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\MediaType;
class MediaTypeEncoder extends AbstractEncoder
{
/**
* Encoder options.
*
* @var array<int|string, mixed>
*/
protected array $options = [];
/**
* Create new encoder instance.
*
* @param null|string|MediaType $mediaType Target media type for example "image/jpeg"
*/
public function __construct(public null|string|MediaType $mediaType = null, mixed ...$options)
{
$this->options = $options;
}
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*
* @throws NotSupportedException
*/
public function encode(ImageInterface $image): EncodedImageInterface
{
$mediaType = is_null($this->mediaType) ? $image->origin()->mediaType() : $this->mediaType;
return $image->encode(
$this->encoderByMediaType($mediaType)
);
}
/**
* Return new encoder by given media (MIME) type.
*
* @throws NotSupportedException
*/
protected function encoderByMediaType(string|MediaType $mediaType): EncoderInterface
{
try {
$mediaType = is_string($mediaType) ? MediaType::from($mediaType) : $mediaType;
} catch (Error) {
throw new NotSupportedException(
'Unable to find encoder for unknown image media type "' . $mediaType . '"',
);
}
return $mediaType->format()->encoder(...$this->options);
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
class PngEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*/
public function __construct(public bool $interlaced = false, public bool $indexed = false)
{
//
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class TiffEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*
* @param null|bool $strip Strip EXIF metadata
* @throws InvalidArgumentException
*/
public function __construct(
public int $quality = self::DEFAULT_QUALITY,
public ?bool $strip = null
) {
if ($quality < 0 || $quality > 100) {
throw new InvalidArgumentException('Quality must be in range 0 to 100');
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Encoders;
use Intervention\Image\Drivers\SpecializableEncoder;
use Intervention\Image\Exceptions\InvalidArgumentException;
class WebpEncoder extends SpecializableEncoder
{
/**
* Create new encoder object.
*
* @param null|bool $strip Strip EXIF metadata
* @throws InvalidArgumentException
*/
public function __construct(
public int $quality = self::DEFAULT_QUALITY,
public ?bool $strip = null
) {
if ($quality < 0 || $quality > 100) {
throw new InvalidArgumentException('Quality must be in range 0 to 100');
}
}
}