Skip to content
netherphpPublic

About

Redux of Datastore from Common as standalone.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

61 Commits

Folders and files

Repository files navigation

NetherPHP: Datastore

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

About

Redux of Datastore from Common as standalone.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages