From c43f3a476861b7f04f0786b0a00aedfde96aca62 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 10 Oct 2023 14:39:27 +0300 Subject: [PATCH] 20231010#1 --- README.md | 6 +- src/{ => Mysql}/Exception/MysqlException.php | 2 +- src/{ => Mysql}/MysqlStorage.php | 2 +- src/{ => Mysql}/MysqlStorageData.php | 2 +- src/{ => Mysql}/MysqlStorageInterface.php | 2 +- src/Session/Session.php | 58 ++++++++++++++++++++ src/Session/SessionInterface.php | 38 +++++++++++++ 7 files changed, 103 insertions(+), 7 deletions(-) rename src/{ => Mysql}/Exception/MysqlException.php (56%) rename src/{ => Mysql}/MysqlStorage.php (99%) rename src/{ => Mysql}/MysqlStorageData.php (97%) rename src/{ => Mysql}/MysqlStorageInterface.php (98%) create mode 100644 src/Session/Session.php create mode 100644 src/Session/SessionInterface.php diff --git a/README.md b/README.md index 7a4e743..b86f801 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,15 @@ DB component for **Rmphp** Stable version ```bash -composer require rmphp/kernel +composer require rmphp/storage ``` ```bash -composer require rmphp/kernel:"^1.0" +composer require rmphp/storage:"^2.0" ``` Dev version contains the latest changes ```bash -composer require rmphp/kernel:"1.x-dev" +composer require rmphp/storage:"2.x-dev" ``` diff --git a/src/Exception/MysqlException.php b/src/Mysql/Exception/MysqlException.php similarity index 56% rename from src/Exception/MysqlException.php rename to src/Mysql/Exception/MysqlException.php index 93469d0..00a1e57 100644 --- a/src/Exception/MysqlException.php +++ b/src/Mysql/Exception/MysqlException.php @@ -1,6 +1,6 @@ getSession()[$name]) : !empty($this->getSession()); + } + + /** @inheritDoc */ + public function get(string $name = "", string $type = ""): mixed { + $session = $this->getSession(); + if(!empty($name = strtolower($name))) { + if (!isset($session[$name])) return null; + elseif ($type == self::STRING) { + return (!empty($session[$name])) ? (string)$session[$name] : null; + } + elseif ($type == self::INT) { + return (!empty((int)$session[$name]) || $session[$name]==0) ? (int)$session[$name] : null; + } + return $session[$name]; + } + return $session; + } + + /** @inheritDoc */ + public function set(string $name, $value = null) : void { + $_SESSION[$name] = $value; + } + + /** @inheritDoc */ + public function clear(string $name = null) : void { + if (isset($name)) unset($_SESSION[$name]); + else $_SESSION = []; + } + + /** @inheritDoc */ + private function getSession() : array { + return $_SESSION; + } +} \ No newline at end of file diff --git a/src/Session/SessionInterface.php b/src/Session/SessionInterface.php new file mode 100644 index 0000000..6f22207 --- /dev/null +++ b/src/Session/SessionInterface.php @@ -0,0 +1,38 @@ +