PHPackages                             changhorizon/scoped-storage-strategy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. changhorizon/scoped-storage-strategy

ActiveLibrary[Caching](/categories/caching)

changhorizon/scoped-storage-strategy
====================================

A flexible and pluggable storage strategy for managing scoped, temporary key-value data using sessions, tokens, Redis, and more.

v2.1.2(4w ago)0271MITPHPPHP &gt;=8.2CI passing

Since Apr 9Pushed 4w ago1 watchersCompare

[ Source](https://github.com/changhorizon/scoped-storage-strategy)[ Packagist](https://packagist.org/packages/changhorizon/scoped-storage-strategy)[ RSS](/packages/changhorizon-scoped-storage-strategy/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (4)Versions (7)Used By (1)

Scoped Storage Strategy
=======================

[](#scoped-storage-strategy)

> A pluggable and namespace-aware storage abstraction for temporarily persisting key-value data during scoped user interactions.

[![License](https://camo.githubusercontent.com/ea24d8aa6e77083c1ae42e51de16102ab1bea2c4fd21a30d7561ae0b4d7e8ce1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6368616e67686f72697a6f6e2f73636f7065642d73746f726167652d73747261746567793f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ea24d8aa6e77083c1ae42e51de16102ab1bea2c4fd21a30d7561ae0b4d7e8ce1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6368616e67686f72697a6f6e2f73636f7065642d73746f726167652d73747261746567793f7374796c653d666c61742d737175617265)[![Latest Version](https://camo.githubusercontent.com/f30918f50cd5b81fa119f71630143b09519fc25bf4c3b443ddbcfdbe36ac90f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368616e67686f72697a6f6e2f73636f7065642d73746f726167652d73747261746567793f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f30918f50cd5b81fa119f71630143b09519fc25bf4c3b443ddbcfdbe36ac90f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368616e67686f72697a6f6e2f73636f7065642d73746f726167652d73747261746567793f7374796c653d666c61742d737175617265)[![PHP Version](https://camo.githubusercontent.com/10b897c523f00fa3f8f7b54dfe73999190e622480655d5b5f011e31fc32a7111/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322d2d382e342d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/10b897c523f00fa3f8f7b54dfe73999190e622480655d5b5f011e31fc32a7111/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322d2d382e342d626c75653f7374796c653d666c61742d737175617265)[![Static Analysis](https://camo.githubusercontent.com/1a477f5e7e742a33c1ff5b685167579083a26c342c4e997fe056ea4ef7bea73e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617469635f616e616c797369732d5048505374616e2d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/1a477f5e7e742a33c1ff5b685167579083a26c342c4e997fe056ea4ef7bea73e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617469635f616e616c797369732d5048505374616e2d626c75653f7374796c653d666c61742d737175617265)[![Tests](https://camo.githubusercontent.com/72829871c802983bff15745f71c846973b36a6fea0bb5298dadaeeb690463604/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d504850556e69742d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/72829871c802983bff15745f71c846973b36a6fea0bb5298dadaeeb690463604/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d504850556e69742d627269676874677265656e3f7374796c653d666c61742d737175617265)[![codecov](https://camo.githubusercontent.com/e65575e1b3d6d9e4da7f925885792a4d161b16d3c9cd9fa4b040116a4318bafd/68747470733a2f2f636f6465636f762e696f2f67682f6368616e67686f72697a6f6e2f73636f7065642d73746f726167652d73747261746567792f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/changhorizon/scoped-storage-strategy)[![CI](https://github.com/changhorizon/scoped-storage-strategy/actions/workflows/ci.yml/badge.svg?style=flat-square)](https://github.com/changhorizon/scoped-storage-strategy/actions/workflows/ci.yml/badge.svg?style=flat-square)

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

[](#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

[](#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

[](#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，建议遵循以下流程：

1. Fork 仓库
2. 创建新分支进行开发
3. 提交 PR 前请确保测试通过、风格一致
4. 提交详细描述

📜 License
---------

[](#-license)

MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance94

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Recently: every ~99 days

Total

6

Last Release

29d ago

Major Versions

v1.0.1 → v2.0.02025-09-03

PHP version history (2 changes)v1.0.0PHP &gt;=8.1

v2.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/191742660?v=4)[ChangHorizon](/maintainers/changhorizon)[@changhorizon](https://github.com/changhorizon)

---

Top Contributors

[![changhorizon](https://avatars.githubusercontent.com/u/191742660?v=4)](https://github.com/changhorizon "changhorizon (9 commits)")

---

Tags

redisstoragesessionstrategyscoped

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/changhorizon-scoped-storage-strategy/health.svg)

```
[![Health](https://phpackages.com/badges/changhorizon-scoped-storage-strategy/health.svg)](https://phpackages.com/packages/changhorizon-scoped-storage-strategy)
```

###  Alternatives

[jrschumacher/symfony-redis-session-handler

Redis Session Handler Symfony HttpFoundation Component

1262.1k](/packages/jrschumacher-symfony-redis-session-handler)[craftsys/laravel-redis-session-enhanced

Enhanced redis driver for sessions in Laravel

107.0k](/packages/craftsys-laravel-redis-session-enhanced)[dmitry-suffi/redis-session-handler

Обработчик сессий через Redis с механизмом блокировки

113.2k](/packages/dmitry-suffi-redis-session-handler)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
