Fluent storage repository with dot notated key support.
You may install this package using composer.
$ composer require bhittani/repository
This package provides a fluent and intuitive storage repository.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Bhittani\Repository\Repository;
$storage = new Repository;
// See below examples for usage...
// Store and retrieve a value.
$storage->set('foo', 'bar');
echo $storage->get('foo'); // 'bar'
// Store an array and retrieve a value using dot notated key access.
$storage->set('app', ['name' => 'Acme', 'version' => '0.1.0']);
echo $storage->get('app.version'); // '0.1.0'
// Store a value using dot notated keys.
$storage->set('db.sqlite.path', ':memory:');
$storage->set('db.sqlite.prefix', 'acme_');
var_dump($storage->get('db.sqlite')); // ['path' => ':memory:', 'prefix' => 'acme_']
$storage->preset('a', 'b');
echo $storage->get('a'); // 'b'
$storage->set('x', 'y');
$storage->preset('x', 'z');
echo $storage->get('x'); // 'y'
$storage->set('append', ['foo']);
$storage->append('append', 'bar');
var_dump($storage->get('append')); // ['foo', 'bar']
$storage->set('prepend', ['foo']);
$storage->append('prepend', 'bar');
var_dump($storage->get('prepend')); // ['bar', 'foo]
echo $storage->get('incr'); // null
$storage->increment('incr');
echo $storage->get('incr'); // 1
$storage->increment('incr', 5);
echo $storage->get('incr'); // 6
echo $storage->get('decr'); // null
$storage->decerement('decr');
echo $storage->get('decr'); // -1
$storage->decerement('decr', 5);
echo $storage->get('decr'); // -6
echo $storage->get('bar'); // null
echo $storage->get('bar', 'fallback'); // 'fallback'
var_dump($storage->has('bar')); // (bool) false
$storage->add('foo', 'bar');
$storage->add('beep.boop', 'baz');
var_dump($storage->all()); // ['foo' => 'bar', 'beep' => ['boop' => 'baz']]
Please see CHANGELOG for more information on what has changed.
$ git clone https://github.com/kamalkhan/repository
$ cd repository
$ composer install
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email shout@bhittani.com
instead of using the issue tracker.
The MIT License (MIT). Please see the License File for more information.