diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php deleted file mode 100644 index f6521cb..0000000 --- a/src/Cache/Cache.php +++ /dev/null @@ -1,111 +0,0 @@ -path = rtrim($path, "/"); - if(!is_dir($this->path) && !mkdir($this->path, 0777, true)) throw new Exception("Error create path"); - } - - /** @inheritDoc */ - public function save(string $name, $value, int $expires = 0) : bool { - if(empty($expires)) $expires = time() + $this->defaultTime; - if(!$this->fileSave($name, $expires."::".$name."::".serialize($value))) return false; - return true; - } - - /** @inheritDoc */ - public function getItem(string $key) { - if($this->hasItem($key)){ - $data = explode("::", $this->fileRead($key), 3); - return unserialize($data[2]); - } - return null; - } - - /** @inheritDoc */ - public function hasItem(string $key) : bool { - if (!empty($fileValue = $this->fileRead($key))){ - if(count($data = explode("::", $fileValue, 3)) != 3) return false; - if(time() < (int)$data[0]) return true; - } - $this->fileDelete($key); - return false; - } - - /** @inheritDoc */ - public function get(string $name, callable $function, int $expires = 0) : mixed { - if($this->hasItem($name)){ - $data = explode("::", $this->fileRead($name), 3); - return unserialize($data[2]); - } - $value = $function(); - if(empty($expires)) $expires = time() + $this->defaultTime; - $this->fileSave($name, $expires."::".$name."::".serialize($value)); - return $value; - } - - /** - * @param string $name - * @return object - */ - private function getPath(string $name) : object { - $hexName = md5($name); - $subPath = substr($hexName, 0, $this->subLength); - return (object)[ - "path" => $this->path."/".$subPath, - "file" => $this->path."/".$subPath."/".$hexName, - ]; - } - - /** - * @param string $name - * @param string $data - * @return bool - */ - private function fileSave(string $name, string $data) : bool { - $pathObject = $this->getPath($name); - if(!is_dir($pathObject->path)) mkdir($pathObject->path, 0777, true); - if(!file_put_contents($pathObject->file, $data)) return false; - return true; - } - - /** - * @param string $name - * @return string - */ - private function fileRead(string $name) : string { - $pathObject = $this->getPath($name); - if (file_exists($pathObject->file) && $fileValue = file_get_contents($pathObject->file)) return $fileValue; - return ""; - } - - /** - * @param $key - * @return bool - */ - public function fileDelete($key) : bool { - $pathObject = $this->getPath($key); - if(file_exists($pathObject->file)) unlink($pathObject->file); - return true; - } -} \ No newline at end of file diff --git a/src/Cache/CacheInterface.php b/src/Cache/CacheInterface.php deleted file mode 100644 index 1b1e316..0000000 --- a/src/Cache/CacheInterface.php +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index 6f22207..0000000 --- a/src/Session/SessionInterface.php +++ /dev/null @@ -1,38 +0,0 @@ -