poirot/storage

There is no license information available for the latest version (dev-devel) of this package.

An Abstraction key-value store API.

dev-devel 2019-08-08 18:52 UTC

This package is auto-updated.

Last update: 2024-04-09 04:27:26 UTC


README

InMemory Store

// Storage for 'test' Realm.

$s = new InMemoryStore('test');
$s->set('name', 'Payam');
$s->set('family', 'Naderi');

$fullname = $s->getFromKeys(['name', 'family']);
$fullname = StdTravers::of($fullname)
    ->each(function($val, $_ ,$prev) {
        return $prev.= ' '.$val;
    });

print_r($fullname);

FlatFile Store

$s = new FlatFileStore('user_codes');
        
$user_id = 'd5e110k33f';
$s->set($user_id, '1453');
// Without this syntax storage will save given entity when dispatch shutdown.
$s->save(); // force to save current 

In Next Calls

values can be retrieved.

$s = new FlatFileStore('user_codes');
if ($s->has('d5e110k33f'))
    print_r($s->get('d5e110k33f'));

Destroy Storage

will destroy storage for given 'user_codes' realm.

$s = new FlatFileStore('user_codes');
$s->destroy();

Choose Desired Options

Options In under_score with construct

$s = new FlatFileStore('user_codes', ['dir_path' => __DIR__.'/my_user_codes.dat']);
$s->set('key', 'value');

will map to setter methods

$s = new FlatFileStore('user_codes');
$s->setPathDir(__DIR__.'/my_user_codes.dat');
$s->set('key', 'value');

Mongo Store

$client     = \Module\MongoDriver\Actions::Driver()->getClient('master');
$collection = $client->selectCollection('papioniha', 'store.app');

$s = new MongoStore('pass_trough', ['collection' => $collection]);

// Traverse All Data

$v = StdTravers::of( $s )
    ->each(function($val, $key ,$prev) {
        if ( is_array($prev) )
            return $prev[$key] = $val;

        return [$key => $val];
    });

print_r($v);