-
Notifications
You must be signed in to change notification settings - Fork 12
5.8. Registry
A registry object contains methods to easily manage multidimensional arrays. Ideally registries are designed to organize all sorts of configurations and works well with JSON objects. Implementing this object can be done like so.
use Cradle\Data\Registry;
$registry1 = new Registry;
//or
$registry2 = new Registry(['zoo' => ['foo' => ['bar']]]);A registry object mounts ArrayAccessTrait, CountableTrait, GeneratorTrait,
IteratorTrait, MagicTrait, DotTrait
(see Data Traits) and implements 5 additional methods.
exists - Returns true if the data has the given key path or whether
if there is data at all.
$registry1->exists(); //--> false
$registry2->exists(); //--> true
$registry2->exists('zoo'); //--> true
$registry2->exists('zoo', 'foo'); //--> true
$registry2->exists('foo', 'bar'); //--> falseget - Returns part of the data given the key path or the entire data set.
$registry2->get(); //--> ['zoo' => ['foo' => ['bar']]]
$registry2->get('zoo'); //--> ['foo' => ['bar']]
$registry2->get('zoo', 'foo'); //--> ['bar']
$registry2->get('zoo', 'foo', 0); //--> 'bar'isEmpty - Returns true if the data, given key path is empty or whether
if there is data at all.
$registry1->isEmpty(); //--> true
$registry2->isEmpty(); //--> false
$registry2->isEmpty('zoo'); //--> false
$registry2->isEmpty('zoo', 'foo'); //--> false
$registry2->isEmpty('foo', 'bar'); //--> trueremove - Removes part of the data given the key path or the entire data set.
$registry2->remove('zoo', 'foo', 0); // 'bar'
$registry2->remove('zoo', 'foo'); // ['bar']
$registry2->remove('zoo'); // ['foo' => ['bar']]
$registry2->remove(); // ['zoo' => ['foo' => ['bar']]]
$registry2->remove('foo', 'bar'); // does nothing because it doesn't existset - Sets part of the data given the key path or the entire data set.
$registry2->set('zoo', 'foo', 0, 'bar'); // ['zoo' => ['foo' => ['bar']]]2.B. Reference: Validation Types
2.D. Reference: Indexes & Relations
3.A. Reference: Cradle on Shared Hosts
3.B. Reference: Command Line Tools
3.C. Reference: Architecture Recommendations
4.4. Intro to Handlebars Templating
4.B. Reference: Handlebars Helpers
4.C. Reference: Doon Interfaces
4.D. Reference: Global Package Methods