From 8b503f02e0b585040ff22fc104e459ceebe06082 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:13:21 +0400 Subject: [PATCH 1/2] Remove shared StorageInterface in favor of package-level contracts --- src/Config/Config.php | 27 +++---- src/Config/Contracts/ConfigInterface.php | 70 +++++++++++++++++++ .../Contracts/CookieStorageInterface.php | 27 ++++++- .../Contracts/DebuggerStoreInterface.php} | 22 +++--- src/Debugger/DebuggerStore.php | 19 +++-- .../Contracts/SessionStorageInterface.php | 40 ++++++++++- 6 files changed, 169 insertions(+), 36 deletions(-) create mode 100644 src/Config/Contracts/ConfigInterface.php rename src/{Contracts/StorageInterface.php => Debugger/Contracts/DebuggerStoreInterface.php} (70%) diff --git a/src/Config/Config.php b/src/Config/Config.php index d5ebed1ba..c23794200 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -18,7 +18,7 @@ use Quantum\Config\Exceptions\ConfigException; use Quantum\Loader\Exceptions\LoaderException; -use Quantum\Contracts\StorageInterface; +use Quantum\Config\Contracts\ConfigInterface; use Quantum\Di\Exceptions\DiException; use Dflydev\DotAccessData\Data; use Quantum\Loader\Loader; @@ -30,7 +30,7 @@ * Class Config * @package Quantum\Config */ -class Config implements StorageInterface +class Config implements ConfigInterface { private static ?Data $configs = null; @@ -49,10 +49,8 @@ public static function getInstance(): Config } /** - * Loads configuration - * @throws ConfigException - * @throws DiException - * @throws ReflectionException + * @inheritDoc + * @throws DiException|LoaderException|ReflectionException */ public function load(Setup $setup): void { @@ -64,7 +62,7 @@ public function load(Setup $setup): void } /** - * Imports new config file + * @inheritDoc * @throws ConfigException * @throws DiException * @throws ReflectionException|LoaderException @@ -85,9 +83,7 @@ public function import(Setup $setup): void } /** - * Gets the config item by given key - * @param mixed $default - * @return mixed|null + * @inheritDoc */ public function get(string $key, $default = null) { @@ -99,7 +95,7 @@ public function get(string $key, $default = null) } /** - * Get all configs + * @inheritDoc */ public function all(): ?Data { @@ -107,7 +103,7 @@ public function all(): ?Data } /** - * Checks config data + * @inheritDoc */ public function has(string $key): bool { @@ -115,8 +111,7 @@ public function has(string $key): bool } /** - * Sets new value - * @param mixed $value + * @inheritDoc */ public function set(string $key, $value): void { @@ -128,7 +123,7 @@ public function set(string $key, $value): void } /** - * Removes the data from config + * @inheritDoc */ public function delete(string $key): void { @@ -136,7 +131,7 @@ public function delete(string $key): void } /** - * Deletes whole config data + * @inheritDoc */ public function flush(): void { diff --git a/src/Config/Contracts/ConfigInterface.php b/src/Config/Contracts/ConfigInterface.php new file mode 100644 index 000000000..fbb441956 --- /dev/null +++ b/src/Config/Contracts/ConfigInterface.php @@ -0,0 +1,70 @@ + + * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) + * @link http://quantum.softberg.org/ + * @since 3.0.0 + */ + +namespace Quantum\Config\Contracts; + +use Quantum\Loader\Setup; + +/** + * Interface ConfigInterface + * @package Quantum\Config + */ +interface ConfigInterface +{ + /** + * Gets whole storage data + * @return mixed + */ + public function all(); + + /** + * Checks if the storage contains a key + */ + public function has(string $key): bool; + + /** + * Gets the value from the storage by given key + * @param mixed $default + * @return mixed|null + */ + public function get(string $key, $default = null); + + /** + * Sets storage value with the given key + * @param mixed $value + */ + public function set(string $key, $value): void; + + /** + * Deletes the data from the storage by given key + */ + public function delete(string $key): void; + + /** + * Deletes whole storage data + */ + public function flush(): void; + + /** + * Loads configuration + */ + public function load(Setup $setup): void; + + /** + * Imports new config file + */ + public function import(Setup $setup): void; +} diff --git a/src/Cookie/Contracts/CookieStorageInterface.php b/src/Cookie/Contracts/CookieStorageInterface.php index 81d89f4d4..6f2553612 100644 --- a/src/Cookie/Contracts/CookieStorageInterface.php +++ b/src/Cookie/Contracts/CookieStorageInterface.php @@ -16,14 +16,29 @@ namespace Quantum\Cookie\Contracts; -use Quantum\Contracts\StorageInterface; - /** * Interface CookieStorageInterface * @package Quantum\Cookie */ -interface CookieStorageInterface extends StorageInterface +interface CookieStorageInterface { + /** + * Gets whole storage data + * @return mixed + */ + public function all(); + + /** + * Checks if the storage contains a key + */ + public function has(string $key): bool; + + /** + * Gets the value from the storage by given key + * @return mixed|null + */ + public function get(string $key); + /** * Sets data by given key * @param mixed $value @@ -36,4 +51,10 @@ public function set(string $key, $value = '', int $time = 0, string $path = '/', * @return void */ public function delete(string $key, string $path = '/'): void; + + /** + * Deletes whole storage data + * @return void + */ + public function flush(); } diff --git a/src/Contracts/StorageInterface.php b/src/Debugger/Contracts/DebuggerStoreInterface.php similarity index 70% rename from src/Contracts/StorageInterface.php rename to src/Debugger/Contracts/DebuggerStoreInterface.php index 4156c894c..c856d4f54 100644 --- a/src/Contracts/StorageInterface.php +++ b/src/Debugger/Contracts/DebuggerStoreInterface.php @@ -14,14 +14,19 @@ * @since 3.0.0 */ -namespace Quantum\Contracts; +namespace Quantum\Debugger\Contracts; /** - * Interface StorageInterface - * @package Quantum\Contracts + * Interface DebuggerStoreInterface + * @package Quantum\Debugger */ -interface StorageInterface +interface DebuggerStoreInterface { + /** + * @param array $keys + */ + public function init(array $keys): void; + /** * Gets whole storage data * @return mixed @@ -42,19 +47,16 @@ public function get(string $key); /** * Sets storage value with the given key * @param mixed $value - * @return void */ - public function set(string $key, $value); + public function set(string $key, $value): void; /** * Deletes the data from the storage by given key - * @return void */ - public function delete(string $key); + public function delete(string $key): void; /** * Deletes whole storage data - * @return void */ - public function flush(); + public function flush(): void; } diff --git a/src/Debugger/DebuggerStore.php b/src/Debugger/DebuggerStore.php index d9bfc0207..de88dde15 100644 --- a/src/Debugger/DebuggerStore.php +++ b/src/Debugger/DebuggerStore.php @@ -16,13 +16,13 @@ namespace Quantum\Debugger; -use Quantum\Contracts\StorageInterface; +use Quantum\Debugger\Contracts\DebuggerStoreInterface; /** * Class DebuggerStore * @package Quantum\Debugger */ -class DebuggerStore implements StorageInterface +class DebuggerStore implements DebuggerStoreInterface { /** * @var array @@ -30,7 +30,7 @@ class DebuggerStore implements StorageInterface private static array $store = []; /** - * @param array $keys + * @inheritDoc */ public function init(array $keys): void { @@ -42,6 +42,7 @@ public function init(array $keys): void } /** + * @inheritDoc * @return array */ public function all(): array @@ -49,12 +50,16 @@ public function all(): array return self::$store; } + /** + * @inheritDoc + */ public function has(string $key): bool { return isset(self::$store[$key]); } /** + * @inheritDoc * @return array */ public function get(string $key): array @@ -63,7 +68,7 @@ public function get(string $key): array } /** - * @param mixed $value + * @inheritDoc */ public function set(string $key, $value): void { @@ -74,6 +79,9 @@ public function set(string $key, $value): void } } + /** + * @inheritDoc + */ public function delete(string $key): void { if ($this->has($key)) { @@ -81,6 +89,9 @@ public function delete(string $key): void } } + /** + * @inheritDoc + */ public function flush(): void { self::$store = []; diff --git a/src/Session/Contracts/SessionStorageInterface.php b/src/Session/Contracts/SessionStorageInterface.php index 29dfea85b..1dcde6ecf 100644 --- a/src/Session/Contracts/SessionStorageInterface.php +++ b/src/Session/Contracts/SessionStorageInterface.php @@ -16,14 +16,48 @@ namespace Quantum\Session\Contracts; -use Quantum\Contracts\StorageInterface; - /** * Interface SessionStorageInterface * @package Quantum\Session */ -interface SessionStorageInterface extends StorageInterface +interface SessionStorageInterface { + /** + * Gets whole storage data + * @return mixed + */ + public function all(); + + /** + * Checks if the storage contains a key + */ + public function has(string $key): bool; + + /** + * Gets the value from the storage by given key + * @return mixed|null + */ + public function get(string $key); + + /** + * Sets storage value with the given key + * @param mixed $value + * @return void + */ + public function set(string $key, $value); + + /** + * Deletes the data from the storage by given key + * @return void + */ + public function delete(string $key); + + /** + * Deletes whole storage data + * @return void + */ + public function flush(); + /** * Gets flash value by given key * @return mixed|string|null From 1b4667fe847b88a202004e3efb0cc7d197782aff Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:32:19 +0400 Subject: [PATCH 2/2] Add explicit : void return types to SessionStorageInterface and CookieStorageInterface for consistency across all package contracts. --- src/Cookie/Contracts/CookieStorageInterface.php | 5 +---- src/Session/Contracts/SessionStorageInterface.php | 9 +++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Cookie/Contracts/CookieStorageInterface.php b/src/Cookie/Contracts/CookieStorageInterface.php index 6f2553612..6058f12d4 100644 --- a/src/Cookie/Contracts/CookieStorageInterface.php +++ b/src/Cookie/Contracts/CookieStorageInterface.php @@ -42,19 +42,16 @@ public function get(string $key); /** * Sets data by given key * @param mixed $value - * @return void */ public function set(string $key, $value = '', int $time = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httponly = false): void; /** * Deletes data by given key - * @return void */ public function delete(string $key, string $path = '/'): void; /** * Deletes whole storage data - * @return void */ - public function flush(); + public function flush(): void; } diff --git a/src/Session/Contracts/SessionStorageInterface.php b/src/Session/Contracts/SessionStorageInterface.php index 1dcde6ecf..cff63f42a 100644 --- a/src/Session/Contracts/SessionStorageInterface.php +++ b/src/Session/Contracts/SessionStorageInterface.php @@ -42,21 +42,18 @@ public function get(string $key); /** * Sets storage value with the given key * @param mixed $value - * @return void */ - public function set(string $key, $value); + public function set(string $key, $value): void; /** * Deletes the data from the storage by given key - * @return void */ - public function delete(string $key); + public function delete(string $key): void; /** * Deletes whole storage data - * @return void */ - public function flush(); + public function flush(): void; /** * Gets flash value by given key