netherphp / datastore
Redux of Datastore from Common
v0.0.4
2026-11-07 18:14 UTC
Requires
- php: ^8.5
- netherphp/filter: ^0
- netherphp/meta: ^0
Requires (Dev)
- phpunit/phpunit: ^13
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-07 18:16:35 UTC
README
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));