Fluent storage repository with dot notated key support

0.1.0 2018-03-15 21:11 UTC

This package is auto-updated.

Last update: 2021-01-14 17:12:33 UTC


Travis Build Status Codacy Coverage Codacy Grade Packagist Downloads License

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.


require_once __DIR__ . '/vendor/autoload.php';

use Bhittani\Repository\Repository;

$storage = new Repository;

// See below examples for usage...

Store and retrieve values

// 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_']

Preset an undefined key

$storage->preset('a', 'b');
echo $storage->get('a'); // 'b'

$storage->set('x', 'y');
$storage->preset('x', 'z');
echo $storage->get('x'); // 'y'

Append a value

$storage->set('append', ['foo']);
$storage->append('append', 'bar');
var_dump($storage->get('append')); // ['foo', 'bar']

Prepend a value

$storage->set('prepend', ['foo']);
$storage->append('prepend', 'bar');
var_dump($storage->get('prepend')); // ['bar', 'foo]

Increment a value

echo $storage->get('incr'); // null

echo $storage->get('incr'); // 1

$storage->increment('incr', 5);
echo $storage->get('incr'); // 6

Decrement a value

echo $storage->get('decr'); // null

echo $storage->get('decr'); // -1

$storage->decerement('decr', 5);
echo $storage->get('decr'); // -6

Fallback to a default value

echo $storage->get('bar'); // null

echo $storage->get('bar', 'fallback'); // 'fallback'

Check whether a key is set

var_dump($storage->has('bar')); // (bool) false

Get all items

$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
$ cd repository
$ composer install
$ composer test


Please see CONTRIBUTING and CONDUCT for details.


If you discover any security related issues, please email instead of using the issue tracker.



The MIT License (MIT). Please see the License File for more information.