Search by

netherphp / datastore

bobmagicii

Redux of Datastore from Common

Package info

github.com/netherphp/datastore

pkg:composer/netherphp/datastore

Statistics

Installs: 32

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.4 2026-11-07 18:14 UTC

This package is auto-updated.

Last update: 2026-11-07 18:16:35 UTC


README

Packagist Build Status codecov

Provide a wrapper to work on collections of data instead of dealing with arrays directly by hand. Sane and consistent function naming, without having to guess the order of arguments for callable arugments. Also implements common SPL interfaces so the Datastore can be passed onto other things that accept generic iterables.

Documentation

See docs/API.md for full API documentation.

Example: creating a configuration and then using it later.

$Config = new Datastore([
	'APIKEY' => 'qwer-ty-asdf-gh-zxcv-bn',
	'Theme'  => 'dark'
]);
echo SomeCaptchaWidgetProbably(
	$Config['APIKEY'],
	$Config['Theme']
);

Example: processing a list of users into a mailing-list.json file.

(new Datastore($Users))
->Filter(fn(User $Who)=> $Who->HasOptedIn('emails'))
->SortByValue(fn(User $A, User $B)=> $A->Username <=> $B->Username)
->Remap(fn(User $Who)=> sprintf('%s <%s>', $Who->Username, $Who->Email))
->Reindex()
->Write('mailing-list.json');

Example: loading a mailing-list.json file from disk.

$Emails = Datastore::FromFile('mailing-list.json');
$Emails->Each(fn(string $To)=> print('* %s%s', $To, PHP_EOL));