PHP code example of hizpark / scoped-storage-strategy

1. Go to this page and download the library: Download hizpark/scoped-storage-strategy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hizpark / scoped-storage-strategy example snippets


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');

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');

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');

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;
}

namespace Hizpark\ScopedStorageStrategy;

interface SessionInitializerInterface
{
    public function initialize(): void;
}
txt
src/
├── ScopedStorageStrategyInterface.php
├── SessionInitializerInterface.php
├── Session/
│   ├── SessionStorageStrategy.php
│   ├── SessionInitializerWithCookie.php
│   └── SessionInitializerWithToken.php
└── Redis/
    └── RedisStorageStrategy.php