20231010#1

This commit is contained in:
User
2023-10-10 14:39:27 +03:00
parent 19305af62f
commit c43f3a4768
7 changed files with 103 additions and 7 deletions

View File

@@ -7,15 +7,15 @@ DB component for **Rmphp**
Stable version Stable version
```bash ```bash
composer require rmphp/kernel composer require rmphp/storage
``` ```
```bash ```bash
composer require rmphp/kernel:"^1.0" composer require rmphp/storage:"^2.0"
``` ```
Dev version contains the latest changes Dev version contains the latest changes
```bash ```bash
composer require rmphp/kernel:"1.x-dev" composer require rmphp/storage:"2.x-dev"
``` ```

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage\Exception; namespace Rmphp\Storage\Mysql\Exception;
class MysqlException extends \Exception { class MysqlException extends \Exception {

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage; namespace Rmphp\Storage\Mysql;
use Exception; use Exception;
use Mysqli; use Mysqli;

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage; namespace Rmphp\Storage\Mysql;
class MysqlStorageData { class MysqlStorageData {

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Rmphp\Storage; namespace Rmphp\Storage\Mysql;
interface MysqlStorageInterface { interface MysqlStorageInterface {

58
src/Session/Session.php Normal file
View File

@@ -0,0 +1,58 @@
<?php
namespace Rmphp\Storage\Session;
class Session implements SessionInterface {
const INT = "INT";
const STRING = "STRING";
public function __construct(string $name = "usi") {
if(session_status() == PHP_SESSION_NONE) {
if(in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)){
session_id("cli");
} elseif(!empty($name)) {
session_name($name);
}
session_start();
}
}
/** @inheritDoc */
public function has(string $name = "") : bool {
return (!empty($name)) ? isset($this->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;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: Zuev Yuri
* Date: 10.10.2023
* Time: 14:34
*/
namespace Rmphp\Storage\Session;
interface SessionInterface {
/**
* @param string $name
* @return bool
*/
public function has(string $name = "") : bool;
/**
* @param string $name
* @param string $type
* @return mixed
*/
public function get(string $name = "", string $type = ""): mixed;
/**
* @param string $name
* @param $value
*/
public function set(string $name, $value = null) : void;
/**
* @param string|null $name
* @return void
*/
public function clear(string $name = null) : void;
}