From f94e5fb6b5e9a38b9ce10744f5603ad170d46fb0 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Fri, 12 Dec 2025 20:18:19 +0400 Subject: [PATCH] More changes related to exception messages --- src/Console/Commands/DebugBarCommand.php | 19 +++++++++----- .../Cache/Adapters/DatabaseAdapter.php | 12 +++++---- src/Libraries/Cache/Adapters/FileAdapter.php | 18 +++++++++---- .../Cache/Adapters/MemcachedAdapter.php | 10 ++++--- src/Libraries/Cache/Adapters/RedisAdapter.php | 12 +++++---- .../Cache/Enums/ExceptionMessages.php | 26 +++++++++++++++++++ .../src/Controllers/AccountController.php.tpl | 6 ++--- 7 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 src/Libraries/Cache/Enums/ExceptionMessages.php diff --git a/src/Console/Commands/DebugBarCommand.php b/src/Console/Commands/DebugBarCommand.php index 01f0b3a0c..99a5a3284 100644 --- a/src/Console/Commands/DebugBarCommand.php +++ b/src/Console/Commands/DebugBarCommand.php @@ -9,16 +9,19 @@ * @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\Console\Commands; +use Quantum\Libraries\Storage\Exceptions\FileSystemException; use Quantum\Libraries\Storage\Factories\FileSystemFactory; -use Quantum\Libraries\Lang\Exceptions\LangException; +use Quantum\Config\Exceptions\ConfigException; use Quantum\App\Exceptions\BaseException; use Quantum\Libraries\Storage\FileSystem; +use Quantum\Di\Exceptions\DiException; use Quantum\Console\QtCommand; +use ReflectionException; /** * Class DebugBarAssetsCommand @@ -64,8 +67,11 @@ class DebugBarCommand extends QtCommand /** * Executes the command and publishes the debug bar assets - * @throws LangException * @throws BaseException + * @throws FileSystemException + * @throws ConfigException + * @throws DiException + * @throws ReflectionException */ public function exec() { @@ -85,7 +91,8 @@ public function exec() * Recursively copies the debug bar assets * @param string $src * @param string $dst - * @throws LangException + * @return void + * @throws FileSystemException */ private function copyResources(string $src, string $dst) { @@ -93,7 +100,7 @@ private function copyResources(string $src, string $dst) if ($dst != $this->publicDebugBarFolderPath) { if ($this->fs->makeDirectory($dst) === false) { - throw new \RuntimeException(t('exception.directory_cant_be_created', $dst)); + throw FileSystemException::directoryNotWritable($dst); } } @@ -111,4 +118,4 @@ private function copyResources(string $src, string $dst) closedir($dir); } } -} +} \ No newline at end of file diff --git a/src/Libraries/Cache/Adapters/DatabaseAdapter.php b/src/Libraries/Cache/Adapters/DatabaseAdapter.php index dea8a8809..4ce043f6b 100644 --- a/src/Libraries/Cache/Adapters/DatabaseAdapter.php +++ b/src/Libraries/Cache/Adapters/DatabaseAdapter.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\Libraries\Cache\Adapters; +use Quantum\Libraries\Cache\Enums\ExceptionMessages; use Quantum\Model\Factories\ModelFactory; use Psr\SimpleCache\CacheInterface; use InvalidArgumentException; @@ -73,11 +74,12 @@ public function get($key, $default = null) /** * @inheritDoc + * @throws InvalidArgumentException */ public function getMultiple($keys, $default = null) { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$keys')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$keys'), E_WARNING); } $result = []; @@ -133,7 +135,7 @@ public function set($key, $value, $ttl = null): bool public function setMultiple($values, $ttl = null): bool { if (!is_array($values)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $results = []; @@ -166,7 +168,7 @@ public function delete($key): bool public function deleteMultiple($keys): bool { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$keys')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$keys'), E_WARNING); } $results = []; @@ -195,4 +197,4 @@ private function keyHash(string $key): string { return sha1($this->prefix . $key); } -} +} \ No newline at end of file diff --git a/src/Libraries/Cache/Adapters/FileAdapter.php b/src/Libraries/Cache/Adapters/FileAdapter.php index d294c1d7f..a7834ba8e 100644 --- a/src/Libraries/Cache/Adapters/FileAdapter.php +++ b/src/Libraries/Cache/Adapters/FileAdapter.php @@ -9,16 +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\Libraries\Cache\Adapters; use Quantum\Libraries\Storage\Factories\FileSystemFactory; +use Quantum\Libraries\Cache\Enums\ExceptionMessages; +use Quantum\Config\Exceptions\ConfigException; use Quantum\App\Exceptions\BaseException; use Quantum\Libraries\Storage\FileSystem; +use Quantum\Di\Exceptions\DiException; use Psr\SimpleCache\CacheInterface; use InvalidArgumentException; +use ReflectionException; /** * Class FileAdapter @@ -50,6 +54,9 @@ class FileAdapter implements CacheInterface /** * @param array $params * @throws BaseException + * @throws ConfigException + * @throws DiException + * @throws ReflectionException */ public function __construct(array $params) { @@ -84,11 +91,12 @@ public function get($key, $default = null) /** * @inheritDoc + * @throws InvalidArgumentException */ public function getMultiple($keys, $default = null) { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$keys')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$keys'), E_WARNING); } $result = []; @@ -134,7 +142,7 @@ public function set($key, $value, $ttl = null) public function setMultiple($values, $ttl = null): bool { if (!is_array($values)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $results = []; @@ -167,7 +175,7 @@ public function delete($key) public function deleteMultiple($keys): bool { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$keys')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$keys'), E_WARNING); } $results = []; @@ -210,4 +218,4 @@ private function getPath(string $key): string { return $this->cacheDir . DS . sha1($this->prefix . $key); } -} +} \ No newline at end of file diff --git a/src/Libraries/Cache/Adapters/MemcachedAdapter.php b/src/Libraries/Cache/Adapters/MemcachedAdapter.php index 4d1d6cb8c..3f9b64dbc 100644 --- a/src/Libraries/Cache/Adapters/MemcachedAdapter.php +++ b/src/Libraries/Cache/Adapters/MemcachedAdapter.php @@ -15,6 +15,7 @@ namespace Quantum\Libraries\Cache\Adapters; use Quantum\Libraries\Cache\Exceptions\CacheException; +use Quantum\Libraries\Cache\Enums\ExceptionMessages; use Quantum\App\Exceptions\BaseException; use Psr\SimpleCache\CacheInterface; use InvalidArgumentException; @@ -81,11 +82,12 @@ public function get($key, $default = null) /** * @inheritDoc + * @throws InvalidArgumentException */ public function getMultiple($keys, $default = null) { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $result = []; @@ -126,7 +128,7 @@ public function set($key, $value, $ttl = null): bool public function setMultiple($values, $ttl = null): bool { if (!is_array($values)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $results = []; @@ -153,7 +155,7 @@ public function delete($key): bool public function deleteMultiple($keys): bool { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $results = []; @@ -182,4 +184,4 @@ private function keyHash(string $key): string { return sha1($this->prefix . $key); } -} +} \ No newline at end of file diff --git a/src/Libraries/Cache/Adapters/RedisAdapter.php b/src/Libraries/Cache/Adapters/RedisAdapter.php index 6e1d8a8c4..075756eba 100644 --- a/src/Libraries/Cache/Adapters/RedisAdapter.php +++ b/src/Libraries/Cache/Adapters/RedisAdapter.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.5 + * @since 2.9.9 */ namespace Quantum\Libraries\Cache\Adapters; +use Quantum\Libraries\Cache\Enums\ExceptionMessages; use Psr\SimpleCache\CacheInterface; use InvalidArgumentException; use RedisException; @@ -76,11 +77,12 @@ public function get($key, $default = null) /** * @inheritDoc + * @throws InvalidArgumentException */ public function getMultiple($keys, $default = null) { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $result = []; @@ -128,7 +130,7 @@ public function set($key, $value, $ttl = null) public function setMultiple($values, $ttl = null): bool { if (!is_array($values)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $results = []; @@ -155,7 +157,7 @@ public function delete($key): bool public function deleteMultiple($keys): bool { if (!is_array($keys)) { - throw new InvalidArgumentException(t(_message('exception.non_iterable_value', '$values')), E_WARNING); + throw new InvalidArgumentException(_message(ExceptionMessages::ARGUMENT_NOT_ITERABLE, '$values'), E_WARNING); } $results = []; @@ -185,4 +187,4 @@ private function keyHash(string $key): string { return sha1($this->prefix . $key); } -} +} \ No newline at end of file diff --git a/src/Libraries/Cache/Enums/ExceptionMessages.php b/src/Libraries/Cache/Enums/ExceptionMessages.php new file mode 100644 index 000000000..bff512b43 --- /dev/null +++ b/src/Libraries/Cache/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\Cache\Enums; + +use Quantum\App\Enums\ExceptionMessages as BaseExceptionMessages; + +/** + * Class ExceptionMessages + * @package Quantum\Libraries\Cache + */ +final class ExceptionMessages extends BaseExceptionMessages +{ + const ARGUMENT_NOT_ITERABLE = 'The argument {%1} is not iterable'; +} \ No newline at end of file diff --git a/src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl b/src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl index c93f64e4d..e21f5999b 100644 --- a/src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl +++ b/src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl @@ -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 {{MODULE_NAMESPACE}}\Controllers; @@ -66,7 +66,7 @@ class AccountController extends BaseController } catch (AuthException $e) { $response->json([ 'status' => self::STATUS_ERROR, - 'message' => t('exception.execution_terminated') + 'message' => $e->getMessage() ]); } } @@ -94,7 +94,7 @@ class AccountController extends BaseController } catch (AuthException $e) { $response->json([ 'status' => self::STATUS_ERROR, - 'message' => t('exception.execution_terminated') + 'message' => $e->getMessage() ]); } }