solophp/storage
最新稳定版本:v1.2.0
Composer 安装命令:
composer require solophp/storage
包简介
Simple file-based storage system for storing string data using key-value pairs.
README 文档
README
A lightweight, file-based storage system for PHP applications that provides simple key-value pair storage functionality.
Features
- Simple key-value storage interface
- File-based persistence
- Thread-safe file operations
- Directory traversal protection
- Minimal dependencies
- Type-safe implementation (strict types)
Requirements
- PHP 8.1 or higher
Installation
composer require solophp/storage
Usage
Basic Setup
use Solo\Storage; // Initialize with default storage location (current directory) $storage = new Storage(); // Or specify a custom storage directory $storage = new Storage('/path/to/storage/directory');
Store Data
// Store a string value $storage->set('user.name', 'John Doe'); $storage->set('user.email', 'john@example.com');
Retrieve Data
// Get a stored value $name = $storage->get('user.name'); // Returns 'John Doe' // Handle non-existent keys $value = $storage->get('non.existent.key'); // Returns null
Check Data Existence
// Check if a key exists if ($storage->has('user.name')) { // Key exists }
Delete Data
// Delete a stored value $storage->delete('user.name');
Error Handling
All methods are designed to fail gracefully:
set()returnsboolindicating success/failureget()returnsnullif key doesn't exist or on errorhas()returnsboolindicating key existencedelete()returnsboolindicating success/failure
Security
The storage system includes protection against directory traversal attacks by sanitizing storage keys.
Thread Safety
File operations use exclusive locks (LOCK_EX) to ensure thread safety when writing data.
License
MIT
统计信息
- 总下载量: 88
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-13