Skip to content
Simple data manager for nested data and dot notation access, plus optional extras
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src v0.9.3 - Extract Collections (#56) Mar 8, 2017
tests
.gitattributes
.gitignore
.scrutinizer.yml
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE.md
README.md
composer.json
mkdocs.yml
phpunit.xml.dist
sami.php

README.md

Data Manager

Latest Version Documentation Status Software License Build Status Coverage Status Scrutinizer Code Quality Total Downloads

SensioLabsInsight

Simple data manager for nested data, dot notation access, extendability, and container interoperability.

See Full Documentation

Goals

  • Light weight and fluent, simple, clear API
  • Manage nested data via dot-notation
  • Be composable - integrate into current containers via traits (extras)
  • Include extras for
  • Allow for protected data (immutable) and default values.
  • IoC container should:
    • Resolve via classes, factories, etc
    • Configure dependencies for dependencies,
    • Allow for fallbacks, preparing objects, and more.
  • Full test coverage, PSR compliant, container interoperability, and best practices

Install

Via Composer

$ composer require michaels/data-manager

Getting Started

Manager does exactly what you would expect: it manages complex items such as config data, arrays, and closures. The best way to get started is simply instantiate Michaels\Manager\Manager

$manager = new Michaels\Manager\Manager([
    'some' => [
        'starting' => [
            'data' => 'here (optional)'
        ]
    ]
]);
// Note, you may initialize Manager with an array or any instance of Traversable (like Manager itself)

/* Basic Usage. All works with dot notation as well */
$manager->add('name', 'value');
$manager->add('some.nested.data', 3); // Use dot notation for namespacing or nesting
$manager->get('name'); // 'value'
$manager->get('doesntexist', 'fallback'); // 'fallback'
$manager->get('doesntexist') // throws an ItemNotFoundException with no fallback
$manager->getIfHas('doesntexist') // returns a NoItemFoundMessage instead of a script-stopping exception
$manager->getAll(); // returns array of all items
$manager->all(); // returns array of all items
$manager->exists('name'); // true
$manager->exists('some.starting.data'); // true
$manager->exists('nope'); // false
$manager->has('something'); // alias of exist
$manager->set('name', 'new-value'); // updates item
$manager->remove('some.starting.data');
$manager->isEmpty(); // true or false
$manager->toJson(); // returns json of all items
echo $manager; // returns json string of all items
$manager->reset($array); // rebuild with new items
$manager->clear(); // empty the manager

/* You can also use $manager as an array or in loops */
$manager['some']['starting']['data']; // 'here (optional)'
//etc

foreach ($manager as $item => $value) {
    // do whatever your heart desires
}

/* You may also push elements onto an array */
$manager->set('a.b', []);
$manager->push('a.b', 'c', 'd', 'e');
$manager->get('a.b'); // ['c', 'd', 'e']

/* Finally, you may manage values using magic methods */
$manager->some()->starting()->data; // 'here (optional)'
$manager->some()->item = 'item'; // sets some.item = 'item'
$manager->some()->item()->drop(); // deletes some.item

// Note that levels are called as a method with no params. The data is then called, updated, or set as a property.

Advanced Features

See documentation for topics like protecting data, using as an ioc container, loading files, using as an array, defaults, composing, and more.

Interoperability

Data Manager is PSR compliant and Container Interoperability compliant. Any oversights, please let me know.

Testing

We try for at least 80% test coverage.

$ phpunit

You may also use the tests under tests/traits to test your integrated functionality. You may have to grab these through cloning the repo. composer usually won't include tests in your require

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.

Security

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

Credits

License

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

You can’t perform that action at this time.