changhorizon/scoped-storage-strategy
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.
changhorizon/scoped-storage-strategy 适用场景与选型建议
changhorizon/scoped-storage-strategy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「storage」 「session」 「strategy」 「scoped」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 changhorizon/scoped-storage-strategy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 changhorizon/scoped-storage-strategy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 changhorizon/scoped-storage-strategy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Secure session middleware for Slim 3 framework
Microservice RPC through message queues.
The CodeIgniter Redis package
Non-I/O blocking PHP SessionHandler implementation using Nette/Caching with DI Extension for Nette framework
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 47
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-11