From e4c67fef814a88e18f803b8039f929ab0cc46d2d Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Thu, 11 Dec 2025 20:15:55 +0400 Subject: [PATCH 1/4] Remove Translating Exception Messages and refactor Exceptions --- src/App/Enums/ExceptionMessages.php | 44 +++++++++++ src/App/{Constants => Enums}/ReservedKeys.php | 4 +- src/App/Exceptions/AppException.php | 6 +- src/App/Exceptions/BaseException.php | 74 +++++++++++++++++-- src/App/Exceptions/StopExecutionException.php | 7 +- src/Config/Config.php | 4 +- src/Config/Enums/ExceptionMessages.php | 26 +++++++ src/Config/Exceptions/ConfigException.php | 14 +--- src/Di/Enums/ExceptionMessages.php | 35 +++++++++ src/Di/Exceptions/DiException.php | 13 ++-- src/Environment/{Constants => Enums}/Env.php | 4 +- src/Environment/Enums/ExceptionMessages.php | 28 +++++++ src/Environment/Environment.php | 4 +- src/Environment/Exceptions/EnvException.php | 7 +- src/Hook/Enums/ExceptionMessages.php | 28 +++++++ src/Hook/Exceptions/HookException.php | 7 +- src/Http/{Constants => Enums}/ContentType.php | 4 +- src/Http/{Constants => Enums}/StatusCode.php | 4 +- src/Http/Exceptions/HttpException.php | 34 +-------- src/Http/Helpers/http.php | 8 +- src/Http/Request/HttpRequest.php | 5 +- src/Http/Response/HttpResponse.php | 4 +- src/Http/Traits/Request/Body.php | 4 +- src/Http/Traits/Request/Internal.php | 2 +- src/Http/Traits/Request/Params.php | 4 +- src/Http/Traits/Request/RawInput.php | 4 +- src/Http/Traits/Response/Body.php | 6 +- src/Http/Traits/Response/Header.php | 4 +- src/Http/Traits/Response/Status.php | 4 +- .../Archive/Enums/ExceptionMessages.php | 28 +++++++ .../Archive/Exceptions/ArchiveException.php | 7 +- .../Asset/Enums/ExceptionMessages.php | 28 +++++++ .../Asset/Exceptions/AssetException.php | 8 +- .../Auth/Adapters/JwtAuthAdapter.php | 4 +- .../Auth/Adapters/SessionAuthAdapter.php | 4 +- .../Auth/{Constants => Enums}/AuthKeys.php | 2 +- .../Auth/Enums/ExceptionMessages.php | 34 +++++++++ .../Auth/Exceptions/AuthException.php | 21 ++---- src/Libraries/Auth/Factories/AuthFactory.php | 10 ++- src/Libraries/Auth/Traits/AuthTrait.php | 2 +- .../Cache/Adapters/MemcachedAdapter.php | 6 +- .../Cache/Exceptions/CacheException.php | 11 +-- src/Libraries/Cookie/Cookie.php | 6 +- .../Csrf/Enums/ExceptionMessages.php | 28 +++++++ .../Csrf/Exceptions/CsrfException.php | 7 +- .../Database/Adapters/Idiorm/IdiormDbal.php | 5 +- .../Adapters/Idiorm/Statements/Query.php | 25 ++++--- .../Idiorm/Statements/Transaction.php | 15 ++-- .../Database/Adapters/Sleekdb/SleekDbal.php | 6 +- .../Database/Enums/ExceptionMessages.php | 32 ++++++++ .../Database/{Constants => Enums}/Key.php | 4 +- .../Database/{Constants => Enums}/Type.php | 4 +- .../Database/Exceptions/DatabaseException.php | 37 ++-------- src/Libraries/Database/Schemas/Column.php | 4 +- src/Libraries/Database/Schemas/Table.php | 9 +-- src/Libraries/Database/Traits/TableTrait.php | 4 +- .../Adapters/AsymmetricEncryptionAdapter.php | 12 ++- .../Adapters/SymmetricEncryptionAdapter.php | 3 + .../Encryption/Enums/ExceptionMessages.php | 32 ++++++++ .../Exceptions/CryptorException.php | 24 ++---- .../Hasher/Enums/ExceptionMessages.php | 32 ++++++++ .../Hasher/Exceptions/HasherException.php | 7 +- .../HttpClient/Enums/ExceptionMessages.php | 26 +++++++ .../Exceptions/HttpClientException.php | 13 +--- src/Libraries/HttpClient/HttpClient.php | 6 +- src/Libraries/Jwt/Enums/ExceptionMessages.php | 26 +++++++ src/Libraries/Jwt/Exceptions/JwtException.php | 6 +- .../Lang/Enums/ExceptionMessages.php | 28 +++++++ .../Lang/Exceptions/LangException.php | 5 +- .../Logger/Enums/ExceptionMessages.php | 28 +++++++ .../Logger/Exceptions/LoggerException.php | 16 +--- .../Logger/Factories/LoggerFactory.php | 2 +- .../Mailer/Exceptions/MailerException.php | 10 +-- .../ResourceCache/Enums/ExceptionMessages.php | 26 +++++++ .../Exceptions/ResourceCacheException.php | 36 +++++++++ src/Libraries/ResourceCache/ViewCache.php | 10 ++- .../Session/Enums/ExceptionMessages.php | 28 +++++++ .../Session/Exceptions/SessionException.php | 15 +--- .../Storage/Enums/ExceptionMessages.php | 32 ++++++++ .../Exceptions/FileSystemException.php | 20 ++--- .../Exceptions/FileUploadException.php | 5 +- .../Storage/Factories/FileSystemFactory.php | 16 ++-- src/Libraries/Storage/UploadedFile.php | 2 +- src/Middleware/Enums/ExceptionMessages.php | 26 +++++++ .../Exceptions/MiddlewareException.php | 3 +- src/Migration/Enums/ExceptionMessages.php | 30 ++++++++ .../Exceptions/MigrationException.php | 27 ++----- src/Migration/MigrationTable.php | 4 +- src/Model/Enums/ExceptionMessages.php | 28 +++++++ src/Model/Exceptions/ModelException.php | 42 +---------- src/Model/Factories/ModelFactory.php | 8 +- src/Model/QtModel.php | 10 +-- src/Module/Enums/ExceptionMessages.php | 36 +++++++++ src/Module/Exceptions/ModuleException.php | 17 +++-- .../src/Controllers/AuthController.php.tpl | 2 +- .../src/Controllers/PostController.php.tpl | 2 +- .../DemoApi/src/Middlewares/Auth.php.tpl | 2 +- .../src/Middlewares/BaseMiddleware.php.tpl | 2 +- .../DemoApi/src/Middlewares/Editor.php.tpl | 2 +- .../src/Controllers/PostController.php.tpl | 2 +- .../DemoWeb/src/Middlewares/Activate.php.tpl | 2 +- .../DemoWeb/src/Middlewares/PostOwner.php.tpl | 2 +- .../DemoWeb/src/Middlewares/Reset.php.tpl | 2 +- .../DemoWeb/src/Middlewares/Verify.php.tpl | 2 +- src/Paginator/Enums/ExceptionMessages.php | 26 +++++++ .../{Constants => Enums}/Pagination.php | 4 +- .../Exceptions/PaginatorException.php | 16 ++-- src/Paginator/Factories/PaginatorFactory.php | 4 +- src/Paginator/Traits/PaginatorTrait.php | 4 +- src/Router/Enums/ExceptionMessages.php | 48 ++++++++++++ .../Exceptions/RouteControllerException.php | 5 +- src/Router/Exceptions/RouteException.php | 25 ++++--- src/Router/Router.php | 4 +- src/Service/Exceptions/ServiceException.php | 27 +------ src/Service/Factories/ServiceFactory.php | 12 ++- src/Service/QtService.php | 7 +- src/View/Enums/ExceptionMessages.php | 28 +++++++ src/View/Exceptions/ViewException.php | 15 +--- 118 files changed, 1208 insertions(+), 477 deletions(-) create mode 100644 src/App/Enums/ExceptionMessages.php rename src/App/{Constants => Enums}/ReservedKeys.php (92%) create mode 100644 src/Config/Enums/ExceptionMessages.php create mode 100644 src/Di/Enums/ExceptionMessages.php rename src/Environment/{Constants => Enums}/Env.php (94%) create mode 100644 src/Environment/Enums/ExceptionMessages.php create mode 100644 src/Hook/Enums/ExceptionMessages.php rename src/Http/{Constants => Enums}/ContentType.php (95%) rename src/Http/{Constants => Enums}/StatusCode.php (98%) create mode 100644 src/Libraries/Archive/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Asset/Enums/ExceptionMessages.php rename src/Libraries/Auth/{Constants => Enums}/AuthKeys.php (96%) create mode 100644 src/Libraries/Auth/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Csrf/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Database/Enums/ExceptionMessages.php rename src/Libraries/Database/{Constants => Enums}/Key.php (92%) rename src/Libraries/Database/{Constants => Enums}/Type.php (95%) create mode 100644 src/Libraries/Encryption/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Hasher/Enums/ExceptionMessages.php create mode 100644 src/Libraries/HttpClient/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Jwt/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Lang/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Logger/Enums/ExceptionMessages.php create mode 100644 src/Libraries/ResourceCache/Enums/ExceptionMessages.php create mode 100644 src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php create mode 100644 src/Libraries/Session/Enums/ExceptionMessages.php create mode 100644 src/Libraries/Storage/Enums/ExceptionMessages.php create mode 100644 src/Middleware/Enums/ExceptionMessages.php create mode 100644 src/Migration/Enums/ExceptionMessages.php create mode 100644 src/Model/Enums/ExceptionMessages.php create mode 100644 src/Module/Enums/ExceptionMessages.php create mode 100644 src/Paginator/Enums/ExceptionMessages.php rename src/Paginator/{Constants => Enums}/Pagination.php (94%) create mode 100644 src/Router/Enums/ExceptionMessages.php create mode 100644 src/View/Enums/ExceptionMessages.php diff --git a/src/App/Enums/ExceptionMessages.php b/src/App/Enums/ExceptionMessages.php new file mode 100644 index 000000000..b3705bf06 --- /dev/null +++ b/src/App/Enums/ExceptionMessages.php @@ -0,0 +1,44 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\App\Enums; + +/** + * Class ExceptionMessages + * @package Quantum\App + */ +class ExceptionMessages +{ + const APP_KEY_MISSING = 'APP KEY is missing.'; + + const EXECUTION_TERMINATED = 'Execution was terminated.'; + + const METHOD_NOT_SUPPORTED = 'The method `{%1}` is not supported for `{%2}`.'; + + const ADAPTER_NOT_SUPPORTED = 'The adapter `{%1}` is not supported.'; + + const DRIVER_NOT_SUPPORTED = 'The driver `{%1}` is not supported.'; + + const FILE_NOT_FOUND = 'The file `{%1}` not found.'; + + const NOT_FOUND = '{%1} `{%2}` not found.'; + + const NOT_INSTANCE_OF = 'The `{%1}` is not instance of `{%2}`.'; + + const CANT_CONNECT = 'Can not connect to `{%1}`.'; + + const MISSING_CONFIG = 'Could not load config `{%1}` properly.'; + + const UNAVAILABLE_REQUEST_METHOD = 'Provided request method `{%1}` is not available.'; +} \ No newline at end of file diff --git a/src/App/Constants/ReservedKeys.php b/src/App/Enums/ReservedKeys.php similarity index 92% rename from src/App/Constants/ReservedKeys.php rename to src/App/Enums/ReservedKeys.php index 241326424..4e4e813b4 100644 --- a/src/App/Constants/ReservedKeys.php +++ b/src/App/Enums/ReservedKeys.php @@ -9,10 +9,10 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ -namespace Quantum\App\Constants; +namespace Quantum\App\Enums; /** * Class ReservedKeys diff --git a/src/App/Exceptions/AppException.php b/src/App/Exceptions/AppException.php index abeeaf84a..9fb05e1da 100644 --- a/src/App/Exceptions/AppException.php +++ b/src/App/Exceptions/AppException.php @@ -9,11 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\App\Exceptions; +use Quantum\App\Enums\ExceptionMessages; + /** * Class AppException * @package Quantum\App @@ -26,6 +28,6 @@ class AppException extends BaseException */ public static function missingAppKey(): AppException { - return new static(t('exception.app_key_missing'), E_ERROR); + return new static(ExceptionMessages::APP_KEY_MISSING, E_ERROR); } } diff --git a/src/App/Exceptions/BaseException.php b/src/App/Exceptions/BaseException.php index 2db295189..f5a40df11 100644 --- a/src/App/Exceptions/BaseException.php +++ b/src/App/Exceptions/BaseException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\App\Exceptions; +use Quantum\App\Enums\ExceptionMessages; use Exception; /** @@ -31,7 +32,7 @@ class BaseException extends Exception public static function methodNotSupported(string $methodName, string $className): self { return new static( - "The method `$methodName` is not supported for `$className`", + _message(ExceptionMessages::METHOD_NOT_SUPPORTED, [$methodName, $className]), E_WARNING ); } @@ -43,7 +44,7 @@ public static function methodNotSupported(string $methodName, string $className) public static function adapterNotSupported(string $name): self { return new static( - "The adapter `$name` is not supported`", + _message(ExceptionMessages::ADAPTER_NOT_SUPPORTED, [$name]), E_ERROR ); } @@ -55,7 +56,7 @@ public static function adapterNotSupported(string $name): self public static function driverNotSupported(string $name): self { return new static( - "The driver `$name` is not supported", + _message(ExceptionMessages::DRIVER_NOT_SUPPORTED, [$name]), E_ERROR ); } @@ -67,8 +68,71 @@ public static function driverNotSupported(string $name): self public static function fileNotFound(string $name): self { return new static( - "The file `$name` not found", + _message(ExceptionMessages::FILE_NOT_FOUND, [$name]), E_ERROR ); } + + /** + * @param string $subject + * @param string $name + * @return self + */ + public static function notFound(string $subject, string $name): self + { + return new static( + _message(ExceptionMessages::NOT_FOUND, [$subject, $name]), + E_ERROR + ); + } + + /** + * @param string $instance + * @param string $name + * @return self + */ + public static function notInstanceOf(string $instance, string $name): self + { + return new static( + _message(ExceptionMessages::NOT_INSTANCE_OF, [$instance, $name]), + E_ERROR + ); + } + + /** + * @param string $name + * @return self + */ + public static function cantConnect(string $name): self + { + return new static( + _message(ExceptionMessages::CANT_CONNECT, [$name]), + E_ERROR + ); + } + + /** + * @param string $name + * @return self + */ + + public static function missingConfig(string $name): self + { + return new static( + _message(ExceptionMessages::MISSING_CONFIG, $name), + E_ERROR + ); + } + + /** + * @param string $name + * @return self + */ + public static function requestMethodNotAvailable(string $name): self + { + return new static( + _message(ExceptionMessages::UNAVAILABLE_REQUEST_METHOD, [$name]), + E_WARNING + ); + } } \ No newline at end of file diff --git a/src/App/Exceptions/StopExecutionException.php b/src/App/Exceptions/StopExecutionException.php index 23679ab68..8980ddb7c 100644 --- a/src/App/Exceptions/StopExecutionException.php +++ b/src/App/Exceptions/StopExecutionException.php @@ -9,23 +9,26 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\App\Exceptions; +use Quantum\App\Enums\ExceptionMessages; + /** * Class StopExecutionException * @package Quantum\App */ class StopExecutionException extends BaseException { + /** * @param int|null $code * @return StopExecutionException */ public static function executionTerminated(?int $code): StopExecutionException { - return new static(t('exception.execution_terminated'), $code); + return new static(ExceptionMessages::EXECUTION_TERMINATED, $code); } } \ No newline at end of file diff --git a/src/Config/Config.php b/src/Config/Config.php index 8d14577ee..40482293e 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Config; @@ -25,7 +25,7 @@ /** * Class Config - * @package Quantum\Libraries\Config + * @package Quantum\Config */ class Config implements StorageInterface { diff --git a/src/Config/Enums/ExceptionMessages.php b/src/Config/Enums/ExceptionMessages.php new file mode 100644 index 000000000..fdbc36117 --- /dev/null +++ b/src/Config/Enums/ExceptionMessages.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Config\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Config + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const CONFIG_COLLISION = 'Config key `{%1}` is already in use'; +} \ No newline at end of file diff --git a/src/Config/Exceptions/ConfigException.php b/src/Config/Exceptions/ConfigException.php index d7b9ca4f7..14a4e732f 100644 --- a/src/Config/Exceptions/ConfigException.php +++ b/src/Config/Exceptions/ConfigException.php @@ -9,26 +9,20 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Config\Exceptions; +use Quantum\Config\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** * Class ConfigException - * @package Quantum\Libraries\Config + * @package Quantum\Config */ class ConfigException extends BaseException { - /** - * @return ConfigException - */ - public static function configAlreadyLoaded(): ConfigException - { - return new static(t('exception.config_already_loaded'), E_WARNING); - } /** * @param string $name @@ -36,6 +30,6 @@ public static function configAlreadyLoaded(): ConfigException */ public static function configCollision(string $name): ConfigException { - return new static('Config key `' . $name . '` is already in use', E_WARNING); + return new static(_message(ExceptionMessages::CONFIG_COLLISION, [$name]), E_WARNING); } } \ No newline at end of file diff --git a/src/Di/Enums/ExceptionMessages.php b/src/Di/Enums/ExceptionMessages.php new file mode 100644 index 000000000..22bb5361d --- /dev/null +++ b/src/Di/Enums/ExceptionMessages.php @@ -0,0 +1,35 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Di\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Di + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + + const DEPENDENCY_NOT_REGISTERED = 'The dependency `{%1}` is not registered.'; + + const DEPENDENCY_ALREADY_REGISTERED = 'The dependency `{%1}` is already registered.'; + + const DEPENDENCY_NOT_INSTANTIABLE = 'The dependency `{%1}` is not instantiable.'; + + const INVALID_ABSTRACT_DEPENDENCY = 'The dependency `{%1}` is not valid abstract class.'; + + const CIRCULAR_DEPENDENCY = 'Circular dependency detected: `{%1}`'; +} \ No newline at end of file diff --git a/src/Di/Exceptions/DiException.php b/src/Di/Exceptions/DiException.php index 56a88b003..3f9751e44 100644 --- a/src/Di/Exceptions/DiException.php +++ b/src/Di/Exceptions/DiException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Di\Exceptions; +use Quantum\Di\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -28,7 +29,7 @@ class DiException extends BaseException */ public static function dependencyNotRegistered(string $name): DiException { - return new self(t('exception.dependency_not_registered', $name), E_ERROR); + return new self(_message(ExceptionMessages::DEPENDENCY_NOT_REGISTERED, [$name]), E_ERROR); } /** @@ -37,7 +38,7 @@ public static function dependencyNotRegistered(string $name): DiException */ public static function dependencyAlreadyRegistered(string $name): DiException { - return new self(t('exception.dependency_already_registered', $name), E_ERROR); + return new self(_message(ExceptionMessages::DEPENDENCY_ALREADY_REGISTERED, $name), E_ERROR); } /** @@ -46,7 +47,7 @@ public static function dependencyAlreadyRegistered(string $name): DiException */ public static function dependencyNotInstantiable(string $name): DiException { - return new self(t('exception.dependency_not_instantiable', $name), E_ERROR); + return new self(_message(ExceptionMessages::DEPENDENCY_NOT_INSTANTIABLE, $name), E_ERROR); } /** @@ -55,7 +56,7 @@ public static function dependencyNotInstantiable(string $name): DiException */ public static function invalidAbstractDependency(string $name): DiException { - return new self(t('exception.invalid_abstract_dependency', $name), E_ERROR); + return new self(_message(ExceptionMessages::INVALID_ABSTRACT_DEPENDENCY, $name), E_ERROR); } /** @@ -64,6 +65,6 @@ public static function invalidAbstractDependency(string $name): DiException */ public static function circularDependency(string $chain): DiException { - return new self("Circular dependency detected: $chain", 0); + return new self(_message(ExceptionMessages::CIRCULAR_DEPENDENCY, [$chain]), 0); } } diff --git a/src/Environment/Constants/Env.php b/src/Environment/Enums/Env.php similarity index 94% rename from src/Environment/Constants/Env.php rename to src/Environment/Enums/Env.php index a58b85302..913415405 100644 --- a/src/Environment/Constants/Env.php +++ b/src/Environment/Enums/Env.php @@ -9,10 +9,10 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ -namespace Quantum\Environment\Constants; +namespace Quantum\Environment\Enums; /** * Class Env diff --git a/src/Environment/Enums/ExceptionMessages.php b/src/Environment/Enums/ExceptionMessages.php new file mode 100644 index 000000000..43d2b45e9 --- /dev/null +++ b/src/Environment/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Environment\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Environment + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const IMMUTABLE_ENVIRONMENT = 'The environment is immutable. Modifications are not allowed.'; + + const ENVIRONMENT_NOT_LOADED = 'Environment not loaded. Call `load()` method first.'; +} \ No newline at end of file diff --git a/src/Environment/Environment.php b/src/Environment/Environment.php index 08cc19011..d52449c9e 100644 --- a/src/Environment/Environment.php +++ b/src/Environment/Environment.php @@ -9,15 +9,15 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Environment; use Quantum\Environment\Exceptions\EnvException; use Quantum\App\Exceptions\BaseException; -use Quantum\Environment\Constants\Env; use Quantum\Di\Exceptions\DiException; +use Quantum\Environment\Enums\Env; use Quantum\Loader\Loader; use Quantum\Loader\Setup; use ReflectionException; diff --git a/src/Environment/Exceptions/EnvException.php b/src/Environment/Exceptions/EnvException.php index 2747dc164..eb1cb9111 100644 --- a/src/Environment/Exceptions/EnvException.php +++ b/src/Environment/Exceptions/EnvException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Environment\Exceptions; +use Quantum\Environment\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -28,7 +29,7 @@ class EnvException extends BaseException */ public static function environmentImmutable(): EnvException { - return new static(t('exception.immutable_environment'), E_ERROR); + return new static(ExceptionMessages::IMMUTABLE_ENVIRONMENT, E_ERROR); } /** @@ -36,6 +37,6 @@ public static function environmentImmutable(): EnvException */ public static function environmentNotLoaded(): EnvException { - return new static(t('exception.environment_not_loaded'), E_ERROR); + return new static(ExceptionMessages::ENVIRONMENT_NOT_LOADED, E_ERROR); } } diff --git a/src/Hook/Enums/ExceptionMessages.php b/src/Hook/Enums/ExceptionMessages.php new file mode 100644 index 000000000..72c6ee17a --- /dev/null +++ b/src/Hook/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Hook\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Hook + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const DUPLICATE_HOOK_NAME = 'The Hook `{%1}` already registered.'; + + const UNREGISTERED_HOOK_NAME = 'The Hook `{%1}` was not registered.'; +} \ No newline at end of file diff --git a/src/Hook/Exceptions/HookException.php b/src/Hook/Exceptions/HookException.php index a37a85b21..defbf5599 100644 --- a/src/Hook/Exceptions/HookException.php +++ b/src/Hook/Exceptions/HookException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Hook\Exceptions; +use Quantum\Hook\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -28,7 +29,7 @@ class HookException extends BaseException */ public static function hookDuplicateName(string $name): HookException { - return new static(t('exception.duplicate_hook_name', $name), E_ERROR); + return new static(_message(ExceptionMessages::DUPLICATE_HOOK_NAME, [$name]), E_ERROR); } /** @@ -37,6 +38,6 @@ public static function hookDuplicateName(string $name): HookException */ public static function unregisteredHookName(string $name): HookException { - return new static(t('exception.unregistered_hook_name', $name), E_WARNING); + return new static(_message(ExceptionMessages::UNREGISTERED_HOOK_NAME, [$name]), E_WARNING); } } \ No newline at end of file diff --git a/src/Http/Constants/ContentType.php b/src/Http/Enums/ContentType.php similarity index 95% rename from src/Http/Constants/ContentType.php rename to src/Http/Enums/ContentType.php index 1e1403c1f..eb34c898d 100644 --- a/src/Http/Constants/ContentType.php +++ b/src/Http/Enums/ContentType.php @@ -9,10 +9,10 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ -namespace Quantum\Http\Constants; +namespace Quantum\Http\Enums; /** * Class ContentType diff --git a/src/Http/Constants/StatusCode.php b/src/Http/Enums/StatusCode.php similarity index 98% rename from src/Http/Constants/StatusCode.php rename to src/Http/Enums/StatusCode.php index dbea8399d..a539ee8c7 100644 --- a/src/Http/Constants/StatusCode.php +++ b/src/Http/Enums/StatusCode.php @@ -9,10 +9,10 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ -namespace Quantum\Http\Constants; +namespace Quantum\Http\Enums; /** * Class StatusCode diff --git a/src/Http/Exceptions/HttpException.php b/src/Http/Exceptions/HttpException.php index 0c66217ca..99e8a1017 100644 --- a/src/Http/Exceptions/HttpException.php +++ b/src/Http/Exceptions/HttpException.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Exceptions; @@ -22,37 +22,5 @@ */ class HttpException extends BaseException { - /** - * @return HttpException - */ - public static function unexpectedRequestInitialization(): HttpException - { - return new static(t('exception.unexpected_request_initialization'), E_WARNING); - } - - /** - * @return HttpException - */ - public static function unexpectedResponseInitialization(): HttpException - { - return new static(t('exception.unexpected_response_initialization'), E_WARNING); - } - - /** - * @param string $name - * @return HttpException - */ - public static function methodNotAvailable(string $name): HttpException - { - return new static(t('exception.method_not_available', $name), E_WARNING); - } - - /** - * @return static - */ - public static function contentTypeNotSupported(): HttpException - { - return new static(t('exception.not_supported_content_type'), E_WARNING); - } } diff --git a/src/Http/Helpers/http.php b/src/Http/Helpers/http.php index 35436d4bd..9ca108c48 100644 --- a/src/Http/Helpers/http.php +++ b/src/Http/Helpers/http.php @@ -9,15 +9,15 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ use Quantum\Config\Exceptions\ConfigException; use Quantum\App\Exceptions\BaseException; -use Quantum\Http\Constants\ContentType; -use Quantum\App\Constants\ReservedKeys; use Quantum\Di\Exceptions\DiException; -use Quantum\Http\Constants\StatusCode; +use Quantum\App\Enums\ReservedKeys; +use Quantum\Http\Enums\ContentType; +use Quantum\Http\Enums\StatusCode; use DebugBar\DebugBarException; use Quantum\Http\Response; use Quantum\Http\Request; diff --git a/src/Http/Request/HttpRequest.php b/src/Http/Request/HttpRequest.php index 6da60fdf2..7da6d48b8 100644 --- a/src/Http/Request/HttpRequest.php +++ b/src/Http/Request/HttpRequest.php @@ -166,12 +166,13 @@ public static function getMethod(): ?string /** * Sets the request method * @param string $method - * @throws HttpException + * @return void + * @throws BaseException */ public static function setMethod(string $method) { if (!in_array(strtoupper($method), self::METHODS)) { - throw HttpException::methodNotAvailable($method); + throw HttpException::requestMethodNotAvailable($method); } self::$__method = $method; diff --git a/src/Http/Response/HttpResponse.php b/src/Http/Response/HttpResponse.php index 08606fd6d..2f5118702 100644 --- a/src/Http/Response/HttpResponse.php +++ b/src/Http/Response/HttpResponse.php @@ -16,10 +16,10 @@ use Quantum\Http\Traits\Response\Header; use Quantum\Http\Traits\Response\Status; -use Quantum\Environment\Constants\Env; -use Quantum\Http\Constants\StatusCode; use Quantum\Http\Traits\Response\Body; use Quantum\Environment\Environment; +use Quantum\Environment\Enums\Env; +use Quantum\Http\Enums\StatusCode; use Exception; /** diff --git a/src/Http/Traits/Request/Body.php b/src/Http/Traits/Request/Body.php index 15e581fae..ac82720d9 100644 --- a/src/Http/Traits/Request/Body.php +++ b/src/Http/Traits/Request/Body.php @@ -9,12 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Traits\Request; -use Quantum\App\Constants\ReservedKeys; +use Quantum\App\Enums\ReservedKeys; use InvalidArgumentException; /** diff --git a/src/Http/Traits/Request/Internal.php b/src/Http/Traits/Request/Internal.php index c937ce3ce..7108dd7b4 100644 --- a/src/Http/Traits/Request/Internal.php +++ b/src/Http/Traits/Request/Internal.php @@ -16,8 +16,8 @@ use Quantum\Config\Exceptions\ConfigException; use Quantum\App\Exceptions\BaseException; -use Quantum\Http\Constants\ContentType; use Quantum\Di\Exceptions\DiException; +use Quantum\Http\Enums\ContentType; use Quantum\Environment\Server; use ReflectionException; diff --git a/src/Http/Traits/Request/Params.php b/src/Http/Traits/Request/Params.php index 36627eb69..98b1b22ec 100644 --- a/src/Http/Traits/Request/Params.php +++ b/src/Http/Traits/Request/Params.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Traits\Request; @@ -17,8 +17,8 @@ use Quantum\Config\Exceptions\ConfigException; use Quantum\App\Exceptions\BaseException; -use Quantum\Http\Constants\ContentType; use Quantum\Di\Exceptions\DiException; +use Quantum\Http\Enums\ContentType; use ReflectionException; /** diff --git a/src/Http/Traits/Request/RawInput.php b/src/Http/Traits/Request/RawInput.php index 419ca047e..67f3ffd19 100644 --- a/src/Http/Traits/Request/RawInput.php +++ b/src/Http/Traits/Request/RawInput.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Traits\Request; @@ -18,8 +18,8 @@ use Quantum\Config\Exceptions\ConfigException; use Quantum\Libraries\Storage\UploadedFile; use Quantum\App\Exceptions\BaseException; -use Quantum\Http\Constants\ContentType; use Quantum\Di\Exceptions\DiException; +use Quantum\Http\Enums\ContentType; use Quantum\Environment\Server; use ReflectionException; diff --git a/src/Http/Traits/Response/Body.php b/src/Http/Traits/Response/Body.php index 42bf987a3..0f1a7e10b 100644 --- a/src/Http/Traits/Response/Body.php +++ b/src/Http/Traits/Response/Body.php @@ -9,14 +9,14 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Traits\Response; use Quantum\Http\Exceptions\HttpException; -use Quantum\App\Constants\ReservedKeys; -use Quantum\Http\Constants\ContentType; +use Quantum\App\Enums\ReservedKeys; +use Quantum\Http\Enums\ContentType; use SimpleXMLElement; use DOMDocument; use Exception; diff --git a/src/Http/Traits/Response/Header.php b/src/Http/Traits/Response/Header.php index 3b60c6a25..da4408975 100644 --- a/src/Http/Traits/Response/Header.php +++ b/src/Http/Traits/Response/Header.php @@ -9,13 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Traits\Response; use Quantum\App\Exceptions\StopExecutionException; -use Quantum\Http\Constants\ContentType; +use Quantum\Http\Enums\ContentType; /** * Trait Header diff --git a/src/Http/Traits/Response/Status.php b/src/Http/Traits/Response/Status.php index c649de56f..349b43af2 100644 --- a/src/Http/Traits/Response/Status.php +++ b/src/Http/Traits/Response/Status.php @@ -9,12 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Traits\Response; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use InvalidArgumentException; /** diff --git a/src/Libraries/Archive/Enums/ExceptionMessages.php b/src/Libraries/Archive/Enums/ExceptionMessages.php new file mode 100644 index 000000000..74ffd52bb --- /dev/null +++ b/src/Libraries/Archive/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Archive\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Archive + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const CANT_OPEN = 'The archive `{%1}` can not be opened'; + + const NAME_NOT_SET = 'Archive name is not set'; +} \ No newline at end of file diff --git a/src/Libraries/Archive/Exceptions/ArchiveException.php b/src/Libraries/Archive/Exceptions/ArchiveException.php index caae8f7b3..b605d8d71 100644 --- a/src/Libraries/Archive/Exceptions/ArchiveException.php +++ b/src/Libraries/Archive/Exceptions/ArchiveException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Archive\Exceptions; +use Quantum\Libraries\Archive\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -28,7 +29,7 @@ class ArchiveException extends BaseException */ public static function cantOpen(string $name): ArchiveException { - return new static(t('exception.cant_open', $name), E_WARNING); + return new static(_message(ExceptionMessages::CANT_OPEN, $name), E_WARNING); } /** @@ -36,6 +37,6 @@ public static function cantOpen(string $name): ArchiveException */ public static function missingArchiveName(): ArchiveException { - return new static(t('exception.name_not_set'), E_WARNING); + return new static(ExceptionMessages::NAME_NOT_SET, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Asset/Enums/ExceptionMessages.php b/src/Libraries/Asset/Enums/ExceptionMessages.php new file mode 100644 index 000000000..3fabe56f5 --- /dev/null +++ b/src/Libraries/Asset/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Asset\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Asset + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const POSITION_IN_USE = 'Position `{%1}` for asset `{%2}` is in use'; + + const NAME_IN_USE = 'The name {%1} is in use'; +} \ No newline at end of file diff --git a/src/Libraries/Asset/Exceptions/AssetException.php b/src/Libraries/Asset/Exceptions/AssetException.php index 9c1e6eb4e..d59fc4f2a 100644 --- a/src/Libraries/Asset/Exceptions/AssetException.php +++ b/src/Libraries/Asset/Exceptions/AssetException.php @@ -9,11 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Asset\Exceptions; +use Quantum\Libraries\Asset\Enums\ExceptionMessages; + /** * Class AssetException * @package Quantum\Libraries\Asset @@ -27,7 +29,7 @@ class AssetException extends \Exception */ public static function positionInUse(string $position, string $name): AssetException { - return new self(t('exception.position_in_use', [$position, $name]), E_WARNING); + return new self(_message(ExceptionMessages::POSITION_IN_USE, [$position, $name]), E_WARNING); } /** @@ -36,6 +38,6 @@ public static function positionInUse(string $position, string $name): AssetExcep */ public static function nameInUse(?string $name): AssetException { - return new self(t('exception.name_in_use', [$name]), E_WARNING); + return new self(_message(ExceptionMessages::NAME_IN_USE, [$name]), E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Auth/Adapters/JwtAuthAdapter.php b/src/Libraries/Auth/Adapters/JwtAuthAdapter.php index 30f331ac4..e6e2954b8 100644 --- a/src/Libraries/Auth/Adapters/JwtAuthAdapter.php +++ b/src/Libraries/Auth/Adapters/JwtAuthAdapter.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.6 + * @since 2.9.9 */ namespace Quantum\Libraries\Auth\Adapters; @@ -18,8 +18,8 @@ use Quantum\Libraries\Auth\Contracts\AuthServiceInterface; use Quantum\Libraries\Auth\Exceptions\AuthException; use Quantum\Libraries\Jwt\Exceptions\JwtException; -use Quantum\Libraries\Auth\Constants\AuthKeys; use Quantum\Libraries\Auth\Traits\AuthTrait; +use Quantum\Libraries\Auth\Enums\AuthKeys; use Quantum\Libraries\Mailer\Mailer; use Quantum\Libraries\Hasher\Hasher; use Quantum\Libraries\Jwt\JwtToken; diff --git a/src/Libraries/Auth/Adapters/SessionAuthAdapter.php b/src/Libraries/Auth/Adapters/SessionAuthAdapter.php index 5fd9cfefb..6bf2638ce 100644 --- a/src/Libraries/Auth/Adapters/SessionAuthAdapter.php +++ b/src/Libraries/Auth/Adapters/SessionAuthAdapter.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Auth\Adapters; @@ -20,8 +20,8 @@ use Quantum\Libraries\Session\Exceptions\SessionException; use Quantum\Libraries\Auth\Exceptions\AuthException; use Quantum\Config\Exceptions\ConfigException; -use Quantum\Libraries\Auth\Constants\AuthKeys; use Quantum\Libraries\Auth\Traits\AuthTrait; +use Quantum\Libraries\Auth\Enums\AuthKeys; use Quantum\App\Exceptions\BaseException; use Quantum\Di\Exceptions\DiException; use Quantum\Libraries\Hasher\Hasher; diff --git a/src/Libraries/Auth/Constants/AuthKeys.php b/src/Libraries/Auth/Enums/AuthKeys.php similarity index 96% rename from src/Libraries/Auth/Constants/AuthKeys.php rename to src/Libraries/Auth/Enums/AuthKeys.php index 06db8950c..c4df5a2ed 100644 --- a/src/Libraries/Auth/Constants/AuthKeys.php +++ b/src/Libraries/Auth/Enums/AuthKeys.php @@ -12,7 +12,7 @@ * @since 2.9.5 */ -namespace Quantum\Libraries\Auth\Constants; +namespace Quantum\Libraries\Auth\Enums; /** * Class AuthKeys diff --git a/src/Libraries/Auth/Enums/ExceptionMessages.php b/src/Libraries/Auth/Enums/ExceptionMessages.php new file mode 100644 index 000000000..b4e4af7c5 --- /dev/null +++ b/src/Libraries/Auth/Enums/ExceptionMessages.php @@ -0,0 +1,34 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Auth\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Auth + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const INCORRECT_USER_SCHEMA = 'User schema does not contains all key fields.'; + + const VERIFICATION_CODE_EXPIRED = 'Verification code expired.'; + + const INCORRECT_VERIFICATION_CODE = 'Incorrect verification code.'; + + const INACTIVE_ACCOUNT = 'The account is not activated.'; + + const INCORRECT_CREDENTIALS = 'Incorrect credentials.'; +} \ No newline at end of file diff --git a/src/Libraries/Auth/Exceptions/AuthException.php b/src/Libraries/Auth/Exceptions/AuthException.php index 859e10043..059a0caa7 100644 --- a/src/Libraries/Auth/Exceptions/AuthException.php +++ b/src/Libraries/Auth/Exceptions/AuthException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Auth\Exceptions; +use Quantum\Libraries\Auth\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -27,7 +28,7 @@ class AuthException extends BaseException */ public static function incorrectCredentials(): AuthException { - return new static(t('exception.incorrect_auth_credentials')); + return new static(ExceptionMessages::INCORRECT_CREDENTIALS, E_ERROR); } /** @@ -35,7 +36,7 @@ public static function incorrectCredentials(): AuthException */ public static function inactiveAccount(): AuthException { - return new static(t('exception.inactive_account')); + return new static(ExceptionMessages::INACTIVE_ACCOUNT); } /** @@ -43,7 +44,7 @@ public static function inactiveAccount(): AuthException */ public static function incorrectVerificationCode(): AuthException { - return new static(t('exception.incorrect_verification_code')); + return new static(ExceptionMessages::INCORRECT_VERIFICATION_CODE, E_ERROR); } /** @@ -51,7 +52,7 @@ public static function incorrectVerificationCode(): AuthException */ public static function verificationCodeExpired(): AuthException { - return new static(t('exception.verification_code_expired')); + return new static(ExceptionMessages::VERIFICATION_CODE_EXPIRED, E_ERROR); } /** @@ -59,14 +60,6 @@ public static function verificationCodeExpired(): AuthException */ public static function incorrectUserSchema(): AuthException { - return new static(t('exception.incorrect_user_schema')); - } - - /** - * @return AuthException - */ - public static function incorrectAuthService(): AuthException - { - return new static(t('exception.incorrect_auth_service')); + return new static(ExceptionMessages::INCORRECT_USER_SCHEMA, E_ERROR); } } \ No newline at end of file diff --git a/src/Libraries/Auth/Factories/AuthFactory.php b/src/Libraries/Auth/Factories/AuthFactory.php index 1646bf5df..5f156cac0 100644 --- a/src/Libraries/Auth/Factories/AuthFactory.php +++ b/src/Libraries/Auth/Factories/AuthFactory.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Auth\Factories; @@ -114,17 +114,19 @@ private static function getAdapterClass(string $adapter): string /** * @param string $adapter * @return AuthServiceInterface - * @throws AuthException + * @throws BaseException * @throws DiException * @throws ReflectionException * @throws ServiceException */ private static function createAuthService(string $adapter): AuthServiceInterface { - $authService = ServiceFactory::create(config()->get('auth.' . $adapter . '.service')); + $authServiceClass = config()->get('auth.' . $adapter . '.service'); + + $authService = ServiceFactory::create($authServiceClass); if (!$authService instanceof AuthServiceInterface) { - throw AuthException::incorrectAuthService(); + throw AuthException::notInstanceOf($authServiceClass, AuthServiceInterface::class); } return $authService; diff --git a/src/Libraries/Auth/Traits/AuthTrait.php b/src/Libraries/Auth/Traits/AuthTrait.php index 6e9701598..29a372cea 100644 --- a/src/Libraries/Auth/Traits/AuthTrait.php +++ b/src/Libraries/Auth/Traits/AuthTrait.php @@ -19,7 +19,7 @@ use Quantum\Libraries\Auth\Exceptions\AuthException; use Quantum\Libraries\Jwt\Exceptions\JwtException; use Quantum\Config\Exceptions\ConfigException; -use Quantum\Libraries\Auth\Constants\AuthKeys; +use Quantum\Libraries\Auth\Enums\AuthKeys; use Quantum\App\Exceptions\BaseException; use Quantum\Di\Exceptions\DiException; use Quantum\Libraries\Hasher\Hasher; diff --git a/src/Libraries/Cache/Adapters/MemcachedAdapter.php b/src/Libraries/Cache/Adapters/MemcachedAdapter.php index 922eb239c..4d1d6cb8c 100644 --- a/src/Libraries/Cache/Adapters/MemcachedAdapter.php +++ b/src/Libraries/Cache/Adapters/MemcachedAdapter.php @@ -9,12 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Cache\Adapters; use Quantum\Libraries\Cache\Exceptions\CacheException; +use Quantum\App\Exceptions\BaseException; use Psr\SimpleCache\CacheInterface; use InvalidArgumentException; use Memcached; @@ -42,10 +43,9 @@ class MemcachedAdapter implements CacheInterface */ private $memcached; - /** * @param array $params - * @throws CacheException + * @throws BaseException */ public function __construct(array $params) { diff --git a/src/Libraries/Cache/Exceptions/CacheException.php b/src/Libraries/Cache/Exceptions/CacheException.php index 10a514dea..ad98c7b25 100644 --- a/src/Libraries/Cache/Exceptions/CacheException.php +++ b/src/Libraries/Cache/Exceptions/CacheException.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Cache\Exceptions; @@ -22,12 +22,5 @@ */ class CacheException extends BaseException { - /** - * @param string $name - * @return CacheException - */ - public static function cantConnect(string $name): CacheException - { - return new static(t('exception.cant_connect', $name)); - } + } \ No newline at end of file diff --git a/src/Libraries/Cookie/Cookie.php b/src/Libraries/Cookie/Cookie.php index 39e659068..13df8be80 100644 --- a/src/Libraries/Cookie/Cookie.php +++ b/src/Libraries/Cookie/Cookie.php @@ -9,12 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Cookie; use Quantum\Libraries\Cookie\Contracts\CookieStorageInterface; +use Quantum\App\Exceptions\BaseException; /** * Class Cookie @@ -61,6 +62,7 @@ public static function getInstance(array &$storage): Cookie /** * @inheritDoc + * @throws BaseException */ public function all(): array { @@ -83,6 +85,7 @@ public function has(string $key): bool /** * @inheritDoc + * @throws BaseException */ public function get(string $key) { @@ -91,6 +94,7 @@ public function get(string $key) /** * @inheritDoc + * @throws BaseException */ public function set(string $key, $value = '', int $time = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httponly = false) { diff --git a/src/Libraries/Csrf/Enums/ExceptionMessages.php b/src/Libraries/Csrf/Enums/ExceptionMessages.php new file mode 100644 index 000000000..206ea7155 --- /dev/null +++ b/src/Libraries/Csrf/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Csrf\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Csrf + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const CSRF_TOKEN_MISSING = 'CSRF Token is missing'; + + const CSRF_TOKEN_MISMATCH = 'CSRF Token does not matched'; +} \ No newline at end of file diff --git a/src/Libraries/Csrf/Exceptions/CsrfException.php b/src/Libraries/Csrf/Exceptions/CsrfException.php index b43ef1648..8f8ccf701 100644 --- a/src/Libraries/Csrf/Exceptions/CsrfException.php +++ b/src/Libraries/Csrf/Exceptions/CsrfException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Csrf\Exceptions; +use Quantum\Libraries\Csrf\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -27,7 +28,7 @@ class CsrfException extends BaseException */ public static function tokenNotFound(): CsrfException { - return new static(t('exception.csrf_token_not_found'), E_WARNING); + return new static(ExceptionMessages::CSRF_TOKEN_MISSING, E_WARNING); } /** @@ -35,6 +36,6 @@ public static function tokenNotFound(): CsrfException */ public static function tokenNotMatched(): CsrfException { - return new static(t('exception.csrf_token_not_matched'), E_WARNING); + return new static(ExceptionMessages::CSRF_TOKEN_MISMATCH, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php b/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php index a0eb02688..390bfcc43 100644 --- a/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php +++ b/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php @@ -24,6 +24,7 @@ use Quantum\Libraries\Database\Contracts\RelationalInterface; use Quantum\Libraries\Database\Exceptions\DatabaseException; use Quantum\Libraries\Database\Contracts\DbalInterface; +use Quantum\App\Exceptions\BaseException; use InvalidArgumentException; use ORM; use PDO; @@ -202,13 +203,13 @@ public function getTable(): string /** * Gets the ORM model * @return ORM - * @throws DatabaseException + * @throws BaseException */ public function getOrmModel(): ORM { if (!$this->ormModel) { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } $this->ormModel = (self::$ormClass)::for_table($this->table)->use_id_column($this->idColumn); diff --git a/src/Libraries/Database/Adapters/Idiorm/Statements/Query.php b/src/Libraries/Database/Adapters/Idiorm/Statements/Query.php index 05253eb09..8664557aa 100644 --- a/src/Libraries/Database/Adapters/Idiorm/Statements/Query.php +++ b/src/Libraries/Database/Adapters/Idiorm/Statements/Query.php @@ -9,12 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Adapters\Idiorm\Statements; use Quantum\Libraries\Database\Exceptions\DatabaseException; +use Quantum\App\Exceptions\BaseException; /** * Trait Query @@ -25,12 +26,12 @@ trait Query /** * @inheritDoc - * @throws DatabaseException + * @throws BaseException */ public static function execute(string $query, array $parameters = []): bool { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } return (self::$ormClass)::raw_execute($query, $parameters); @@ -38,12 +39,12 @@ public static function execute(string $query, array $parameters = []): bool /** * @inheritDoc - * @throws DatabaseException + * @throws BaseException */ public static function query(string $query, array $parameters = []): array { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } return (self::$ormClass)::for_table('dummy')->raw_query($query, $parameters)->find_array(); @@ -51,12 +52,12 @@ public static function query(string $query, array $parameters = []): array /** * @inheritDoc - * @throws DatabaseException + * @throws BaseException */ public static function lastQuery(): ?string { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } return (self::$ormClass)::get_last_query(); @@ -64,12 +65,12 @@ public static function lastQuery(): ?string /** * @inheritDoc - * @throws DatabaseException + * @throws BaseException */ public static function lastStatement(): object { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } return (self::$ormClass)::get_last_statement(); @@ -77,12 +78,12 @@ public static function lastStatement(): object /** * @inheritDoc - * @throws DatabaseException + * @throws BaseException */ public static function queryLog(): array { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } return (self::$ormClass)::get_query_log(); @@ -92,7 +93,7 @@ public static function queryLog(): array * Fetches columns of the table * @param string $table * @return array - * @throws DatabaseException + * @throws BaseException */ public static function fetchColumns(string $table): array { diff --git a/src/Libraries/Database/Adapters/Idiorm/Statements/Transaction.php b/src/Libraries/Database/Adapters/Idiorm/Statements/Transaction.php index 7c3a841ea..493f9053a 100644 --- a/src/Libraries/Database/Adapters/Idiorm/Statements/Transaction.php +++ b/src/Libraries/Database/Adapters/Idiorm/Statements/Transaction.php @@ -9,12 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Adapters\Idiorm\Statements; use Quantum\Libraries\Database\Exceptions\DatabaseException; +use Quantum\App\Exceptions\BaseException; /** * Trait Transaction @@ -25,12 +26,12 @@ trait Transaction /** * Begins a transaction - * @throws DatabaseException + * @throws BaseException */ public static function beginTransaction() { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } (self::$ormClass)::get_db()->beginTransaction(); @@ -38,12 +39,12 @@ public static function beginTransaction() /** * Commits a transaction - * @throws DatabaseException + * @throws BaseException */ public static function commit(): void { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } (self::$ormClass)::get_db()->commit(); @@ -51,12 +52,12 @@ public static function commit(): void /** * Rolls back a transaction - * @throws DatabaseException + * @throws BaseException */ public static function rollback(): void { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } (self::$ormClass)::get_db()->rollBack(); diff --git a/src/Libraries/Database/Adapters/Sleekdb/SleekDbal.php b/src/Libraries/Database/Adapters/Sleekdb/SleekDbal.php index cdb6fed3a..10387e98e 100644 --- a/src/Libraries/Database/Adapters/Sleekdb/SleekDbal.php +++ b/src/Libraries/Database/Adapters/Sleekdb/SleekDbal.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Adapters\Sleekdb; @@ -24,6 +24,7 @@ use SleekDB\Exceptions\InvalidConfigurationException; use SleekDB\Exceptions\InvalidArgumentException; use Quantum\Model\Exceptions\ModelException; +use Quantum\App\Exceptions\BaseException; use SleekDB\Exceptions\IOException; use SleekDB\QueryBuilder; use SleekDB\Store; @@ -255,12 +256,13 @@ public function getTable(): string * @throws IOException * @throws InvalidArgumentException * @throws InvalidConfigurationException + * @throws BaseException */ public function getOrmModel(): Store { if (!$this->ormModel) { if (!self::getConnection()) { - throw DatabaseException::missingConfig(); + throw DatabaseException::missingConfig('database'); } $connection = self::getConnection(); diff --git a/src/Libraries/Database/Enums/ExceptionMessages.php b/src/Libraries/Database/Enums/ExceptionMessages.php new file mode 100644 index 000000000..e9549048a --- /dev/null +++ b/src/Libraries/Database/Enums/ExceptionMessages.php @@ -0,0 +1,32 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Database\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Database + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const INCORRECT_CONFIG = 'The structure of config is not correct'; + + const NOT_SUPPORTED_OPERATOR = 'The operator `{%1}` is not supported'; + + const TABLE_ALREADY_EXISTS = 'The table `{%1}` is already exists'; + + const TABLE_NOT_EXISTS = 'The table `{%1}` does not exists'; +} \ No newline at end of file diff --git a/src/Libraries/Database/Constants/Key.php b/src/Libraries/Database/Enums/Key.php similarity index 92% rename from src/Libraries/Database/Constants/Key.php rename to src/Libraries/Database/Enums/Key.php index 65a373b50..da872e7d2 100644 --- a/src/Libraries/Database/Constants/Key.php +++ b/src/Libraries/Database/Enums/Key.php @@ -9,10 +9,10 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ -namespace Quantum\Libraries\Database\Constants; +namespace Quantum\Libraries\Database\Enums; /** * Class Key diff --git a/src/Libraries/Database/Constants/Type.php b/src/Libraries/Database/Enums/Type.php similarity index 95% rename from src/Libraries/Database/Constants/Type.php rename to src/Libraries/Database/Enums/Type.php index aeece1c63..1f36a192f 100644 --- a/src/Libraries/Database/Constants/Type.php +++ b/src/Libraries/Database/Enums/Type.php @@ -9,10 +9,10 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ -namespace Quantum\Libraries\Database\Constants; +namespace Quantum\Libraries\Database\Enums; /** * Class Type diff --git a/src/Libraries/Database/Exceptions/DatabaseException.php b/src/Libraries/Database/Exceptions/DatabaseException.php index 30c17cebf..6323f0c40 100644 --- a/src/Libraries/Database/Exceptions/DatabaseException.php +++ b/src/Libraries/Database/Exceptions/DatabaseException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Exceptions; +use Quantum\Libraries\Database\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -22,37 +23,13 @@ */ class DatabaseException extends BaseException { - /** - * @return DatabaseException - */ - public static function missingConfig(): DatabaseException - { - return new static(t('exception.config_not_provided'), E_ERROR); - } /** * @return DatabaseException */ public static function incorrectConfig(): DatabaseException { - return new static(t('exception.incorrect_config'), E_ERROR); - } - - /** - * @return DatabaseException - */ - public static function ormClassNotDefined(): DatabaseException - { - return new static(t('exception.orm_class_not_defined'), E_ERROR); - } - - /** - * @param string $name - * @return DatabaseException - */ - public static function ormClassNotFound(string $name): DatabaseException - { - return new static(t('exception.orm_class_not_found', $name), E_ERROR); + return new static(ExceptionMessages::INCORRECT_CONFIG, E_ERROR); } /** @@ -61,7 +38,7 @@ public static function ormClassNotFound(string $name): DatabaseException */ public static function operatorNotSupported(string $operator): DatabaseException { - return new static(t('not_supported_operator', [$operator]), E_WARNING); + return new static(_message(ExceptionMessages::NOT_SUPPORTED_OPERATOR, [$operator]), E_WARNING); } /** @@ -70,7 +47,7 @@ public static function operatorNotSupported(string $operator): DatabaseException */ public static function tableAlreadyExists(string $name): DatabaseException { - return new static(t('exception.table_already_exists', $name), E_ERROR); + return new static(_message(ExceptionMessages::TABLE_ALREADY_EXISTS, $name), E_ERROR); } /** @@ -79,6 +56,6 @@ public static function tableAlreadyExists(string $name): DatabaseException */ public static function tableDoesNotExists(string $name): DatabaseException { - return new static(t('exception.table_does_not_exists', $name), E_ERROR); + return new static(_message(ExceptionMessages::TABLE_NOT_EXISTS, $name), E_ERROR); } -} +} \ No newline at end of file diff --git a/src/Libraries/Database/Schemas/Column.php b/src/Libraries/Database/Schemas/Column.php index a8d8b657f..d8aad35b2 100644 --- a/src/Libraries/Database/Schemas/Column.php +++ b/src/Libraries/Database/Schemas/Column.php @@ -9,12 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.8.0 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Schemas; -use Quantum\Libraries\Database\Constants\Key; +use Quantum\Libraries\Database\Enums\Key; /** * Class Column diff --git a/src/Libraries/Database/Schemas/Table.php b/src/Libraries/Database/Schemas/Table.php index 2fcc3537d..eb4b153b8 100644 --- a/src/Libraries/Database/Schemas/Table.php +++ b/src/Libraries/Database/Schemas/Table.php @@ -9,15 +9,15 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Schemas; use Quantum\Libraries\Database\Exceptions\DatabaseException; -use Quantum\Libraries\Lang\Exceptions\LangException; use Quantum\Migration\Exceptions\MigrationException; use Quantum\Libraries\Database\Traits\TableTrait; +use Quantum\App\Exceptions\BaseException; use Quantum\Libraries\Database\Database; /** @@ -278,13 +278,12 @@ public function getSql(): string * @param string $method * @param array|null $arguments * @return $this - * @throws MigrationException - * @throws LangException + * @throws BaseException */ public function __call(string $method, ?array $arguments) { if (!method_exists(Column::class, $method)) { - throw MigrationException::methodNotDefined($method); + throw MigrationException::methodNotSupported($method, Column::class); } $this->columns[$this->columnKey()]['column']->{$method}(...$arguments); diff --git a/src/Libraries/Database/Traits/TableTrait.php b/src/Libraries/Database/Traits/TableTrait.php index e42061680..c88232094 100644 --- a/src/Libraries/Database/Traits/TableTrait.php +++ b/src/Libraries/Database/Traits/TableTrait.php @@ -9,13 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Traits; use Quantum\Libraries\Database\Schemas\Column; -use Quantum\Libraries\Database\Constants\Key; +use Quantum\Libraries\Database\Enums\Key; /** * Trait TableTrait diff --git a/src/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapter.php b/src/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapter.php index 29844e604..40a18a2b6 100644 --- a/src/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapter.php +++ b/src/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapter.php @@ -9,13 +9,14 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Encryption\Adapters; use Quantum\Libraries\Encryption\Contracts\EncryptionInterface; use Quantum\Libraries\Encryption\Exceptions\CryptorException; +use Quantum\App\Exceptions\BaseException; /** * Class AsymmetricEncryptionAdapter @@ -45,7 +46,7 @@ class AsymmetricEncryptionAdapter implements EncryptionInterface private $privateKey; /** - * @throws CryptorException + * @throws BaseException */ public function __construct() { @@ -56,6 +57,7 @@ public function __construct() } /** + * Encrypts the string * @param string $plain * @return string * @throws CryptorException @@ -71,6 +73,7 @@ public function encrypt(string $plain): string } /** + * Decrypts the string * @param string $encrypted * @return string * @throws CryptorException @@ -86,8 +89,9 @@ public function decrypt(string $encrypted): string } /** + * Generate key pairs * @return array - * @throws CryptorException + * @throws BaseException */ private function generateKeyPair(): array { @@ -98,7 +102,7 @@ private function generateKeyPair(): array ]); if (!$resource) { - throw CryptorException::configNotFound(); + throw CryptorException::missingConfig('openssl.cnf'); } openssl_pkey_export($resource, $privateKey); diff --git a/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php b/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php index f7f21eed2..557a69481 100644 --- a/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php +++ b/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php @@ -51,6 +51,7 @@ public function __construct() } /** + * Encrypts the string * @param string $plain * @return string */ @@ -64,6 +65,7 @@ public function encrypt(string $plain): string } /** + * Decrypts the string * @param string $encrypted * @return string * @throws CryptorException @@ -87,6 +89,7 @@ public function decrypt(string $encrypted): string } /** + * Generates initialization vector * @return string */ private function generateIV(): string diff --git a/src/Libraries/Encryption/Enums/ExceptionMessages.php b/src/Libraries/Encryption/Enums/ExceptionMessages.php new file mode 100644 index 000000000..05e278b79 --- /dev/null +++ b/src/Libraries/Encryption/Enums/ExceptionMessages.php @@ -0,0 +1,32 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Encryption\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Encryption + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const PUBLIC_KEY_MISSING = 'Public key is not provided'; + + const PRIVATE_KEY_MISSING = 'Private key is not provided'; + + const INVALID_CIPHER = 'The cipher is invalid'; + + +} \ No newline at end of file diff --git a/src/Libraries/Encryption/Exceptions/CryptorException.php b/src/Libraries/Encryption/Exceptions/CryptorException.php index d2d4a3304..386e2ccf0 100644 --- a/src/Libraries/Encryption/Exceptions/CryptorException.php +++ b/src/Libraries/Encryption/Exceptions/CryptorException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Encryption\Exceptions; +use Quantum\Libraries\Encryption\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -22,28 +23,13 @@ */ class CryptorException extends BaseException { - /** - * @return CryptorException - */ - public static function configNotFound(): CryptorException - { - return new static(t('exception.openssl_config_not_found'), E_WARNING); - } - - /** - * @return CryptorException - */ - public static function noPrivateKeyCreated(): CryptorException - { - return new static(t('exception.openssl_private_key_not_created'), E_WARNING); - } /** * @return CryptorException */ public static function publicKeyNotProvided(): CryptorException { - return new static(t('exception.openssl_public_key_not_provided'), E_WARNING); + return new static(ExceptionMessages::PUBLIC_KEY_MISSING, E_WARNING); } /** @@ -51,7 +37,7 @@ public static function publicKeyNotProvided(): CryptorException */ public static function privateKeyNotProvided(): CryptorException { - return new static(t('exception.openssl_private_key_not_provided'), E_WARNING); + return new static(ExceptionMessages::PRIVATE_KEY_MISSING, E_WARNING); } /** @@ -59,6 +45,6 @@ public static function privateKeyNotProvided(): CryptorException */ public static function invalidCipher(): CryptorException { - return new static(t('exception.openssl_invalid_cipher'), E_WARNING); + return new static(ExceptionMessages::INVALID_CIPHER, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Hasher/Enums/ExceptionMessages.php b/src/Libraries/Hasher/Enums/ExceptionMessages.php new file mode 100644 index 000000000..27c7d4dbb --- /dev/null +++ b/src/Libraries/Hasher/Enums/ExceptionMessages.php @@ -0,0 +1,32 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Hasher\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Hasher + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const ALGORITHM_NOT_SUPPORTED = 'The algorithm {%1} not supported.'; + + const INVALID_BCRYPT_COST = 'Provided bcrypt cost is invalid.'; + + + + +} \ No newline at end of file diff --git a/src/Libraries/Hasher/Exceptions/HasherException.php b/src/Libraries/Hasher/Exceptions/HasherException.php index 5fb3b2948..4473d0e9d 100644 --- a/src/Libraries/Hasher/Exceptions/HasherException.php +++ b/src/Libraries/Hasher/Exceptions/HasherException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Hasher\Exceptions; +use Quantum\Libraries\Hasher\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -30,7 +31,7 @@ class HasherException extends BaseException */ public static function algorithmNotSupported(string $algorithm): self { - return new static(t('exception.not_supported_algorithm', $algorithm), E_WARNING); + return new static(_message(ExceptionMessages::ALGORITHM_NOT_SUPPORTED, $algorithm), E_WARNING); } /** @@ -39,6 +40,6 @@ public static function algorithmNotSupported(string $algorithm): self */ public static function invalidBcryptCost(): self { - return new static(t('exception.invalid_bcrypt_cost'), E_WARNING); + return new static(ExceptionMessages::INVALID_BCRYPT_COST, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/HttpClient/Enums/ExceptionMessages.php b/src/Libraries/HttpClient/Enums/ExceptionMessages.php new file mode 100644 index 000000000..7c9c1fbc9 --- /dev/null +++ b/src/Libraries/HttpClient/Enums/ExceptionMessages.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\HttpClient\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\HttpClient + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const REQUEST_NOT_CREATED = 'Request is not created.'; +} \ No newline at end of file diff --git a/src/Libraries/HttpClient/Exceptions/HttpClientException.php b/src/Libraries/HttpClient/Exceptions/HttpClientException.php index ca958e9ff..5002fefe9 100644 --- a/src/Libraries/HttpClient/Exceptions/HttpClientException.php +++ b/src/Libraries/HttpClient/Exceptions/HttpClientException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\HttpClient\Exceptions; +use Quantum\Libraries\HttpClient\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -24,19 +25,11 @@ class HttpClientException extends BaseException { /** - * @param string $name * @return HttpClientException */ - public static function methodNotAvailable(string $name): self - { - return new static(t('exception.method_not_available', $name), E_WARNING); - } - /** - * @return HttpClientException - */ public static function requestNotCreated(): self { - return new static(t('exception.request_not_created'), E_WARNING); + return new static(ExceptionMessages::REQUEST_NOT_CREATED, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/HttpClient/HttpClient.php b/src/Libraries/HttpClient/HttpClient.php index 536e9d4d2..203946319 100644 --- a/src/Libraries/HttpClient/HttpClient.php +++ b/src/Libraries/HttpClient/HttpClient.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\HttpClient; @@ -126,12 +126,12 @@ public function createAsyncMultiRequest(callable $success, callable $error): Htt * Sets http method * @param string $method * @return $this - * @throws HttpClientException + * @throws BaseException */ public function setMethod(string $method): HttpClient { if (!in_array($method, self::METHODS)) { - throw HttpClientException::methodNotAvailable($method); + throw HttpClientException::requestMethodNotAvailable($method); } $this->method = $method; diff --git a/src/Libraries/Jwt/Enums/ExceptionMessages.php b/src/Libraries/Jwt/Enums/ExceptionMessages.php new file mode 100644 index 000000000..b1e8a608f --- /dev/null +++ b/src/Libraries/Jwt/Enums/ExceptionMessages.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Jwt\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Jwt + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const MISSING_PAYLOAD = 'JWT payload is missing.'; +} \ No newline at end of file diff --git a/src/Libraries/Jwt/Exceptions/JwtException.php b/src/Libraries/Jwt/Exceptions/JwtException.php index 57b4ca924..1341b9802 100644 --- a/src/Libraries/Jwt/Exceptions/JwtException.php +++ b/src/Libraries/Jwt/Exceptions/JwtException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Jwt\Exceptions; +use Quantum\Libraries\Jwt\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -22,11 +23,12 @@ */ class JwtException extends BaseException { + /** * @return JwtException */ public static function payloadNotFound(): JwtException { - return new static(t('exception.jwt_payload_not_found'), E_WARNING); + return new static(ExceptionMessages::MISSING_PAYLOAD, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Lang/Enums/ExceptionMessages.php b/src/Libraries/Lang/Enums/ExceptionMessages.php new file mode 100644 index 000000000..904334cc6 --- /dev/null +++ b/src/Libraries/Lang/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Lang\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Lang + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const TRANSLATION_FILES_NOT_FOUND = 'Translation files not found.'; + + const MISCONFIGURED_DEFAULT_LANG = 'Misconfigured lang default config.'; +} \ No newline at end of file diff --git a/src/Libraries/Lang/Exceptions/LangException.php b/src/Libraries/Lang/Exceptions/LangException.php index acb08e15c..8d7fb9b78 100644 --- a/src/Libraries/Lang/Exceptions/LangException.php +++ b/src/Libraries/Lang/Exceptions/LangException.php @@ -14,6 +14,7 @@ namespace Quantum\Libraries\Lang\Exceptions; +use Quantum\Libraries\Lang\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -28,7 +29,7 @@ class LangException extends BaseException */ public static function translationsNotFound(): LangException { - return new static('Translation files not found', E_WARNING); + return new static(ExceptionMessages::TRANSLATION_FILES_NOT_FOUND, E_WARNING); } /** @@ -36,6 +37,6 @@ public static function translationsNotFound(): LangException */ public static function misconfiguredDefaultConfig(): LangException { - return new static('Misconfigured lang default config', E_WARNING); + return new static(ExceptionMessages::MISCONFIGURED_DEFAULT_LANG, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Logger/Enums/ExceptionMessages.php b/src/Libraries/Logger/Enums/ExceptionMessages.php new file mode 100644 index 000000000..9d8a65632 --- /dev/null +++ b/src/Libraries/Logger/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Logger\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Logger + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const LOG_PATH_NOT_DIRECTORY = 'Log path is not point to a directory.'; + + const LOG_PATH_NOT_FILE = 'Log path is not point to a file.'; +} \ No newline at end of file diff --git a/src/Libraries/Logger/Exceptions/LoggerException.php b/src/Libraries/Logger/Exceptions/LoggerException.php index c5ea0f2e5..b6ca26703 100644 --- a/src/Libraries/Logger/Exceptions/LoggerException.php +++ b/src/Libraries/Logger/Exceptions/LoggerException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Logger\Exceptions; +use Quantum\Libraries\Logger\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -29,7 +30,7 @@ class LoggerException extends BaseException */ public static function logPathIsNotDirectory(string $name): LoggerException { - return new static(t('exception.log_path_is_not_directory', $name)); + return new static(_message(ExceptionMessages::LOG_PATH_NOT_DIRECTORY, [$name]), E_ERROR); } /** @@ -38,15 +39,6 @@ public static function logPathIsNotDirectory(string $name): LoggerException */ public static function logPathIsNotFile(string $name): LoggerException { - return new static(t('exception.log_path_is_not_file', $name)); - } - - /** - * @param string $name - * @return LoggerException - */ - public static function adapterNotAllowed(string $name): LoggerException - { - return new static(t('exception.message_logger_not_in_debug_mode', $name)); + return new static(_message(ExceptionMessages::LOG_PATH_NOT_FILE, [$name]), E_ERROR); } } \ No newline at end of file diff --git a/src/Libraries/Logger/Factories/LoggerFactory.php b/src/Libraries/Logger/Factories/LoggerFactory.php index 7b3bb9d71..9c7cc1b45 100644 --- a/src/Libraries/Logger/Factories/LoggerFactory.php +++ b/src/Libraries/Logger/Factories/LoggerFactory.php @@ -64,7 +64,7 @@ public static function get(?string $adapter = null): Logger $isDebug = is_debug_mode(); if (!$isDebug && $adapter === Logger::MESSAGE) { - throw LoggerException::adapterNotAllowed(Logger::MESSAGE); + throw LoggerException::adapterNotSupported(Logger::MESSAGE); } $adapter = $isDebug ? Logger::MESSAGE : ($adapter ?? config()->get('logging.default')); diff --git a/src/Libraries/Mailer/Exceptions/MailerException.php b/src/Libraries/Mailer/Exceptions/MailerException.php index 4187e0742..fe09b4a1a 100644 --- a/src/Libraries/Mailer/Exceptions/MailerException.php +++ b/src/Libraries/Mailer/Exceptions/MailerException.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Mailer\Exceptions; @@ -23,12 +23,4 @@ class MailerException extends BaseException { - /** - * @param string $error - * @return MailerException - */ - public static function unableToSend(string $error): MailerException - { - return new static($error, E_WARNING); - } } \ No newline at end of file diff --git a/src/Libraries/ResourceCache/Enums/ExceptionMessages.php b/src/Libraries/ResourceCache/Enums/ExceptionMessages.php new file mode 100644 index 000000000..7c61d38be --- /dev/null +++ b/src/Libraries/ResourceCache/Enums/ExceptionMessages.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\ResourceCache\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Lang + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const TRANSLATION_FILES_NOT_FOUND = 'The class class {%1} not found. Please install {%2} package.'; +} \ No newline at end of file diff --git a/src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php b/src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php new file mode 100644 index 000000000..5ee41e9a4 --- /dev/null +++ b/src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php @@ -0,0 +1,36 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\ResourceCache\Exceptions; + +use Quantum\Libraries\ResourceCache\Enums\ExceptionMessages; +use Quantum\App\Exceptions\BaseException; + +/** + * Class JwtException + * @package Quantum\Libraries\JwtToken + */ +class ResourceCacheException extends BaseException +{ + + /** + * @param string $className + * @param string $packageName + * @return ResourceCacheException + */ + public static function classNotFound(string $className, string $packageName): ResourceCacheException + { + return new static(_message(ExceptionMessages::TRANSLATION_FILES_NOT_FOUND, [$className, $packageName]), E_WARNING); + } +} \ No newline at end of file diff --git a/src/Libraries/ResourceCache/ViewCache.php b/src/Libraries/ResourceCache/ViewCache.php index f2941cc5b..fe811e187 100644 --- a/src/Libraries/ResourceCache/ViewCache.php +++ b/src/Libraries/ResourceCache/ViewCache.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\ResourceCache; +use Quantum\Libraries\ResourceCache\Exceptions\ResourceCacheException; use Quantum\Libraries\Database\Exceptions\DatabaseException; use Quantum\Libraries\Session\Exceptions\SessionException; use Quantum\Libraries\Storage\Factories\FileSystemFactory; @@ -282,13 +283,14 @@ private function getCacheFile(string $key): string /** * @param string $content * @return string + * @throws ResourceCacheException */ private function minify(string $content): string { - if (class_exists(HtmlMin::class)) { - return (new HtmlMin())->minify($content); + if (!class_exists(HtmlMin::class)) { + throw ResourceCacheException::classNotFound('HtmlMin', 'voku/html-min'); } - return $content; + return (new HtmlMin())->minify($content); } } \ No newline at end of file diff --git a/src/Libraries/Session/Enums/ExceptionMessages.php b/src/Libraries/Session/Enums/ExceptionMessages.php new file mode 100644 index 000000000..446ef5503 --- /dev/null +++ b/src/Libraries/Session/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Session\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Session + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const SESSION_NOT_STARTED = 'Can not start the session.'; + + const SESSION_NOT_DESTROYED = 'Can not destroy the session.'; +} \ No newline at end of file diff --git a/src/Libraries/Session/Exceptions/SessionException.php b/src/Libraries/Session/Exceptions/SessionException.php index e9656eddd..d7f16883b 100644 --- a/src/Libraries/Session/Exceptions/SessionException.php +++ b/src/Libraries/Session/Exceptions/SessionException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Session\Exceptions; +use Quantum\Libraries\Session\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -27,7 +28,7 @@ class SessionException extends BaseException */ public static function sessionNotStarted(): SessionException { - return new static(t('exception.session_not_started'), E_WARNING); + return new static(ExceptionMessages::SESSION_NOT_STARTED, E_WARNING); } /** @@ -35,14 +36,6 @@ public static function sessionNotStarted(): SessionException */ public static function sessionNotDestroyed(): SessionException { - return new static(t('exception.session_not_destroyed'), E_WARNING); - } - - /** - * @return SessionException - */ - public static function sessionTableNotProvided(): SessionException - { - return new static(t('exception.session_table_not_provided')); + return new static(ExceptionMessages::SESSION_NOT_DESTROYED, E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Storage/Enums/ExceptionMessages.php b/src/Libraries/Storage/Enums/ExceptionMessages.php new file mode 100644 index 000000000..b0d10fd24 --- /dev/null +++ b/src/Libraries/Storage/Enums/ExceptionMessages.php @@ -0,0 +1,32 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Libraries\Storage\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Session + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const DIRECTORY_NOT_EXISTS = 'The directory {%1} does not exists.'; + + const DIRECTORY_NOT_WRITABLE = 'The directory {%1} is not writable.'; + + const FILE_ALREADY_EXISTS = 'The file {%1} already exists.'; + + const FILE_TYPE_NOT_ALLOWED = 'The file type `{%1}` is not allowed.'; +} \ No newline at end of file diff --git a/src/Libraries/Storage/Exceptions/FileSystemException.php b/src/Libraries/Storage/Exceptions/FileSystemException.php index 3ffa48331..7d7c7a53d 100644 --- a/src/Libraries/Storage/Exceptions/FileSystemException.php +++ b/src/Libraries/Storage/Exceptions/FileSystemException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Storage\Exceptions; +use Quantum\Libraries\Storage\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -29,7 +30,7 @@ class FileSystemException extends BaseException */ public static function directoryNotExists(string $name): FileSystemException { - return new static(t('exception.directory_not_exist', $name), E_WARNING); + return new static(_message(ExceptionMessages::DIRECTORY_NOT_EXISTS, [$name]), E_WARNING); } /** @@ -38,22 +39,15 @@ public static function directoryNotExists(string $name): FileSystemException */ public static function directoryNotWritable(string $name): FileSystemException { - return new static(t('exception.directory_not_writable', $name), E_WARNING); + return new static(_message(ExceptionMessages::DIRECTORY_NOT_WRITABLE, [$name]), E_WARNING); } /** + * @param string $path * @return FileSystemException */ - public static function fileAlreadyExists(): FileSystemException + public static function fileAlreadyExists(string $path): FileSystemException { - return new static(t('exception.file_already_exists'), E_WARNING); - } - - /** - * @return FileSystemException - */ - public static function incorrectTokenService(): FileSystemException - { - return new static(t('exception.incorrect_auth_service'), E_WARNING); + return new static(_message(ExceptionMessages::FILE_ALREADY_EXISTS, [$path]), E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Storage/Exceptions/FileUploadException.php b/src/Libraries/Storage/Exceptions/FileUploadException.php index 8eac28675..6f1256a43 100644 --- a/src/Libraries/Storage/Exceptions/FileUploadException.php +++ b/src/Libraries/Storage/Exceptions/FileUploadException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Storage\Exceptions; +use Quantum\Libraries\Storage\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -29,6 +30,6 @@ class FileUploadException extends BaseException */ public static function fileTypeNotAllowed(string $name): FileUploadException { - return new static(t('exception.file_type_not_allowed', $name), E_WARNING); + return new static(_message(ExceptionMessages::FILE_TYPE_NOT_ALLOWED, [$name]), E_WARNING); } } \ No newline at end of file diff --git a/src/Libraries/Storage/Factories/FileSystemFactory.php b/src/Libraries/Storage/Factories/FileSystemFactory.php index bdcd45003..ead7abf1c 100644 --- a/src/Libraries/Storage/Factories/FileSystemFactory.php +++ b/src/Libraries/Storage/Factories/FileSystemFactory.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Storage\Factories; @@ -90,8 +90,8 @@ public static function get(?string $adapter = null): FileSystem * @param string $adapterClass * @param string $adapter * @return FileSystem + * @throws BaseException * @throws DiException - * @throws FileSystemException * @throws ReflectionException * @throws ServiceException */ @@ -119,8 +119,8 @@ private static function getAdapterClass(string $adapter): string /** * @param string $adapter * @return CloudAppInterface|null + * @throws BaseException * @throws DiException - * @throws FileSystemException * @throws ReflectionException * @throws ServiceException */ @@ -143,17 +143,19 @@ private static function createCloudApp(string $adapter): ?CloudAppInterface /** * @param string $adapter * @return TokenServiceInterface - * @throws FileSystemException + * @throws BaseException * @throws DiException - * @throws ServiceException * @throws ReflectionException + * @throws ServiceException */ private static function createTokenService(string $adapter): TokenServiceInterface { - $tokenService = ServiceFactory::create(config()->get('fs.' . $adapter . '.service')); + $serviceClass = config()->get('fs.' . $adapter . '.service'); + + $tokenService = ServiceFactory::create($serviceClass); if (!$tokenService instanceof TokenServiceInterface) { - throw FileSystemException::incorrectTokenService(); + throw FileSystemException::notInstanceOf($serviceClass, TokenServiceInterface::class); } return $tokenService; diff --git a/src/Libraries/Storage/UploadedFile.php b/src/Libraries/Storage/UploadedFile.php index d9dbf77c8..390ae0052 100644 --- a/src/Libraries/Storage/UploadedFile.php +++ b/src/Libraries/Storage/UploadedFile.php @@ -281,7 +281,7 @@ public function save(string $dest, bool $overwrite = false): bool } if ($overwrite === false && $this->localFileSystem->exists($filePath)) { - throw FileSystemException::fileAlreadyExists(); + throw FileSystemException::fileAlreadyExists($filePath); } } diff --git a/src/Middleware/Enums/ExceptionMessages.php b/src/Middleware/Enums/ExceptionMessages.php new file mode 100644 index 000000000..2552ff81d --- /dev/null +++ b/src/Middleware/Enums/ExceptionMessages.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Middleware\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Middleware + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const MIDDLEWARE_NOT_FOUND = 'Middleware class `{%1}` not found.'; +} \ No newline at end of file diff --git a/src/Middleware/Exceptions/MiddlewareException.php b/src/Middleware/Exceptions/MiddlewareException.php index 0fe1695e5..15faf6c18 100644 --- a/src/Middleware/Exceptions/MiddlewareException.php +++ b/src/Middleware/Exceptions/MiddlewareException.php @@ -14,6 +14,7 @@ namespace Quantum\Middleware\Exceptions; +use Quantum\Middleware\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -29,6 +30,6 @@ class MiddlewareException extends BaseException */ public static function middlewareNotFound(string $name): MiddlewareException { - return new static("Middleware class `$name` not found.", E_ERROR); + return new static(_message(ExceptionMessages::MIDDLEWARE_NOT_FOUND, [$name]), E_ERROR); } } \ No newline at end of file diff --git a/src/Migration/Enums/ExceptionMessages.php b/src/Migration/Enums/ExceptionMessages.php new file mode 100644 index 000000000..5ad3a9b74 --- /dev/null +++ b/src/Migration/Enums/ExceptionMessages.php @@ -0,0 +1,30 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Migration\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Migration + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const WRONG_MIGRATION_DIRECTION = 'Migration direction can only be [up] or [down]'; + + const NOT_SUPPORTED_ACTION = 'The action `{%1}`, is not supported'; + + const NOTHING_TO_MIGRATE = 'Nothing to migrate'; +} \ No newline at end of file diff --git a/src/Migration/Exceptions/MigrationException.php b/src/Migration/Exceptions/MigrationException.php index 6605c02fe..8b80433a9 100644 --- a/src/Migration/Exceptions/MigrationException.php +++ b/src/Migration/Exceptions/MigrationException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Migration\Exceptions; +use Quantum\Migration\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -30,7 +31,7 @@ class MigrationException extends BaseException */ public static function wrongDirection(): MigrationException { - return new static(t('exception.wrong_migration_direction'), E_ERROR); + return new static(ExceptionMessages::WRONG_MIGRATION_DIRECTION, E_ERROR); } /** @@ -39,25 +40,7 @@ public static function wrongDirection(): MigrationException */ public static function unsupportedAction(string $action): MigrationException { - return new static(t('exception.non_supported_action', $action), E_ERROR); - } - - /** - * @param string $name - * @return MigrationException - */ - public static function columnNotAvailable(string $name): MigrationException - { - return new static(t('exception.column_not_available', $name), E_ERROR); - } - - /** - * @param string $name - * @return MigrationException - */ - public static function methodNotDefined(string $name): MigrationException - { - return new static(t('exception.method_not_defined', $name), E_ERROR); + return new static(_message(ExceptionMessages::NOT_SUPPORTED_ACTION, [$action]), E_ERROR); } /** @@ -65,6 +48,6 @@ public static function methodNotDefined(string $name): MigrationException */ public static function nothingToMigrate(): MigrationException { - return new static(t('exception.nothing_to_migrate'), E_NOTICE); + return new static(ExceptionMessages::NOTHING_TO_MIGRATE, E_NOTICE); } } \ No newline at end of file diff --git a/src/Migration/MigrationTable.php b/src/Migration/MigrationTable.php index 81e5a4cdb..092cfa332 100644 --- a/src/Migration/MigrationTable.php +++ b/src/Migration/MigrationTable.php @@ -9,14 +9,14 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Migration; use Quantum\Libraries\Database\Exceptions\DatabaseException; use Quantum\Libraries\Database\Factories\TableFactory; -use Quantum\Libraries\Database\Constants\Type; +use Quantum\Libraries\Database\Enums\Type; /** * Class MigrationTable diff --git a/src/Model/Enums/ExceptionMessages.php b/src/Model/Enums/ExceptionMessages.php new file mode 100644 index 000000000..1a176670f --- /dev/null +++ b/src/Model/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Model\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Model + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const INAPPROPRIATE_MODEL_PROPERTY = 'Inappropriate property `{%1}` for fillable object'; + + const WRONG_RELATION = 'The model `{%1}` does not define relation with `{%2}`'; +} \ No newline at end of file diff --git a/src/Model/Exceptions/ModelException.php b/src/Model/Exceptions/ModelException.php index 8dd4817b4..e3e275b2e 100644 --- a/src/Model/Exceptions/ModelException.php +++ b/src/Model/Exceptions/ModelException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Model\Exceptions; +use Quantum\Model\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -22,41 +23,6 @@ */ class ModelException extends BaseException { - /** - * @param string $name - * @return ModelException - */ - public static function notFound(string $name): ModelException - { - return new static(t('exception.model_not_found', $name), E_ERROR); - } - - /** - * @param array $names - * @return ModelException - */ - public static function notModelInstance(array $names): ModelException - { - return new static(t('exception.not_instance_of_model', $names), E_WARNING); - } - - /** - * @param string|null $name - * @return ModelException - */ - public static function noTableDefined(?string $name): ModelException - { - return new static(t('exception.model_without_table_defined', $name), E_WARNING); - } - - /** - * @param string $name - * @return ModelException - */ - public static function undefinedMethod(string $name): ModelException - { - return new static(t('exception.undefined_model_method', $name), E_WARNING); - } /** * @param string $name @@ -64,7 +30,7 @@ public static function undefinedMethod(string $name): ModelException */ public static function inappropriateProperty(string $name): ModelException { - return new static(t('exception.inappropriate_property', $name), E_WARNING); + return new static(_message(ExceptionMessages::INAPPROPRIATE_MODEL_PROPERTY, $name), E_WARNING); } /** @@ -74,6 +40,6 @@ public static function inappropriateProperty(string $name): ModelException */ public static function wrongRelation(string $modelName, string $tableName): ModelException { - return new static(t('exception.wrong_relation', [$modelName, $tableName]), E_ERROR); + return new static(_message(ExceptionMessages::WRONG_RELATION, [$modelName, $tableName]), E_ERROR); } } diff --git a/src/Model/Factories/ModelFactory.php b/src/Model/Factories/ModelFactory.php index eec239e21..5c06f2e39 100644 --- a/src/Model/Factories/ModelFactory.php +++ b/src/Model/Factories/ModelFactory.php @@ -9,13 +9,14 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Model\Factories; use Quantum\Libraries\Database\Contracts\DbalInterface; use Quantum\Model\Exceptions\ModelException; +use Quantum\App\Exceptions\BaseException; use Quantum\Libraries\Database\Database; use Quantum\Model\QtModel; @@ -31,17 +32,18 @@ class ModelFactory * @param string $modelClass * @return QtModel * @throws ModelException + * @throws BaseException */ public static function get(string $modelClass): QtModel { if (!class_exists($modelClass)) { - throw ModelException::notFound($modelClass); + throw ModelException::notFound('Model', $modelClass); } $model = new $modelClass(); if (!$model instanceof QtModel) { - throw ModelException::notModelInstance([$modelClass, QtModel::class]); + throw ModelException::notInstanceOf($modelClass, QtModel::class); } $ormInstance = self::createOrmInstance( diff --git a/src/Model/QtModel.php b/src/Model/QtModel.php index b9b7d1b70..724885a31 100644 --- a/src/Model/QtModel.php +++ b/src/Model/QtModel.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Model; @@ -206,14 +206,14 @@ public function __set(string $property, $value) /** * @param string $method - * @param mixed|null $args - * @return $this|array|int|string - * @throws ModelException + * @param $args + * @return $this + * @throws BaseException */ public function __call(string $method, $args = null) { if (!method_exists($this->ormInstance, $method)) { - throw ModelException::undefinedMethod($method); + throw ModelException::methodNotSupported($method, get_class($this->ormInstance)); } $result = $this->ormInstance->{$method}(...$args); diff --git a/src/Module/Enums/ExceptionMessages.php b/src/Module/Enums/ExceptionMessages.php new file mode 100644 index 000000000..91ae72022 --- /dev/null +++ b/src/Module/Enums/ExceptionMessages.php @@ -0,0 +1,36 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Module\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Module + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const MODULE_ROUTES_NOT_FOUND = 'Routes not found for module `{%1}`'; + + const MODULE_CONFIG_NOT_FOUND = 'Config not found for a module'; + + const MODULE_CREATION_INCOMPLETE = 'Module creation incomplete: missing files.'; + + const MISSING_MODULE_TEMPLATE = 'Template `{%1}` does not exist'; + + const MISSING_MODULE_DIRECTORY = 'Module directory does not exist, skipping config update.'; + + const MODULE_ALREADY_EXISTS = 'A module or prefix named `{%1}` already exists'; +} \ No newline at end of file diff --git a/src/Module/Exceptions/ModuleException.php b/src/Module/Exceptions/ModuleException.php index 4eb7da301..c886170c7 100644 --- a/src/Module/Exceptions/ModuleException.php +++ b/src/Module/Exceptions/ModuleException.php @@ -9,24 +9,27 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Module\Exceptions; +use Quantum\Module\Enums\ExceptionMessages; + /** * Class ModuleLoaderException * @package Quantum\Module */ class ModuleException extends \Exception { + /** * @param string $name * @return ModuleException */ public static function moduleRoutesNotFound(string $name): ModuleException { - return new static(t('exception.module_routes_not_found', $name), E_ERROR); + return new static(_message(ExceptionMessages::MODULE_ROUTES_NOT_FOUND, $name), E_ERROR); } /** @@ -34,7 +37,7 @@ public static function moduleRoutesNotFound(string $name): ModuleException */ public static function moduleConfigNotFound(): ModuleException { - return new static(t('exception.module_config_not_found'), E_ERROR); + return new static(ExceptionMessages::MODULE_CONFIG_NOT_FOUND, E_ERROR); } /** @@ -42,7 +45,7 @@ public static function moduleConfigNotFound(): ModuleException */ public static function moduleCreationIncomplete(): ModuleException { - return new static("Module creation incomplete: missing files.", E_ERROR); + return new static(ExceptionMessages::MODULE_CREATION_INCOMPLETE, E_ERROR); } /** @@ -51,7 +54,7 @@ public static function moduleCreationIncomplete(): ModuleException */ public static function missingModuleTemplate(string $name): ModuleException { - return new static("Template `" . $name . "` does not exist", E_ERROR); + return new static(_message(ExceptionMessages::MISSING_MODULE_TEMPLATE, [$name]), E_ERROR); } /** @@ -59,7 +62,7 @@ public static function missingModuleTemplate(string $name): ModuleException */ public static function missingModuleDirectory(): ModuleException { - return new static("Module directory does not exist, skipping config update.", E_ERROR); + return new static(ExceptionMessages::MISSING_MODULE_DIRECTORY, E_ERROR); } /** @@ -68,6 +71,6 @@ public static function missingModuleDirectory(): ModuleException */ public static function moduleAlreadyExists(string $name): ModuleException { - return new static("A module or prefix named `" . $name . "` already exists", E_ERROR); + return new static(_message(ExceptionMessages::MODULE_ALREADY_EXISTS, [$name]), E_ERROR); } } \ No newline at end of file diff --git a/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl b/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl index 6d10df9fd..87ddadf99 100644 --- a/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl +++ b/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl @@ -15,7 +15,7 @@ namespace {{MODULE_NAMESPACE}}\Controllers; use Quantum\Libraries\Auth\Exceptions\AuthException; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use Quantum\Http\Response; use Quantum\Http\Request; use {{MODULE_NAMESPACE}}\Enums\Role; diff --git a/src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl b/src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl index 8ecb0597c..7aec6fb56 100644 --- a/src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl +++ b/src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl @@ -15,7 +15,7 @@ namespace {{MODULE_NAMESPACE}}\Controllers; use Quantum\Service\Factories\ServiceFactory; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use {{MODULE_NAMESPACE}}\Services\CommentService; use {{MODULE_NAMESPACE}}\Services\PostService; use Quantum\Http\Response; diff --git a/src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl b/src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl index 198636ad4..e0e7ec93a 100644 --- a/src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl +++ b/src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl @@ -14,7 +14,7 @@ namespace {{MODULE_NAMESPACE}}\Middlewares; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use Quantum\Http\Response; use Quantum\Http\Request; use Closure; diff --git a/src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl b/src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl index 822f95205..f92400b93 100644 --- a/src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl +++ b/src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl @@ -15,7 +15,7 @@ namespace {{MODULE_NAMESPACE}}\Middlewares; use Quantum\Libraries\Validation\Validator; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use Quantum\Middleware\QtMiddleware; use Quantum\Http\Response; use Quantum\Http\Request; diff --git a/src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl b/src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl index b5ec9a7ca..075f446df 100644 --- a/src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl +++ b/src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl @@ -14,7 +14,7 @@ namespace {{MODULE_NAMESPACE}}\Middlewares; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use Quantum\Libraries\Validation\Rule; use Quantum\Http\Response; use Quantum\Http\Request; diff --git a/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl b/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl index 80ea0f149..d2b580a32 100644 --- a/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl @@ -16,7 +16,7 @@ namespace {{MODULE_NAMESPACE}}\Controllers; use Quantum\Service\Factories\ServiceFactory; use {{MODULE_NAMESPACE}}\Services\CommentService; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use {{MODULE_NAMESPACE}}\Services\PostService; use Quantum\View\RawParam; use Quantum\Http\Response; diff --git a/src/Module/Templates/DemoWeb/src/Middlewares/Activate.php.tpl b/src/Module/Templates/DemoWeb/src/Middlewares/Activate.php.tpl index fc3fe3f07..0d7813e8e 100644 --- a/src/Module/Templates/DemoWeb/src/Middlewares/Activate.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Middlewares/Activate.php.tpl @@ -15,7 +15,7 @@ namespace {{MODULE_NAMESPACE}}\Middlewares; use Quantum\Libraries\Validation\Rule; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use {{MODULE_NAMESPACE}}\Models\User; use Quantum\Http\Response; use Quantum\Http\Request; diff --git a/src/Module/Templates/DemoWeb/src/Middlewares/PostOwner.php.tpl b/src/Module/Templates/DemoWeb/src/Middlewares/PostOwner.php.tpl index b6dd70c6a..92be4b520 100644 --- a/src/Module/Templates/DemoWeb/src/Middlewares/PostOwner.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Middlewares/PostOwner.php.tpl @@ -16,7 +16,7 @@ namespace {{MODULE_NAMESPACE}}\Middlewares; use Quantum\Service\Factories\ServiceFactory; use Quantum\Libraries\Validation\Rule; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use {{MODULE_NAMESPACE}}\Services\PostService; use Quantum\Http\Response; use Quantum\Http\Request; diff --git a/src/Module/Templates/DemoWeb/src/Middlewares/Reset.php.tpl b/src/Module/Templates/DemoWeb/src/Middlewares/Reset.php.tpl index f3c957f83..2daea6193 100644 --- a/src/Module/Templates/DemoWeb/src/Middlewares/Reset.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Middlewares/Reset.php.tpl @@ -14,7 +14,7 @@ namespace {{MODULE_NAMESPACE}}\Middlewares; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use Quantum\Libraries\Validation\Rule; use {{MODULE_NAMESPACE}}\Models\User; use Quantum\Http\Response; diff --git a/src/Module/Templates/DemoWeb/src/Middlewares/Verify.php.tpl b/src/Module/Templates/DemoWeb/src/Middlewares/Verify.php.tpl index a44369ff4..01274fc55 100644 --- a/src/Module/Templates/DemoWeb/src/Middlewares/Verify.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Middlewares/Verify.php.tpl @@ -14,7 +14,7 @@ namespace {{MODULE_NAMESPACE}}\Middlewares; -use Quantum\Http\Constants\StatusCode; +use Quantum\Http\Enums\StatusCode; use Quantum\Libraries\Validation\Rule; use {{MODULE_NAMESPACE}}\Models\User; use Quantum\Http\Response; diff --git a/src/Paginator/Enums/ExceptionMessages.php b/src/Paginator/Enums/ExceptionMessages.php new file mode 100644 index 000000000..ae30c9bce --- /dev/null +++ b/src/Paginator/Enums/ExceptionMessages.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Paginator\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Paginator + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const MISSING_REQUIRED_PARAMS = 'Missing required parameter `{%1}` missing for adapter {%2}'; +} \ No newline at end of file diff --git a/src/Paginator/Constants/Pagination.php b/src/Paginator/Enums/Pagination.php similarity index 94% rename from src/Paginator/Constants/Pagination.php rename to src/Paginator/Enums/Pagination.php index 8b87c391e..b848bf7af 100644 --- a/src/Paginator/Constants/Pagination.php +++ b/src/Paginator/Enums/Pagination.php @@ -9,10 +9,10 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.6 + * @since 2.9.9 */ -namespace Quantum\Paginator\Constants; +namespace Quantum\Paginator\Enums; /** * Class Pagination diff --git a/src/Paginator/Exceptions/PaginatorException.php b/src/Paginator/Exceptions/PaginatorException.php index f6aca2b33..8f00153df 100644 --- a/src/Paginator/Exceptions/PaginatorException.php +++ b/src/Paginator/Exceptions/PaginatorException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Paginator\Exceptions; +use Quantum\Paginator\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -22,19 +23,14 @@ */ class PaginatorException extends BaseException { + /** * @param string $type - * @param array $missingParams + * @param $missingParam * @return PaginatorException */ - public static function missingRequiredParams(string $type, array $missingParams): PaginatorException + public static function missingRequiredParams(string $type, $missingParam): PaginatorException { - return new static( - t('exception.paginator_missing_params', [ - ucfirst($type), - implode(', ', $missingParams) - ]), - E_WARNING - ); + return new static(_message(ExceptionMessages::MISSING_REQUIRED_PARAMS, [$missingParam, ucfirst($type)]), E_WARNING); } } \ No newline at end of file diff --git a/src/Paginator/Factories/PaginatorFactory.php b/src/Paginator/Factories/PaginatorFactory.php index b58fc5a9d..56f7f355a 100644 --- a/src/Paginator/Factories/PaginatorFactory.php +++ b/src/Paginator/Factories/PaginatorFactory.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Paginator\Factories; @@ -88,7 +88,7 @@ private static function validateRequiredParams(string $type, array $params): voi $missing = array_diff(self::REQUIRED_PARAMS[$type], array_keys($params)); if (!empty($missing)) { - throw PaginatorException::missingRequiredParams($type, $missing); + throw PaginatorException::missingRequiredParams($type, $missing[0]); } } diff --git a/src/Paginator/Traits/PaginatorTrait.php b/src/Paginator/Traits/PaginatorTrait.php index 281798e57..54513cd06 100644 --- a/src/Paginator/Traits/PaginatorTrait.php +++ b/src/Paginator/Traits/PaginatorTrait.php @@ -9,12 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Paginator\Traits; -use Quantum\Paginator\Constants\Pagination; +use Quantum\Paginator\Enums\Pagination; /** * Trait PaginatorTrait diff --git a/src/Router/Enums/ExceptionMessages.php b/src/Router/Enums/ExceptionMessages.php new file mode 100644 index 000000000..9fee0adef --- /dev/null +++ b/src/Router/Enums/ExceptionMessages.php @@ -0,0 +1,48 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\Router\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Router + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const CONTROLLER_NOT_FOUND = 'Controller class `{%1}` not found.'; + + const ACTION_NOT_DEFINED = 'Action `{%1}` not defined"'; + + const ROUTE_NOT_FOUND = 'Route not found'; + + const ROUTE_NOT_CLOSURE = 'Route is not a closure'; + + const REPETITIVE_ROUTE_WITH_SAME_NAME = 'Repetitive Routes with same method `{%1}`'; + + const REPETITIVE_ROUTE_IN_DIFFERENT_MODULES = 'Repetitive Routes in different modules'; + + const INCORRECT_METHOD = 'Incorrect route method `{%1}`'; + + const NAME_BEFORE_ROUTE_DEFINITION = 'Names can not be set before route definition'; + + const NAME_ON_ROUTE_GROUP = 'Name can not be set on route groups'; + + const NAME_NOT_UNIQUE = 'Route names should be unique'; + + const ROUTE_PARAM_NAME_IN_USE = 'Route param name `{%1}` already in use'; + + const INVALID_ROUTE_PARAM_NAME = 'Route param names can only contain letters'; +} \ No newline at end of file diff --git a/src/Router/Exceptions/RouteControllerException.php b/src/Router/Exceptions/RouteControllerException.php index 2da16ad0c..32293957b 100644 --- a/src/Router/Exceptions/RouteControllerException.php +++ b/src/Router/Exceptions/RouteControllerException.php @@ -14,6 +14,7 @@ namespace Quantum\Router\Exceptions; +use Quantum\Router\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -29,7 +30,7 @@ class RouteControllerException extends BaseException */ public static function controllerNotDefined(?string $name): RouteControllerException { - return new static("Controller class `$name` not found.", E_ERROR); + return new static(_message(ExceptionMessages::CONTROLLER_NOT_FOUND, [$name]), E_ERROR); } /** @@ -38,6 +39,6 @@ public static function controllerNotDefined(?string $name): RouteControllerExcep */ public static function actionNotDefined(string $name): RouteControllerException { - return new static("Action `$name` not defined", E_ERROR); + return new static(_message(ExceptionMessages::ACTION_NOT_DEFINED, [$name]), E_ERROR); } } \ No newline at end of file diff --git a/src/Router/Exceptions/RouteException.php b/src/Router/Exceptions/RouteException.php index 85df63f64..833119240 100644 --- a/src/Router/Exceptions/RouteException.php +++ b/src/Router/Exceptions/RouteException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Router\Exceptions; +use Quantum\Router\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -25,9 +26,9 @@ class RouteException extends BaseException /** * @return RouteException */ - public static function notFound(): RouteException + public static function routeNotFound(): RouteException { - return new static(t('exception.route_not_found'), E_ERROR); + return new static(ExceptionMessages::ROUTE_NOT_FOUND, E_ERROR); } /** @@ -35,7 +36,7 @@ public static function notFound(): RouteException */ public static function notClosure(): RouteException { - return new static(t('exception.routes_not_closure'), E_WARNING); + return new static(ExceptionMessages::ROUTE_NOT_CLOSURE, E_WARNING); } /** @@ -44,7 +45,7 @@ public static function notClosure(): RouteException */ public static function repetitiveRouteSameMethod(string $name): RouteException { - return new static(t('exception.repetitive_route_same_method', $name), E_WARNING); + return new static(_message(ExceptionMessages::REPETITIVE_ROUTE_WITH_SAME_NAME, [$name]), E_WARNING); } /** @@ -52,7 +53,7 @@ public static function repetitiveRouteSameMethod(string $name): RouteException */ public static function repetitiveRouteDifferentModules(): RouteException { - return new static(t('exception.repetitive_route_different_modules'), E_WARNING); + return new static(ExceptionMessages::REPETITIVE_ROUTE_IN_DIFFERENT_MODULES, E_WARNING); } /** @@ -61,7 +62,7 @@ public static function repetitiveRouteDifferentModules(): RouteException */ public static function incorrectMethod(?string $name): RouteException { - return new static(t('exception.incorrect_method', $name), E_WARNING); + return new static(_message(ExceptionMessages::INCORRECT_METHOD, [$name]), E_WARNING); } /** @@ -69,7 +70,7 @@ public static function incorrectMethod(?string $name): RouteException */ public static function nameBeforeDefinition(): RouteException { - return new static(t('exception.name_before_route_definition')); + return new static(ExceptionMessages::NAME_BEFORE_ROUTE_DEFINITION, E_WARNING); } /** @@ -77,7 +78,7 @@ public static function nameBeforeDefinition(): RouteException */ public static function nameOnGroup(): RouteException { - return new static(t('exception.name_on_group')); + return new static(ExceptionMessages::NAME_ON_ROUTE_GROUP, E_WARNING); } /** @@ -85,7 +86,7 @@ public static function nameOnGroup(): RouteException */ public static function nonUniqueName(): RouteException { - return new static(t('exception.name_is_not_unique')); + return new static(ExceptionMessages::NAME_NOT_UNIQUE, E_WARNING); } /** @@ -94,7 +95,7 @@ public static function nonUniqueName(): RouteException */ public static function paramNameNotAvailable(string $name): RouteException { - return new static(t('exception.param_name_not_available', $name), E_WARNING); + return new static(_message(ExceptionMessages::ROUTE_PARAM_NAME_IN_USE, [$name]), E_WARNING); } /** @@ -102,6 +103,6 @@ public static function paramNameNotAvailable(string $name): RouteException */ public static function paramNameNotValid(): RouteException { - return new static(t('exception.param_name_not_valid'), E_WARNING); + return new static(ExceptionMessages::INVALID_ROUTE_PARAM_NAME, E_WARNING); } } \ No newline at end of file diff --git a/src/Router/Router.php b/src/Router/Router.php index f65f73e95..d1ecad8c4 100644 --- a/src/Router/Router.php +++ b/src/Router/Router.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Router; @@ -79,7 +79,7 @@ public function findRoute() $uri = $this->request->getUri(); if (!$uri) { - throw RouteException::notFound(); + throw RouteException::routeNotFound(); } $this->matchedRoutes = $this->findMatches($uri); diff --git a/src/Service/Exceptions/ServiceException.php b/src/Service/Exceptions/ServiceException.php index ebf9a2639..7ea4afa17 100644 --- a/src/Service/Exceptions/ServiceException.php +++ b/src/Service/Exceptions/ServiceException.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Service\Exceptions; @@ -22,30 +22,5 @@ */ class ServiceException extends BaseException { - /** - * @param string $name - * @return ServiceException - */ - public static function serviceNotFound(string $name): ServiceException - { - return new static(t('service_not_found', $name), E_ERROR); - } - /** - * @param array $names - * @return ServiceException - */ - public static function notServiceInstance(array $names): ServiceException - { - return new static(t('not_instance_of_service', $names), E_ERROR); - } - - /** - * @param string $name - * @return ServiceException - */ - public static function undefinedMethod(string $name): ServiceException - { - return new static(t('exception.undefined_method', $name), E_ERROR); - } } \ No newline at end of file diff --git a/src/Service/Factories/ServiceFactory.php b/src/Service/Factories/ServiceFactory.php index ab0c68a3e..ee8216410 100644 --- a/src/Service/Factories/ServiceFactory.php +++ b/src/Service/Factories/ServiceFactory.php @@ -9,12 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Service\Factories; use Quantum\Service\Exceptions\ServiceException; +use Quantum\App\Exceptions\BaseException; use Quantum\Di\Exceptions\DiException; use Quantum\Service\QtService; use ReflectionException; @@ -32,9 +33,10 @@ class ServiceFactory * @param string $serviceClass * @param array $args * @return QtService + * @throws BaseException * @throws DiException - * @throws ServiceException * @throws ReflectionException + * @throws ServiceException */ public static function get(string $serviceClass, array $args = []): QtService { @@ -52,6 +54,7 @@ public static function get(string $serviceClass, array $args = []): QtService * @param string $serviceClass * @param array $args * @return QtService + * @throws BaseException * @throws DiException * @throws ReflectionException * @throws ServiceException @@ -68,15 +71,16 @@ public static function create(string $serviceClass, array $args = []): QtService * @param string $serviceClass * @return void * @throws ServiceException + * @throws BaseException */ private static function validate(string $serviceClass): void { if (!class_exists($serviceClass)) { - throw ServiceException::serviceNotFound($serviceClass); + throw ServiceException::notFound('Service', $serviceClass); } if (!is_subclass_of($serviceClass, QtService::class)) { - throw ServiceException::notServiceInstance([$serviceClass, QtService::class]); + throw ServiceException::notInstanceOf($serviceClass, QtService::class); } } } \ No newline at end of file diff --git a/src/Service/QtService.php b/src/Service/QtService.php index 293af9b08..36d64ba1b 100644 --- a/src/Service/QtService.php +++ b/src/Service/QtService.php @@ -9,12 +9,13 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Service; use Quantum\Service\Exceptions\ServiceException; +use Quantum\App\Exceptions\BaseException; /** * Class QtService @@ -27,10 +28,10 @@ class QtService * Handles the missing methods of the service * @param string $method * @param array $arguments - * @throws ServiceException + * @throws BaseException */ public function __call(string $method, array $arguments) { - throw ServiceException::undefinedMethod($method); + throw ServiceException::methodNotSupported($method, QtService::class); } } \ No newline at end of file diff --git a/src/View/Enums/ExceptionMessages.php b/src/View/Enums/ExceptionMessages.php new file mode 100644 index 000000000..0dff4372e --- /dev/null +++ b/src/View/Enums/ExceptionMessages.php @@ -0,0 +1,28 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 2.9.9 + */ + +namespace Quantum\View\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\View + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const LAYOUT_NOT_SET = 'Layout is not set.'; + + const VIEW_NOT_RENDERED_YET = 'View not rendered yet.'; +} \ No newline at end of file diff --git a/src/View/Exceptions/ViewException.php b/src/View/Exceptions/ViewException.php index 9d0b0de08..43791bdac 100644 --- a/src/View/Exceptions/ViewException.php +++ b/src/View/Exceptions/ViewException.php @@ -9,11 +9,12 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\View\Exceptions; +use Quantum\View\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** @@ -22,21 +23,13 @@ */ class ViewException extends BaseException { - /** - * @param string $name - * @return ViewException - */ - public static function directInstantiation(string $name): ViewException - { - return new static(t('exception.direct_view_instance', $name), E_WARNING); - } /** * @return ViewException */ public static function noLayoutSet(): ViewException { - return new static(t('exception.layout_not_set'), E_ERROR); + return new static(ExceptionMessages::LAYOUT_NOT_SET, E_ERROR); } /** @@ -44,6 +37,6 @@ public static function noLayoutSet(): ViewException */ public static function viewNotRendered(): ViewException { - return new static(t('exception.view_not_rendered_yet'), E_ERROR); + return new static(ExceptionMessages::VIEW_NOT_RENDERED_YET, E_ERROR); } } From 6d3d4aa1c6628a592704633e170bd0110ab797fa Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Thu, 11 Dec 2025 20:19:55 +0400 Subject: [PATCH 2/4] Updating unit tests related to Exceptions changes --- tests/Unit/App/Factories/AppFactoryTest.php | 2 +- tests/Unit/Di/DiTest.php | 12 ++++++------ tests/Unit/Hook/Helpers/HookHelperTest.php | 4 ++-- tests/Unit/Hook/HookManagerTest.php | 4 ++-- tests/Unit/Http/ResponseTest.php | 2 +- .../Archive/Factories/ArchiveFactoryTest.php | 2 +- .../Libraries/Auth/Adapters/JwtAuthAdapterTest.php | 7 ++++--- .../Auth/Adapters/SessionAuthAdapterTest.php | 5 +++-- .../Libraries/Auth/Factories/AuthFactoryTest.php | 4 ++-- .../Captcha/Factories/CaptchaFactoryTest.php | 2 +- tests/Unit/Libraries/Csrf/CsrfTest.php | 5 +++-- .../Adapters/Idiorm/Statements/JoinIdiormTest.php | 2 +- .../Adapters/Sleekdb/Statements/JoinSleekTest.php | 4 ++-- .../Database/Factories/TableFactoryTest.php | 10 +++++----- tests/Unit/Libraries/Database/Schema/ColumnTest.php | 2 +- tests/Unit/Libraries/Database/Schema/TableTest.php | 4 ++-- .../Adapters/AsymmetricEncryptionAdapterTest.php | 5 +++-- .../Encryption/Factories/CryptorFactoryTest.php | 2 +- tests/Unit/Libraries/HttpClient/HttpClientTest.php | 2 +- .../Libraries/Logger/Factories/LoggerFactoryTest.php | 4 ++-- .../Logger/Helpers/LoggerHelperFunctionsTest.php | 2 +- .../Libraries/Mailer/Factories/MailerFactoryTest.php | 2 +- .../Session/Factories/SessionFactoryTest.php | 2 +- .../Storage/Factories/FileSystemFactoryTest.php | 2 +- tests/Unit/Libraries/Storage/UploadedFileTest.php | 6 ++++-- tests/Unit/Model/Factories/ModelFactoryTest.php | 4 ++-- tests/Unit/Model/QtModelTest.php | 4 ++-- .../Paginator/Factories/PaginatorFactoryTest.php | 2 +- .../Unit/Renderer/Factories/RendererFactoryTest.php | 2 +- tests/Unit/Router/RouteTest.php | 6 +++--- tests/Unit/Router/RouterTest.php | 8 ++++---- tests/Unit/Service/Factories/ServiceFactoryTest.php | 2 +- tests/Unit/Service/QtServiceTest.php | 3 ++- tests/Unit/View/QtViewTest.php | 2 +- 34 files changed, 69 insertions(+), 62 deletions(-) diff --git a/tests/Unit/App/Factories/AppFactoryTest.php b/tests/Unit/App/Factories/AppFactoryTest.php index 448e8c512..42f7e571f 100644 --- a/tests/Unit/App/Factories/AppFactoryTest.php +++ b/tests/Unit/App/Factories/AppFactoryTest.php @@ -53,7 +53,7 @@ public function testAppFactoryInvalidAdapter() { $this->expectException(AppException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); AppFactory::create('invalid_type', PROJECT_ROOT); } diff --git a/tests/Unit/Di/DiTest.php b/tests/Unit/Di/DiTest.php index 810275f7e..2808e253f 100644 --- a/tests/Unit/Di/DiTest.php +++ b/tests/Unit/Di/DiTest.php @@ -82,7 +82,7 @@ public function testDiAttemptingToRegisterAlreadyRegisteredDependency(): void { $this->expectException(DiException::class); - $this->expectExceptionMessage('exception.dependency_already_registered'); + $this->expectExceptionMessage('The dependency `Quantum\Loader\Setup` is already registered.'); Di::register(Setup::class); Di::register(Setup::class); @@ -91,7 +91,7 @@ public function testDiAttemptingToRegisterAlreadyRegisteredDependency(): void public function testDiAttemptingToRegisterNonExistentClass(): void { $this->expectException(DiException::class); - $this->expectExceptionMessage('exception.dependency_not_instantiable'); + $this->expectExceptionMessage('The dependency `NonExistentClass` is not instantiable.'); Di::register('NonExistentClass'); } @@ -99,7 +99,7 @@ public function testDiAttemptingToRegisterNonExistentClass(): void public function testDiAttemptingToRegisterNonExistentAbstract(): void { $this->expectException(DiException::class); - $this->expectExceptionMessage('exception.invalid_abstract_dependency'); + $this->expectExceptionMessage('The dependency `NonExistentInterface` is not valid abstract class.'); Di::register(DummyService::class, 'NonExistentInterface'); } @@ -137,7 +137,7 @@ public function testDiAttemptingToGetNotRegisteredDependency() $this->expectException(DiException::class); - $this->expectExceptionMessage('dependency_not_registered'); + $this->expectExceptionMessage('The dependency `Quantum\Di\Exceptions\DiException` is not registered.'); Di::get(DiException::class); } @@ -147,9 +147,9 @@ public function testDiCircularDependencyDetectedAtResolve(): void $this->expectException(DiException::class); $this->expectExceptionMessage( - 'Circular dependency detected: ' . CircularDependencyA::class . + 'Circular dependency detected: `' . CircularDependencyA::class . ' -> ' . CircularDependencyB::class . - ' -> ' . CircularDependencyA::class + ' -> ' . CircularDependencyA::class . '`' ); Di::register(CircularDependencyA::class); diff --git a/tests/Unit/Hook/Helpers/HookHelperTest.php b/tests/Unit/Hook/Helpers/HookHelperTest.php index ae5f8e129..cbc22abc6 100644 --- a/tests/Unit/Hook/Helpers/HookHelperTest.php +++ b/tests/Unit/Hook/Helpers/HookHelperTest.php @@ -60,7 +60,7 @@ public function testUnregisteredHookAtOn() { $this->expectException(HookException::class); - $this->expectExceptionMessage('unregistered_hook_name'); + $this->expectExceptionMessage('The Hook `SOME_EVENT` was not registered.'); hook()->on('SOME_EVENT', function () { echo 'Do someting'; @@ -71,7 +71,7 @@ public function testUnregisteredHookAtFire() { $this->expectException(HookException::class); - $this->expectExceptionMessage('unregistered_hook_name'); + $this->expectExceptionMessage('The Hook `SOME_EVENT` was not registered.'); hook()->fire('SOME_EVENT'); } diff --git a/tests/Unit/Hook/HookManagerTest.php b/tests/Unit/Hook/HookManagerTest.php index 0a0053e40..ffb1d5b7b 100644 --- a/tests/Unit/Hook/HookManagerTest.php +++ b/tests/Unit/Hook/HookManagerTest.php @@ -79,7 +79,7 @@ public function testHookIsFiredOnlyOncePerListener() public function testUnregisteredHookThrowsOnOn() { $this->expectException(HookException::class); - $this->expectExceptionMessage('unregistered_hook_name'); + $this->expectExceptionMessage('The Hook `INVALID` was not registered.'); hook()->on('INVALID', function () {}); } @@ -87,7 +87,7 @@ public function testUnregisteredHookThrowsOnOn() public function testUnregisteredHookThrowsOnFire() { $this->expectException(HookException::class); - $this->expectExceptionMessage('unregistered_hook_name'); + $this->expectExceptionMessage('The Hook `INVALID` was not registered.'); hook()->fire('INVALID'); } diff --git a/tests/Unit/Http/ResponseTest.php b/tests/Unit/Http/ResponseTest.php index 3ad628e1b..1110799a6 100644 --- a/tests/Unit/Http/ResponseTest.php +++ b/tests/Unit/Http/ResponseTest.php @@ -2,7 +2,7 @@ namespace Quantum\Tests\Unit\Http; -use Quantum\Http\Constants\ContentType; +use Quantum\Http\Enums\ContentType; use Quantum\Tests\Unit\AppTestCase; use Quantum\Http\Response; use Throwable; diff --git a/tests/Unit/Libraries/Archive/Factories/ArchiveFactoryTest.php b/tests/Unit/Libraries/Archive/Factories/ArchiveFactoryTest.php index 445265226..90ccb7417 100644 --- a/tests/Unit/Libraries/Archive/Factories/ArchiveFactoryTest.php +++ b/tests/Unit/Libraries/Archive/Factories/ArchiveFactoryTest.php @@ -47,7 +47,7 @@ public function testArchiveFactoryInvalidAdapter() { $this->expectException(ArchiveException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); ArchiveFactory::get('invalid_type'); } diff --git a/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php b/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php index ea3e3614f..05c6cc6d5 100644 --- a/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php +++ b/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php @@ -2,8 +2,9 @@ namespace Quantum\Tests\Unit\Libraries\Auth\Adapters; -use Quantum\Libraries\Auth\Adapters\JwtAuthAdapter; use Quantum\Libraries\Auth\Exceptions\AuthException; +use Quantum\Libraries\Auth\Adapters\JwtAuthAdapter; +use Quantum\Libraries\Auth\Enums\ExceptionMessages; use Quantum\Tests\Unit\Libraries\Auth\AuthTestCase; use Quantum\Libraries\Hasher\Hasher; use Quantum\Libraries\Jwt\JwtToken; @@ -54,7 +55,7 @@ public function testApiSigninIncorrectCredentials() { $this->expectException(AuthException::class); - $this->expectExceptionMessage('incorrect_auth_credentials'); + $this->expectExceptionMessage(ExceptionMessages::INCORRECT_CREDENTIALS); $this->jwtAuth->signin('admin@qt.com', '111111'); } @@ -113,7 +114,7 @@ public function testApiSignupAndSigninWithoutActivation() { $this->expectException(AuthException::class); - $this->expectExceptionMessage('inactive_account'); + $this->expectExceptionMessage(ExceptionMessages::INACTIVE_ACCOUNT); $this->jwtAuth->signup($this->guestUser); diff --git a/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php b/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php index f027fcf6b..a2d33a75b 100644 --- a/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php +++ b/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php @@ -4,6 +4,7 @@ use Quantum\Libraries\Auth\Adapters\SessionAuthAdapter; use Quantum\Libraries\Auth\Exceptions\AuthException; +use Quantum\Libraries\Auth\Enums\ExceptionMessages; use Quantum\Tests\Unit\Libraries\Auth\AuthTestCase; use Quantum\Libraries\Hasher\Hasher; use Quantum\Libraries\Auth\User; @@ -42,7 +43,7 @@ public function testWebSigninIncorrectCredentials() { $this->expectException(AuthException::class); - $this->expectExceptionMessage('incorrect_auth_credentials'); + $this->expectExceptionMessage(ExceptionMessages::INCORRECT_CREDENTIALS); $this->sessionAuth->signin('admin@qt.com', '111111'); } @@ -101,7 +102,7 @@ public function testWebSignupAndSigninWithoutActivation() $this->expectException(AuthException::class); - $this->expectExceptionMessage('inactive_account'); + $this->expectExceptionMessage(ExceptionMessages::INACTIVE_ACCOUNT); $this->sessionAuth->signup($this->guestUser); diff --git a/tests/Unit/Libraries/Auth/Factories/AuthFactoryTest.php b/tests/Unit/Libraries/Auth/Factories/AuthFactoryTest.php index 2dab18510..9368a78a2 100644 --- a/tests/Unit/Libraries/Auth/Factories/AuthFactoryTest.php +++ b/tests/Unit/Libraries/Auth/Factories/AuthFactoryTest.php @@ -3,8 +3,8 @@ namespace Quantum\Tests\Unit\Libraries\Auth\Factories; use Quantum\Libraries\Auth\Adapters\SessionAuthAdapter; -use Quantum\Libraries\Auth\Adapters\JwtAuthAdapter; use Quantum\Libraries\Auth\Exceptions\AuthException; +use Quantum\Libraries\Auth\Adapters\JwtAuthAdapter; use Quantum\Libraries\Auth\Factories\AuthFactory; use Quantum\Tests\Unit\AppTestCase; use Quantum\Libraries\Auth\Auth; @@ -53,7 +53,7 @@ public function testAuthFactoryInvalidTypeAdapter() $this->expectException(AuthException::class); - $this->expectExceptionMessage('The adapter `invalid` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid` is not supported'); AuthFactory::get(); } diff --git a/tests/Unit/Libraries/Captcha/Factories/CaptchaFactoryTest.php b/tests/Unit/Libraries/Captcha/Factories/CaptchaFactoryTest.php index 5960f2228..4a9df0fb1 100644 --- a/tests/Unit/Libraries/Captcha/Factories/CaptchaFactoryTest.php +++ b/tests/Unit/Libraries/Captcha/Factories/CaptchaFactoryTest.php @@ -51,7 +51,7 @@ public function testCacheFactoryInvalidTypeAdapter() { $this->expectException(CaptchaException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); CaptchaFactory::get('invalid_type'); } diff --git a/tests/Unit/Libraries/Csrf/CsrfTest.php b/tests/Unit/Libraries/Csrf/CsrfTest.php index db674579d..ab77ebd36 100644 --- a/tests/Unit/Libraries/Csrf/CsrfTest.php +++ b/tests/Unit/Libraries/Csrf/CsrfTest.php @@ -3,6 +3,7 @@ namespace Quantum\Tests\Unit\Libraries\Csrf; use Quantum\Libraries\Csrf\Exceptions\CsrfException; +use Quantum\Libraries\Csrf\Enums\ExceptionMessages; use Quantum\Tests\Unit\AppTestCase; use Quantum\Libraries\Csrf\Csrf; use Quantum\Http\Request; @@ -57,7 +58,7 @@ public function testCheckTokenMissing() $this->expectException(CsrfException::class); - $this->expectExceptionMessage('csrf_token_not_found'); + $this->expectExceptionMessage(ExceptionMessages::CSRF_TOKEN_MISSING); $this->assertTrue($this->csrf->checkToken($this->request)); } @@ -74,7 +75,7 @@ public function testCheckTokenMismatch() $this->expectException(CsrfException::class); - $this->expectExceptionMessage('csrf_token_not_matched'); + $this->expectExceptionMessage(ExceptionMessages::CSRF_TOKEN_MISMATCH); $this->assertTrue($this->csrf->checkToken($this->request)); } diff --git a/tests/Unit/Libraries/Database/Adapters/Idiorm/Statements/JoinIdiormTest.php b/tests/Unit/Libraries/Database/Adapters/Idiorm/Statements/JoinIdiormTest.php index e42cc9de6..1f97acdfe 100644 --- a/tests/Unit/Libraries/Database/Adapters/Idiorm/Statements/JoinIdiormTest.php +++ b/tests/Unit/Libraries/Database/Adapters/Idiorm/Statements/JoinIdiormTest.php @@ -267,7 +267,7 @@ public function testIdiormWrongRelation() { $this->expectException(ModelException::class); - $this->expectExceptionMessage('wrong_relation'); + $this->expectExceptionMessage('The model `' . TestTicketModel::class . '` does not define relation with `' . TestEventModel::class . '`'); $eventModel = ModelFactory::get(TestEventModel::class); diff --git a/tests/Unit/Libraries/Database/Adapters/Sleekdb/Statements/JoinSleekTest.php b/tests/Unit/Libraries/Database/Adapters/Sleekdb/Statements/JoinSleekTest.php index 29cbe0809..e744930f9 100644 --- a/tests/Unit/Libraries/Database/Adapters/Sleekdb/Statements/JoinSleekTest.php +++ b/tests/Unit/Libraries/Database/Adapters/Sleekdb/Statements/JoinSleekTest.php @@ -4,8 +4,8 @@ use Quantum\Tests\Unit\Libraries\Database\Adapters\Sleekdb\SleekDbalTestCase; use Quantum\Tests\_root\shared\Models\TestUserProfessionModel; -use Quantum\Tests\_root\shared\Models\TestUserEventModel; use Quantum\Tests\_root\shared\Models\TestUserMeetingModel; +use Quantum\Tests\_root\shared\Models\TestUserEventModel; use Quantum\Tests\_root\shared\Models\TestTicketModel; use Quantum\Tests\_root\shared\Models\TestEventModel; use Quantum\Tests\_root\shared\Models\TestNotesModel; @@ -179,7 +179,7 @@ public function testSleekWrongRelation() { $this->expectException(ModelException::class); - $this->expectExceptionMessage('wrong_relation'); + $this->expectExceptionMessage('The model `' . TestNotesModel::class . '` does not define relation with `' . TestEventModel::class . '`'); $eventModel = ModelFactory::get(TestEventModel::class); diff --git a/tests/Unit/Libraries/Database/Factories/TableFactoryTest.php b/tests/Unit/Libraries/Database/Factories/TableFactoryTest.php index 4dcf06408..986c2680f 100644 --- a/tests/Unit/Libraries/Database/Factories/TableFactoryTest.php +++ b/tests/Unit/Libraries/Database/Factories/TableFactoryTest.php @@ -77,9 +77,9 @@ public function testAttemptToCreateTableWhichAlreadyExists() $this->expectException(DatabaseException::class); - $this->expectExceptionMessage('table_already_exists'); + $this->expectExceptionMessage('The table `users` is already exists'); - $table = $this->tableFactory->create('users'); + $this->tableFactory->create('users'); } public function testGetTable() @@ -102,7 +102,7 @@ public function testAttemptToGetNonExistingTable() { $this->expectException(DatabaseException::class); - $this->expectExceptionMessage('table_does_not_exists'); + $this->expectExceptionMessage('The table `users` does not exists'); $table = $this->tableFactory->get('users'); } @@ -125,7 +125,7 @@ public function testAttemptToRenameNonExistingTable() { $this->expectException(DatabaseException::class); - $this->expectExceptionMessage('table_does_not_exists'); + $this->expectExceptionMessage('The table `users` does not exists'); $this->tableFactory->rename('users', 'system_users'); } @@ -148,7 +148,7 @@ public function testAttemptToDropNonExistingTable() { $this->expectException(DatabaseException::class); - $this->expectExceptionMessage('table_does_not_exists'); + $this->expectExceptionMessage('The table `users` does not exists'); $this->tableFactory->drop('users', 'system_users'); } diff --git a/tests/Unit/Libraries/Database/Schema/ColumnTest.php b/tests/Unit/Libraries/Database/Schema/ColumnTest.php index 041910559..55360be80 100644 --- a/tests/Unit/Libraries/Database/Schema/ColumnTest.php +++ b/tests/Unit/Libraries/Database/Schema/ColumnTest.php @@ -2,8 +2,8 @@ namespace Quantum\Tests\Unit\Libraries\Database\Schema; -use Quantum\Libraries\Database\Constants\Type; use Quantum\Libraries\Database\Schemas\Column; +use Quantum\Libraries\Database\Enums\Type; use PHPUnit\Framework\TestCase; class ColumnTest extends TestCase diff --git a/tests/Unit/Libraries/Database/Schema/TableTest.php b/tests/Unit/Libraries/Database/Schema/TableTest.php index bc262ae01..17a0aa66c 100644 --- a/tests/Unit/Libraries/Database/Schema/TableTest.php +++ b/tests/Unit/Libraries/Database/Schema/TableTest.php @@ -2,10 +2,10 @@ namespace Quantum\Tests\Unit\Libraries\Database\Schema; -use Quantum\Libraries\Database\Constants\Type; use Quantum\Libraries\Database\Schemas\Column; -use Quantum\Libraries\Database\Constants\Key; use Quantum\Libraries\Database\Schemas\Table; +use Quantum\Libraries\Database\Enums\Type; +use Quantum\Libraries\Database\Enums\Key; use PHPUnit\Framework\TestCase; use Mockery; diff --git a/tests/Unit/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapterTest.php b/tests/Unit/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapterTest.php index 30dee14cf..e9e84b587 100644 --- a/tests/Unit/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapterTest.php +++ b/tests/Unit/Libraries/Encryption/Adapters/AsymmetricEncryptionAdapterTest.php @@ -4,6 +4,7 @@ use Quantum\Libraries\Encryption\Adapters\AsymmetricEncryptionAdapter; use Quantum\Libraries\Encryption\Exceptions\CryptorException; +use Quantum\Libraries\Encryption\Enums\ExceptionMessages; use Quantum\Tests\Unit\AppTestCase; use ReflectionClass; @@ -48,7 +49,7 @@ public function testAsymmetricEncryptionAdapterWithoutPublicKey() $instanceProperty->setValue($adapterInstance, null); $this->expectException(CryptorException::class); - $this->expectExceptionMessage("exception.openssl_public_key_not_provided"); + $this->expectExceptionMessage(ExceptionMessages::PUBLIC_KEY_MISSING); $adapterInstance->encrypt("Some text"); } @@ -63,7 +64,7 @@ public function testAsymmetricEncryptionAdapterDecryptWithoutPrivateKey() $instanceProperty->setValue($adapterInstance, null); $this->expectException(CryptorException::class); - $this->expectExceptionMessage("exception.openssl_private_key_not_provided"); + $this->expectExceptionMessage(ExceptionMessages::PRIVATE_KEY_MISSING); $adapterInstance->decrypt("Some encrypted text"); } diff --git a/tests/Unit/Libraries/Encryption/Factories/CryptorFactoryTest.php b/tests/Unit/Libraries/Encryption/Factories/CryptorFactoryTest.php index 3aa4b22ee..78576b9f3 100644 --- a/tests/Unit/Libraries/Encryption/Factories/CryptorFactoryTest.php +++ b/tests/Unit/Libraries/Encryption/Factories/CryptorFactoryTest.php @@ -47,7 +47,7 @@ public function testCryptorFactoryInvalidTypeAdapter() { $this->expectException(CryptorException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); CryptorFactory::get('invalid_type'); } diff --git a/tests/Unit/Libraries/HttpClient/HttpClientTest.php b/tests/Unit/Libraries/HttpClient/HttpClientTest.php index 280a80289..1e21b5452 100644 --- a/tests/Unit/Libraries/HttpClient/HttpClientTest.php +++ b/tests/Unit/Libraries/HttpClient/HttpClientTest.php @@ -32,7 +32,7 @@ public function testHttpClientGetSetMethod() $this->expectException(HttpClientException::class); - $this->expectExceptionMessage('exception.method_not_available'); + $this->expectExceptionMessage('Provided request method `NOPE` is not available.'); $this->httpClient->setMethod('NOPE'); } diff --git a/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php b/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php index 4973cdbbe..26b18cdb8 100644 --- a/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php +++ b/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php @@ -72,7 +72,7 @@ public function testLoggerFactoryTryingToGetMessageAdapter() { $this->expectException(LoggerException::class); - $this->expectExceptionMessage('exception.message_logger_not_in_debug_mode'); + $this->expectExceptionMessage('The adapter `message` is not supported.'); LoggerFactory::get(Logger::MESSAGE); } @@ -81,7 +81,7 @@ public function testLoggerFactoryInvalidTypeAdapter() { $this->expectException(LoggerException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); LoggerFactory::get('invalid_type'); } diff --git a/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php b/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php index 8dd53a647..ef5c244ec 100644 --- a/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php +++ b/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php @@ -82,7 +82,7 @@ public function testLoggerHelperTryToGetMessageLoggerAdapterInNonDebugMode() $this->expectException(LoggerException::class); - $this->expectExceptionMessage('exception.message_logger_not_in_debug_mode'); + $this->expectExceptionMessage('The adapter `message` is not supported'); logger(Logger::MESSAGE); } diff --git a/tests/Unit/Libraries/Mailer/Factories/MailerFactoryTest.php b/tests/Unit/Libraries/Mailer/Factories/MailerFactoryTest.php index 80cdbc184..92a3c7069 100644 --- a/tests/Unit/Libraries/Mailer/Factories/MailerFactoryTest.php +++ b/tests/Unit/Libraries/Mailer/Factories/MailerFactoryTest.php @@ -80,7 +80,7 @@ public function testMailerFactoryGetInvalidTypeAdapter() { $this->expectException(MailerException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); MailerFactory::get('invalid_type'); } diff --git a/tests/Unit/Libraries/Session/Factories/SessionFactoryTest.php b/tests/Unit/Libraries/Session/Factories/SessionFactoryTest.php index 7bc50a21b..43278c463 100644 --- a/tests/Unit/Libraries/Session/Factories/SessionFactoryTest.php +++ b/tests/Unit/Libraries/Session/Factories/SessionFactoryTest.php @@ -107,7 +107,7 @@ public function testSessionFactoryInvalidTypeAdapter() { $this->expectException(SessionException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); SessionFactory::get('invalid_type'); } diff --git a/tests/Unit/Libraries/Storage/Factories/FileSystemFactoryTest.php b/tests/Unit/Libraries/Storage/Factories/FileSystemFactoryTest.php index c17ec5957..3872f0710 100644 --- a/tests/Unit/Libraries/Storage/Factories/FileSystemFactoryTest.php +++ b/tests/Unit/Libraries/Storage/Factories/FileSystemFactoryTest.php @@ -58,7 +58,7 @@ public function testFileSystemFactoryInvalidTypeAdapter() { $this->expectException(FileSystemException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); FileSystemFactory::get('invalid_type'); } diff --git a/tests/Unit/Libraries/Storage/UploadedFileTest.php b/tests/Unit/Libraries/Storage/UploadedFileTest.php index 21e229d32..fc14f4d5a 100644 --- a/tests/Unit/Libraries/Storage/UploadedFileTest.php +++ b/tests/Unit/Libraries/Storage/UploadedFileTest.php @@ -152,11 +152,13 @@ public function testUploadedFileSaveAndTryOverwrite() $uploadedFile->save(base_dir()); - $this->assertTrue(file_exists(base_dir() . DS . $uploadedFile->getNameWithExtension())); + $filePath = base_dir() . DS . $uploadedFile->getNameWithExtension(); + + $this->assertTrue(file_exists($filePath)); $this->expectException(FileSystemException::class); - $this->expectExceptionMessage('exception.file_already_exists'); + $this->expectExceptionMessage('The file ' . $filePath . ' already exists'); $uploadedFile->save(base_dir()); } diff --git a/tests/Unit/Model/Factories/ModelFactoryTest.php b/tests/Unit/Model/Factories/ModelFactoryTest.php index 708e5c5ca..56b2c5c4e 100644 --- a/tests/Unit/Model/Factories/ModelFactoryTest.php +++ b/tests/Unit/Model/Factories/ModelFactoryTest.php @@ -34,7 +34,7 @@ public function testModelFactoryGetNonExistingModel() { $this->expectException(ModelException::class); - $this->expectExceptionMessage('model_not_found'); + $this->expectExceptionMessage('Model `NonExistentClass` not found'); ModelFactory::get(\NonExistentClass::class); } @@ -43,7 +43,7 @@ public function testModelFactoryModelNotInstanceOfQtModel() { $this->expectException(ModelException::class); - $this->expectExceptionMessage('not_instance_of_model'); + $this->expectExceptionMessage('The `Mockery\Undefined` is not instance of `Quantum\Model\QtModel`'); ModelFactory::get(\Mockery\Undefined::class); } diff --git a/tests/Unit/Model/QtModelTest.php b/tests/Unit/Model/QtModelTest.php index bb1df3740..34a80d66e 100644 --- a/tests/Unit/Model/QtModelTest.php +++ b/tests/Unit/Model/QtModelTest.php @@ -117,7 +117,7 @@ public function testQtModelFillObjectPropsWithUndefinedFillable() { $this->expectException(ModelException::class); - $this->expectExceptionMessage('inappropriate_property'); + $this->expectExceptionMessage('Inappropriate property `country` for fillable object'); $this->model->fillObjectProps(['country' => 'Ireland']); } @@ -135,7 +135,7 @@ public function testQtModelCallingUndefinedModelMethod() { $this->expectException(ModelException::class); - $this->expectExceptionMessage('undefined_model_method'); + $this->expectExceptionMessage('The method `undefinedMethod` is not supported for `' . IdiormDbal::class . '`'); $this->model->undefinedMethod(); } diff --git a/tests/Unit/Paginator/Factories/PaginatorFactoryTest.php b/tests/Unit/Paginator/Factories/PaginatorFactoryTest.php index fc8cc2d9c..dd09173c5 100644 --- a/tests/Unit/Paginator/Factories/PaginatorFactoryTest.php +++ b/tests/Unit/Paginator/Factories/PaginatorFactoryTest.php @@ -65,7 +65,7 @@ public function testPaginatorFactoryInvalidAdapter() { $this->expectException(PaginatorException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); PaginatorFactory::create('invalid_type', [ 'items' => [], diff --git a/tests/Unit/Renderer/Factories/RendererFactoryTest.php b/tests/Unit/Renderer/Factories/RendererFactoryTest.php index 74d090871..0934bde9a 100644 --- a/tests/Unit/Renderer/Factories/RendererFactoryTest.php +++ b/tests/Unit/Renderer/Factories/RendererFactoryTest.php @@ -58,7 +58,7 @@ public function testRendererFactoryInvalidTypeAdapter() { $this->expectException(RendererException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); RendererFactory::get('invalid_type'); } diff --git a/tests/Unit/Router/RouteTest.php b/tests/Unit/Router/RouteTest.php index 93b47b5e9..6f7e866e5 100644 --- a/tests/Unit/Router/RouteTest.php +++ b/tests/Unit/Router/RouteTest.php @@ -229,7 +229,7 @@ public function testNamingRouteBeforeDefinition() { $this->expectException(RouteException::class); - $this->expectExceptionMessage('exception.name_before_route_definition'); + $this->expectExceptionMessage('Names can not be set before route definition'); $this->route->name('myposts')->get('my-posts', 'PostController', 'myPosts'); } @@ -238,7 +238,7 @@ public function testDuplicateNamesOnRoutes() { $this->expectException(RouteException::class); - $this->expectExceptionMessage('exception.name_is_not_unique'); + $this->expectExceptionMessage('Route names should be unique'); $this->route->post('post/1', 'PostController', 'getPost')->name('post'); @@ -249,7 +249,7 @@ public function testNameOnGroup() { $this->expectException(RouteException::class); - $this->expectExceptionMessage('exception.name_on_group'); + $this->expectExceptionMessage('Name can not be set on route groups'); $this->route->group('auth', function ($route) { $route->add('dashboard', 'GET', 'AuthController', 'dashboard'); diff --git a/tests/Unit/Router/RouterTest.php b/tests/Unit/Router/RouterTest.php index c3fdbbc1e..f69a65c23 100644 --- a/tests/Unit/Router/RouterTest.php +++ b/tests/Unit/Router/RouterTest.php @@ -224,7 +224,7 @@ public function testRouteIncorrectMethod() $this->expectException(RouteException::class); - $this->expectExceptionMessage('incorrect_method'); + $this->expectExceptionMessage('Incorrect route method `GET`'); $this->router->findRoute(); } @@ -252,7 +252,7 @@ public function testRepetitiveRoutesWithSameMethod() $this->expectException(RouteException::class); - $this->expectExceptionMessage('repetitive_route_same_method'); + $this->expectExceptionMessage('Repetitive Routes with same method `POST`'); $this->router->findRoute(); } @@ -280,7 +280,7 @@ public function testRepetitiveRoutesInDifferentModules() $this->expectException(RouteException::class); - $this->expectExceptionMessage('repetitive_route_different_modules'); + $this->expectExceptionMessage('Repetitive Routes in different modules'); $this->router->findRoute(); } @@ -291,7 +291,7 @@ public function testRouteNotFound() $this->expectException(StopExecutionException::class); - $this->expectExceptionMessage('execution_terminated'); + $this->expectExceptionMessage('Execution was terminated'); $this->router->findRoute(); } diff --git a/tests/Unit/Service/Factories/ServiceFactoryTest.php b/tests/Unit/Service/Factories/ServiceFactoryTest.php index ee55fe939..cad3b7c8a 100644 --- a/tests/Unit/Service/Factories/ServiceFactoryTest.php +++ b/tests/Unit/Service/Factories/ServiceFactoryTest.php @@ -120,7 +120,7 @@ public function testServiceFactoryServiceNotFound() { $this->expectException(ServiceException::class); - $this->expectExceptionMessage('service_not_found'); + $this->expectExceptionMessage('Service `NonExistentClass` not found'); ServiceFactory::get(\NonExistentClass::class); } diff --git a/tests/Unit/Service/QtServiceTest.php b/tests/Unit/Service/QtServiceTest.php index 3f21ecf64..3f500c069 100644 --- a/tests/Unit/Service/QtServiceTest.php +++ b/tests/Unit/Service/QtServiceTest.php @@ -17,6 +17,7 @@ class TestingService extends QtService use Quantum\Service\Factories\ServiceFactory; use Quantum\Services\TestingService; use Quantum\Tests\Unit\AppTestCase; + use Quantum\Service\QtService; /** * @runTestsInSeparateProcesses @@ -34,7 +35,7 @@ public function testMissingMethods() { $this->expectException(ServiceException::class); - $this->expectExceptionMessage('undefined_method'); + $this->expectExceptionMessage('The method `undefinedMethod` is not supported for `' . QtService::class . '`'); $service = (new ServiceFactory)->get(TestingService::class); diff --git a/tests/Unit/View/QtViewTest.php b/tests/Unit/View/QtViewTest.php index e121ddae9..a2ec637b7 100644 --- a/tests/Unit/View/QtViewTest.php +++ b/tests/Unit/View/QtViewTest.php @@ -98,7 +98,7 @@ public function testRenderWithoutLayout() { $this->expectException(ViewException::class); - $this->expectExceptionMessage('layout_not_set'); + $this->expectExceptionMessage('Layout is not set'); $this->view->render('index'); } From af25eb1989e03a275b75605fa621d321eb3c889f Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Thu, 11 Dec 2025 20:38:28 +0400 Subject: [PATCH 3/4] Fixing minor typo --- tests/Unit/Libraries/Cache/Factories/CacheFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Libraries/Cache/Factories/CacheFactoryTest.php b/tests/Unit/Libraries/Cache/Factories/CacheFactoryTest.php index 4b0253ac5..9fb379b7d 100644 --- a/tests/Unit/Libraries/Cache/Factories/CacheFactoryTest.php +++ b/tests/Unit/Libraries/Cache/Factories/CacheFactoryTest.php @@ -67,7 +67,7 @@ public function testCacheFactoryInvalidTypeAdapter() { $this->expectException(CacheException::class); - $this->expectExceptionMessage('The adapter `invalid_type` is not supported`'); + $this->expectExceptionMessage('The adapter `invalid_type` is not supported'); CacheFactory::get('invalid_type'); } From 0256f7d9be3ef83ce320e8b70cca87e65b60705a Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:21:30 +0400 Subject: [PATCH 4/4] Minor fixes on ExceptionMessages and tiny refactoring on ViewCache and ViewCacheTest --- .../Hasher/Enums/ExceptionMessages.php | 4 --- .../ResourceCache/Enums/ExceptionMessages.php | 26 --------------- .../Exceptions/ResourceCacheException.php | 14 ++------ src/Libraries/ResourceCache/ViewCache.php | 14 ++++++-- .../Libraries/ResourceCache/ViewCacheTest.php | 32 +++++++++++++++++++ 5 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 src/Libraries/ResourceCache/Enums/ExceptionMessages.php diff --git a/src/Libraries/Hasher/Enums/ExceptionMessages.php b/src/Libraries/Hasher/Enums/ExceptionMessages.php index 27c7d4dbb..5e1608f03 100644 --- a/src/Libraries/Hasher/Enums/ExceptionMessages.php +++ b/src/Libraries/Hasher/Enums/ExceptionMessages.php @@ -25,8 +25,4 @@ final class ExceptionMessages extends BaseExceptionMessages const ALGORITHM_NOT_SUPPORTED = 'The algorithm {%1} not supported.'; const INVALID_BCRYPT_COST = 'Provided bcrypt cost is invalid.'; - - - - } \ No newline at end of file diff --git a/src/Libraries/ResourceCache/Enums/ExceptionMessages.php b/src/Libraries/ResourceCache/Enums/ExceptionMessages.php deleted file mode 100644 index 7c61d38be..000000000 --- a/src/Libraries/ResourceCache/Enums/ExceptionMessages.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) - * @link http://quantum.softberg.org/ - * @since 2.9.9 - */ - -namespace Quantum\Libraries\ResourceCache\Enums; - -use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; - -/** - * Class ExceptionMessages - * @package Quantum\Libraries\Lang - */ -final class ExceptionMessages extends BaseExceptionMessages -{ - const TRANSLATION_FILES_NOT_FOUND = 'The class class {%1} not found. Please install {%2} package.'; -} \ No newline at end of file diff --git a/src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php b/src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php index 5ee41e9a4..996716e1d 100644 --- a/src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php +++ b/src/Libraries/ResourceCache/Exceptions/ResourceCacheException.php @@ -14,23 +14,13 @@ namespace Quantum\Libraries\ResourceCache\Exceptions; -use Quantum\Libraries\ResourceCache\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; /** - * Class JwtException - * @package Quantum\Libraries\JwtToken + * Class ResourceCacheException + * @package Quantum\Libraries\ResourceCache */ class ResourceCacheException extends BaseException { - /** - * @param string $className - * @param string $packageName - * @return ResourceCacheException - */ - public static function classNotFound(string $className, string $packageName): ResourceCacheException - { - return new static(_message(ExceptionMessages::TRANSLATION_FILES_NOT_FOUND, [$className, $packageName]), E_WARNING); - } } \ No newline at end of file diff --git a/src/Libraries/ResourceCache/ViewCache.php b/src/Libraries/ResourceCache/ViewCache.php index fe811e187..1c5842d05 100644 --- a/src/Libraries/ResourceCache/ViewCache.php +++ b/src/Libraries/ResourceCache/ViewCache.php @@ -283,14 +283,22 @@ private function getCacheFile(string $key): string /** * @param string $content * @return string - * @throws ResourceCacheException + * @throws BaseException */ private function minify(string $content): string { - if (!class_exists(HtmlMin::class)) { - throw ResourceCacheException::classNotFound('HtmlMin', 'voku/html-min'); + if (!$this->htmlMinifierExists()) { + throw ResourceCacheException::notFound('Package', 'HtmlMin'); } return (new HtmlMin())->minify($content); } + + /** + * @return bool + */ + protected function htmlMinifierExists(): bool + { + return class_exists(HtmlMin::class); + } } \ No newline at end of file diff --git a/tests/Unit/Libraries/ResourceCache/ViewCacheTest.php b/tests/Unit/Libraries/ResourceCache/ViewCacheTest.php index ce997ebbc..ea91b3f06 100644 --- a/tests/Unit/Libraries/ResourceCache/ViewCacheTest.php +++ b/tests/Unit/Libraries/ResourceCache/ViewCacheTest.php @@ -2,10 +2,31 @@ namespace Quantum\Tests\Unit\Libraries\ResourceCache; +use Quantum\Libraries\ResourceCache\Exceptions\ResourceCacheException; use Quantum\Libraries\ResourceCache\ViewCache; use Quantum\Tests\Unit\AppTestCase; use Quantum\Http\Response; +class ViewCacheDouble extends ViewCache +{ + private $forceMissingHtmlMin = false; + + public function simulateMissingHtmlMin(bool $state): void + { + $this->forceMissingHtmlMin = $state; + } + + protected function htmlMinifierExists(): bool + { + if ($this->forceMissingHtmlMin) { + return false; + } + + return class_exists(\voku\helper\HtmlMin::class); + } + +} + class ViewCacheTest extends AppTestCase { private $viewCache; @@ -69,6 +90,17 @@ public function testViewCacheContentMinification() $this->assertEquals($minifiedContent, $content); } + public function testViewCacheMinificationMissingDependency() + { + $viewCache = new ViewCacheDouble(); + $viewCache->enableMinification(true); + $viewCache->simulateMissingHtmlMin(true); + + $this->expectException(ResourceCacheException::class); + + $viewCache->set($this->route, '
test
'); + } + public function testExistsViewCache() { $this->viewCache->set($this->route, $this->content);