diff --git a/src/Cache/Driver/File.php b/src/Cache/Driver/File.php deleted file mode 100644 index 74e6e37..0000000 --- a/src/Cache/Driver/File.php +++ /dev/null @@ -1,21 +0,0 @@ -getExtension(); - } - - /** - * @param string $path - * @return int - */ - public static function size($path) - { - if (!is_dir($path)) { - return filesize($path); - } - - $size = 0; - - $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS), - RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($iterator as $file) { - if ($file->isFile()) { - $size += $file->getSize(); - } - } - - return $size; - } - - /** - * @param int $fileSize - * @return string - */ - public static function sizen($fileSize) - { - $size = floatval($fileSize); - - if ($size < 1024) { - $s = $size . ' B'; - } elseif ($size < 1048576) { - $s = round($size / 1024, 2) . ' KB'; - } elseif ($size < 1073741824) { - $s = round($size / 1048576, 2) . ' MB'; - } elseif ($size < 1099511627776) { - $s = round($size / 1073741824, 2) . ' GB'; - } elseif ($size < 1125899906842624) { - $s = round($size / 1099511627776, 2) . ' TB'; - } elseif ($size < 1152921504606846976) { - $s = round($size / 1125899906842624, 2) . ' PB'; - } elseif ($size < 1.1805916207174E+21) { - $s = round($size / 1152921504606846976, 2) . ' EB'; - } elseif ($size < 1.2089258196146E+24) { - $s = round($size / 1.1805916207174E+21, 2) . ' ZB'; - } else { - $s = round($size / 1.2089258196146E+24, 2) . ' YB'; - } - - return $s; - } - - /** - * @param string $path - * @return bool - */ - public static function remove($path) - { - if (is_link($path)) { - return unlink($path); - } - - if (is_file($path)) { - return unlink($path); - } - - if (is_dir($path)) { - $files = array_diff(scandir($path), ['.', '..']); - foreach ($files as $file) { - $filePath = $path . DIRECTORY_SEPARATOR . $file; - if (!self::remove($filePath)) { - return false; - } - } - return rmdir($path); - } - - if (!file_exists($path)) { - return true; - } - - throw new Exception('remove error, not match file type'); - } - - /** - * @param string $path - * @param array $excludes - * @return RecursiveIteratorIterator - */ - public static function read_full_dir($path, $excludes = []) - { - $directory = new RecursiveDirectoryIterator( - $path, - FilesystemIterator::UNIX_PATHS - | FilesystemIterator::SKIP_DOTS - ); - - $filter = new RecursiveCallbackFilterIterator($directory, function ($current, $key, $iterator) use ($path, $excludes) { - $relativePath = Str::replace_first($path, '', $current->getPathname()); - - foreach ($excludes as $exclude) { - if (empty($exclude)) { - continue; - } - //var_dump($relativePath); - //var_dump($exclude); - - $exclude = trim($exclude); - $exclude = trim($exclude, '/'); - $relativePath = trim($relativePath, '/'); - - if (str_ends_with($relativePath, $exclude)) { - return false; - } - } - - return true; - }); - - return new RecursiveIteratorIterator( - $filter, - RecursiveIteratorIterator::SELF_FIRST - ); - } - - /** - * @param string ...$paths - * @return string - */ - public static function join_path(...$paths) - { - return preg_replace('#/+#', '/', implode('/', $paths)); - } - - /** - * Lấy tên chủ sở hữu file theo tên file - * @param string $filename - * @return string - */ - public static function get_owner_name($filename) - { - $owner_id = @fileowner($filename); - if ($owner_id === false) { - return ''; - } - return self::get_owner_name_by_id($owner_id); - } - - /** - * Lấy tên chủ sở hữu theo user ID - * @param int $id - * @return string - */ - public static function get_owner_name_by_id($id) - { - $info = @posix_getpwuid($id); - return $info['name'] ?? ''; - } -} +getExtension(); + } + + /** + * @param string $path + * @return int + */ + public static function size($path) + { + if (!is_dir($path)) { + return filesize($path); + } + + $size = 0; + + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS), + RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($iterator as $file) { + if ($file->isFile()) { + $size += $file->getSize(); + } + } + + return $size; + } + + /** + * @param int $fileSize + * @return string + */ + public static function sizen($fileSize) + { + $size = floatval($fileSize); + + if ($size < 1024) { + $s = $size . ' B'; + } elseif ($size < 1048576) { + $s = round($size / 1024, 2) . ' KB'; + } elseif ($size < 1073741824) { + $s = round($size / 1048576, 2) . ' MB'; + } elseif ($size < 1099511627776) { + $s = round($size / 1073741824, 2) . ' GB'; + } elseif ($size < 1125899906842624) { + $s = round($size / 1099511627776, 2) . ' TB'; + } elseif ($size < 1152921504606846976) { + $s = round($size / 1125899906842624, 2) . ' PB'; + } elseif ($size < 1.1805916207174E+21) { + $s = round($size / 1152921504606846976, 2) . ' EB'; + } elseif ($size < 1.2089258196146E+24) { + $s = round($size / 1.1805916207174E+21, 2) . ' ZB'; + } else { + $s = round($size / 1.2089258196146E+24, 2) . ' YB'; + } + + return $s; + } + + /** + * @param string $path + * @return bool + */ + public static function remove($path) + { + if (is_link($path)) { + return unlink($path); + } + + if (is_file($path)) { + return unlink($path); + } + + if (is_dir($path)) { + $files = array_diff(scandir($path), ['.', '..']); + foreach ($files as $file) { + $filePath = $path . DIRECTORY_SEPARATOR . $file; + if (!self::remove($filePath)) { + return false; + } + } + return rmdir($path); + } + + if (!file_exists($path)) { + return true; + } + + throw new Exception('remove error, not match file type'); + } + + /** + * @param string ...$paths + * @return string + */ + public static function join_path(...$paths) + { + return preg_replace('#/+#', '/', implode('/', $paths)); + } + + /** + * Lấy tên chủ sở hữu file theo tên file + * @param string $filename + * @return string + */ + public static function get_owner_name($filename) + { + $owner_id = @fileowner($filename); + if ($owner_id === false) { + return ''; + } + return self::get_owner_name_by_id($owner_id); + } + + /** + * Lấy tên chủ sở hữu theo user ID + * @param int $id + * @return string + */ + public static function get_owner_name_by_id($id) + { + $info = @posix_getpwuid($id); + return $info['name'] ?? ''; + } +} diff --git a/src/Session/Storage/Apcu.php b/src/Session/Storage/Apcu.php deleted file mode 100755 index 44896ca..0000000 --- a/src/Session/Storage/Apcu.php +++ /dev/null @@ -1,57 +0,0 @@ -prefix = $prefix; - $this->ttl = $ttl; - } - - #[ReturnTypeWillChange] - public function close() - { - return true; - } - - #[ReturnTypeWillChange] - public function destroy($id) - { - $key = $this->prefix . $id; - return apcu_delete($key); - } - - #[ReturnTypeWillChange] - public function gc($max_lifetime) - { - return 1; - } - - #[ReturnTypeWillChange] - public function open($path, $name) - { - return true; - } - - #[ReturnTypeWillChange] - public function read($id) - { - $key = $this->prefix . $id; - return apcu_exists($key) ? apcu_fetch($key) : ''; - } - - #[ReturnTypeWillChange] - public function write($id, $data) - { - $key = $this->prefix . $id; - return apcu_store($key, $data, $this->ttl); - } -} \ No newline at end of file diff --git a/src/Trie.php b/src/Trie/Trie.php similarity index 100% rename from src/Trie.php rename to src/Trie/Trie.php diff --git a/src/cache/cache.php b/src/cache/cache.php deleted file mode 100644 index e971645..0000000 --- a/src/cache/cache.php +++ /dev/null @@ -1,207 +0,0 @@ - $adapter]); - } - - /** - * @param string $key - * @return void - */ - public function remove_adapter($key) - { - unset(self::$adapters[$key]); - } - - /** - * @return array - */ - public static function get_adapters() - { - return self::$adapters; - } - - // cache - - /** - * @param string $key - * @return bool - */ - public static function has($key) - { - return self::$adapter->hasItem(self::$prefix . $key); - } - - // truyen 1 tham so - lay binh thuong - // truyen 2 tham so tro len - luu cache cho lan sau - /** - * @param string $key - * @param mixed $default - * @param array $opt - * @return mixed - */ - public static function get($key, $default = null, $opt = []) - { - $opt += [ - 'expire' => self::$expire, - 'debug' => false, - 'save' => true, - 'save_if' => null, // ?callable - ]; - - if (self::$debug || $opt['debug']) { - self::unset(self::$prefix . $key); - } - - // get cache - $item = self::$adapter->getItem(self::$prefix . $key); - - if ($item->isHit()) { - return $item->get(); - } else { - if (is_callable($default)) { - $default = call_user_func($default, $opt); - } - - if ($opt['save']) { - $save = false; - - if (is_callable($opt['save_if'])) { - if (call_user_func($opt['save_if'], $default)) { - $save = true; - } - } else { - $save = true; - } - - if ($save) { - self::set($key, $default, $opt['expire']); - } - } - - return $default; - } - } - - /** - * @param string $key - * @param mixed $value - * @param int|null $expire - * @return bool - */ - public static function set($key, $value, $expire = null) - { - $item = self::$adapter->getItem(self::$prefix . $key); - - if ($expire !== null) { - $item->expiresAfter($expire); - } elseif (self::$expire !== null) { - $item->expiresAfter(self::$expire); - } - - $item->set($value); - return self::$adapter->save($item); - } - - /** - * @param string $key - * @return bool - */ - public static function unset($key) - { - return self::$adapter->deleteItem(self::$prefix . $key); - } - - /** - * @param string $prefix - * @return bool - */ - public static function clear($prefix = '') - { - return self::$adapter->clear($prefix); - } -} diff --git a/src/cache/driver.php b/src/cache/driver.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/cache2.php b/src/cache2.php deleted file mode 100644 index 3be5e6e..0000000 --- a/src/cache2.php +++ /dev/null @@ -1,207 +0,0 @@ - $adapter]); - } - - /** - * @param string $key - * @return void - */ - public function remove_adapter($key) - { - unset(self::$adapters[$key]); - } - - /** - * @return array - */ - public function get_adapters() - { - return self::$adapters; - } - - // cache - - /** - * @param string $key - * @return bool - */ - public function has($key) - { - return self::$adapter->hasItem(self::$prefix . $key); - } - - // truyen 1 tham so - lay binh thuong - // truyen 2 tham so tro len - luu cache cho lan sau - /** - * @param string $key - * @param mixed $default - * @param array $opt - * @return mixed - */ - public function get($key, $default = null, $opt = []) - { - $opt += [ - 'expire' => self::$expire, - 'debug' => false, - 'save' => true, - 'save_if' => null, // ?callable - ]; - - if (self::$debug || $opt['debug']) { - self::unset(self::$prefix . $key); - } - - // get cache - $item = self::$adapter->getItem(self::$prefix . $key); - - if ($item->isHit()) { - return $item->get(); - } else { - if (is_callable($default)) { - $default = call_user_func($default, $opt); - } - - if ($opt['save']) { - $save = false; - - if (is_callable($opt['save_if'])) { - if (call_user_func($opt['save_if'], $default)) { - $save = true; - } - } else { - $save = true; - } - - if ($save) { - self::set($key, $default, $opt['expire']); - } - } - - return $default; - } - } - - /** - * @param string $key - * @param mixed $value - * @param int|null $expire - * @return bool - */ - public function set($key, $value, $expire = null) - { - $item = self::$adapter->getItem(self::$prefix . $key); - - if ($expire !== null) { - $item->expiresAfter($expire); - } elseif (self::$expire !== null) { - $item->expiresAfter(self::$expire); - } - - $item->set($value); - return self::$adapter->save($item); - } - - /** - * @param string $key - * @return bool - */ - public function unset($key) - { - return self::$adapter->deleteItem(self::$prefix . $key); - } - - /** - * @param string $prefix - * @return bool - */ - public function clear($prefix = '') - { - return self::$adapter->clear($prefix); - } -} diff --git a/src/http/auth/basic_bultin.php b/src/http/auth/basic_bultin.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/http/auth/form_builtin.php b/src/http/auth/form_builtin.php deleted file mode 100644 index e69de29..0000000