commit 3429959de1227645234be71275f67d472eef6e43 Author: User Date: Tue Oct 10 17:12:40 2023 +0300 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..31dc5a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +/vendor +composer.lock \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ecfc700 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +## Rmphp/Session + +DB component for **Rmphp** + +## Install + +Stable version + +```bash +composer require rmphp/session +``` +```bash +composer require rmphp/session:"^1.0" +``` + + +Dev version contains the latest changes + +```bash +composer require rmphp/session:"1.x-dev" +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bd03cba --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "rmphp/session", + "license": "proprietary", + "authors": [ + { + "name": "Yuri Zuev", + "email": "y_zuev@mail.ru" + } + ], + "require": { + "php": "^8.1" + }, + "autoload": { + "psr-4": { + "Rmphp\\Session\\": "src/" + } + } + +} diff --git a/src/Session/Session.php b/src/Session/Session.php new file mode 100644 index 0000000..5060744 --- /dev/null +++ b/src/Session/Session.php @@ -0,0 +1,57 @@ +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..7165c65 --- /dev/null +++ b/src/Session/SessionInterface.php @@ -0,0 +1,38 @@ +