changhorizon/scoped-storage-strategy
最新稳定版本:v2.1.2
Composer 安装命令:
composer require changhorizon/scoped-storage-strategy
包简介
A flexible and pluggable storage strategy for managing scoped, temporary key-value data using sessions, tokens, Redis, and more.
README 文档
README
A pluggable and namespace-aware storage abstraction for temporarily persisting key-value data during scoped user interactions.
Supports session-based (cookie and token) and Redis-based implementations, designed to decouple application logic from underlying storage mechanisms. Ideal for tracking transient states — such as validation progress, multistep workflows, or temporary metadata.
✨ 特性
- 🍪 Cookie-based PHP session — traditional web applications
- 🆔 Token-based PHP session — stateless API support
- 🚀 Redis storage — shared, scalable scenarios
- 🔌 PSR-style interface for easy integration and extension
- ✅ Unified interface with
put,get,exists,remove,clear
📦 安装
composer require changhorizon/scoped-storage-strategy
📂 目录结构
src/
├── ScopedStorageStrategyInterface.php
├── SessionInitializerInterface.php
├── Session/
│ ├── SessionStorageStrategy.php
│ ├── SessionInitializerWithCookie.php
│ └── SessionInitializerWithToken.php
└── Redis/
└── RedisStorageStrategy.php
🚀 用法示例
SessionStorageStrategy with Cookie
use ChangHorizon\ScopedStorageStrategy\SessionStorageStrategy; use ChangHorizon\ScopedStorageStrategy\SessionInitializerWithCookie; $initializer = new SessionInitializerWithCookie(); $strategy = new SessionStorageStrategy('scope-123', $initializer); $strategy->put('demo-file-123', '/path/to/demo-file-123'); $value = $strategy->get('demo-file-123');
SessionStorageStrategy with Token
use ChangHorizon\ScopedStorageStrategy\SessionStorageStrategy; use ChangHorizon\ScopedStorageStrategy\SessionInitializerWithToken; $token = $_GET['token'] ?? ''; $initializer = new SessionInitializerWithToken($token); $strategy = new SessionStorageStrategy('scope-456', $initializer); $strategy->put('demo-file-456', '/path/to/demo-file-456'); $value = $strategy->get('demo-file-456');
RedisStorageStrategy
use ChangHorizon\ScopedStorageStrategy\RedisStorageStrategy; $redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $strategy = new RedisStorageStrategy('scope-789', $redis); $strategy->put('demo-file-789', '/path/to/demo-file-789'); $value = $strategy->get('demo-file-789');
📐 接口说明
All strategies implement:
namespace ChangHorizon\ScopedStorageStrategy; interface ScopedStorageStrategyInterface { public function put(string $key, string $value): void; public function get(string $key): ?string; public function exists(string $key): bool; public function remove(string $key): void; public function all(): ?array; public function empty(): bool; public function clear(): void; }
Session-based strategies require a session initializer:
namespace ChangHorizon\ScopedStorageStrategy; interface SessionInitializerInterface { public function initialize(): void; }
🔍 静态分析
composer stan
🎯 代码风格
composer cs:chk # check composer cs:fix # auto-fix
✅ 单元测试
composer test
composer test:coverage
🤝 贡献指南
欢迎 Issue 与 PR,建议遵循以下流程:
- Fork 仓库
- 创建新分支进行开发
- 提交 PR 前请确保测试通过、风格一致
- 提交详细描述
📜 License
MIT License. See the LICENSE file for details.
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-11