This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ConversionErrorException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Error occurred while converting image: "%s".';
const ERROR_CODE = 'convert_error';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
abstract class ExceptionAbstract extends \Exception implements ExceptionInterface {
/**
* {@inheritdoc}
*/
final public function __construct( $value = [] ) {
$this->code = $this->get_error_status();
parent::__construct( $this->get_error_message( (array) $value ) );
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
interface ExceptionInterface {
/**
* @param mixed[]|string $value Params of exception.
*/
public function __construct( $value = [] );
/**
* Returns message of error.
*
* @param string[] $values Params from class constructor.
*
* @return string Error message.
*/
public function get_error_message( array $values ): string;
/**
* Returns status of error.
*
* @return string Error status.
*/
public function get_error_status(): string;
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ExtensionUnsupportedException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Unsupported extension "%s" for file "%s".';
const ERROR_CODE = 'unsupported_extension';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0], $values[1] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class FilesizeOversizeException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Image is larger than the maximum size of %1$sMB: "%2$s".';
const ERROR_CODE = 'max_filezile';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
$number = (int) $values[0];
return sprintf(
self::ERROR_MESSAGE,
round( $number / 1024 / 1024 ),
$values[1]
);
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class FunctionUnavailableException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Server configuration: "%s" function is not available.';
const ERROR_CODE = 'server_configuration';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ImageAnimatedException extends ExceptionAbstract {
const ERROR_MESSAGE = '"%s" is an unsupported animated image file.';
const ERROR_CODE = 'invalid_animated_image';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ImageInvalidException extends ExceptionAbstract {
const ERROR_MESSAGE = '"%s" is not a valid image file.';
const ERROR_CODE = 'invalid_image';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ImagickNotSupportWebpException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Server configuration: Imagick does not support WebP format.';
const ERROR_CODE = 'server_configuration';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return self::ERROR_MESSAGE;
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ImagickUnavailableException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Server configuration: Imagick module is not available with this PHP installation.';
const ERROR_CODE = 'server_configuration';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return self::ERROR_MESSAGE;
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class LargerThanOriginalException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Image "%1$s" converted to .%2$s is larger than original and converted .%2$s file has been deleted.';
const ERROR_CODE = 'larger_than_original';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf(
self::ERROR_MESSAGE,
$values[0],
pathinfo( $values[1], PATHINFO_EXTENSION )
);
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class OutputPathException extends ExceptionAbstract {
const ERROR_MESSAGE = 'An error occurred creating destination directory for "%s" file.';
const ERROR_CODE = 'output_path';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class RemoteErrorResponseException extends ExceptionAbstract {
const ERROR_MESSAGE = null;
const ERROR_CODE = 'remote_response_error';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return $values[0];
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class RemoteRequestException extends ExceptionAbstract {
const ERROR_MESSAGE = 'There was an error connecting to the API, received a response code of %1$s: "%2$s".';
const ERROR_CODE = 'remote_request_failed';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0], $values[1] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ResolutionOversizeException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Image is larger than maximum 8K resolution: "%s".';
const ERROR_CODE = 'max_resolution';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class ServerConfigurationException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Server configuration: "%s" function is not available.';
const ERROR_CODE = 'server_configuration';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace WebpConverter\Exception;
/**
* {@inheritdoc}
*/
class SourcePathException extends ExceptionAbstract {
const ERROR_MESSAGE = 'Source path "%s" for image does not exist or is unreadable.';
const ERROR_CODE = 'file_unreadable';
/**
* {@inheritdoc}
*/
public function get_error_message( array $values ): string {
return sprintf( self::ERROR_MESSAGE, $values[0] );
}
/**
* {@inheritdoc}
*/
public function get_error_status(): string {
return self::ERROR_CODE;
}
}