PHPackages                             hizpark/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. hizpark/scoped-storage-strategy

ActiveLibrary[Caching](/categories/caching)

hizpark/scoped-storage-strategy
===============================

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

v2.0.0(8mo ago)0381MITPHPPHP &gt;=8.2CI passing

Since Apr 9Pushed 8mo ago1 watchersCompare

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

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

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

[](#scoped-storage-strategy)

[![License](https://camo.githubusercontent.com/056df826cd34029952098e8f05052f9fee0cd1070920f7e426c20a0a29c6cf9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68697a7061726b2f73636f7065642d73746f726167652d7374726174656779)](https://camo.githubusercontent.com/056df826cd34029952098e8f05052f9fee0cd1070920f7e426c20a0a29c6cf9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68697a7061726b2f73636f7065642d73746f726167652d7374726174656779)

A pluggable and namespace-aware storage abstraction for temporarily persisting key-value data during scoped user interactions. This strategy supports session-based (cookie and token) and Redis-based implementations, and is designed to decouple application logic from underlying storage mechanisms.

Ideal for tracking transient states — such as validation progress, multistep workflows, or temporary metadata — using a consistent and replaceable strategy.

Features
--------

[](#features)

- 🍪 **Cookie-based PHP session**
- 🆔 **Token-based PHP session** (stateless API support)
- 🚀 **Redis storage** for shared, scalable scenarios
- 🔌 PSR-style interface for easy integration and extension
- ✅ Unified interface with `put`, `get`, `exists`, `remove`, `clear`, etc.

Installation
------------

[](#installation)

```
composer require hizpark/scoped-storage-strategy
```

Directory Structure
-------------------

[](#directory-structure)

```
src/
├── ScopedStorageStrategyInterface.php
├── SessionInitializerInterface.php
├── Session/
│   ├── SessionStorageStrategy.php
│   ├── SessionInitializerWithCookie.php
│   └── SessionInitializerWithToken.php
└── Redis/
    └── RedisStorageStrategy.php
```

Usage
-----

[](#usage)

### 1. SessionStorageStrategy with Cookie

[](#1-sessionstoragestrategy-with-cookie)

```
use Hizpark\ScopedStorageStrategy\SessionStorageStrategy;
use Hizpark\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');
```

### 2. SessionStorageStrategy with Token (for stateless APIs)

[](#2-sessionstoragestrategy-with-token-for-stateless-apis)

```
use Hizpark\ScopedStorageStrategy\SessionStorageStrategy;
use Hizpark\ScopedStorageStrategy\SessionInitializerWithToken;

$token = $_GET['token'] ?? ''; // or from Authorization header
$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');
```

### 3. RedisStorageStrategy

[](#3-redisstoragestrategy)

```
use Hizpark\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');
```

Interface
---------

[](#interface)

All strategies implement the following interface:

```
namespace Hizpark\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;
}
```

And session-based strategies require a session initializer:

```
namespace Hizpark\ScopedStorageStrategy;

interface SessionInitializerInterface
{
    public function initialize(): void;
}
```

---

📜 License
---------

[](#-license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance60

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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 ~73 days

Total

3

Last Release

251d 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://www.gravatar.com/avatar/ebedf625b7a40647c79c0b4788067638b60eb50ed9d0cab47ea0852e03772020?d=identicon)[changhorizon](/maintainers/changhorizon)

---

Tags

redisstoragesessionstrategyscoped

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[jrschumacher/symfony-redis-session-handler

Redis Session Handler Symfony HttpFoundation Component

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

Enhanced redis driver for sessions in Laravel

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

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

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

PHPackages © 2026

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