2017 © Pedro Peláez
 

joomla-package registry

Joomla Registry Package

image

joomla/registry

Joomla Registry Package

  • Saturday, July 14, 2018
  • by mbabker
  • Repository
  • 9 Watchers
  • 9 Stars
  • 77,907 Installations
  • PHP
  • 33 Dependents
  • 8 Suggesters
  • 14 Forks
  • 1 Open issues
  • 28 Versions
  • 3 % Grown

The README.md

The Registry Package Build Status

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

``` php use Joomla\Registry\Registry;, (*2)

$registry = new Registry;, (*3)

// Set a value in the registry. $registry->set('foo', 'bar');, (*4)

// Get a value from the registry; $value = $registry->get('foo');, (*5)


## Load config by Registry ``` php use Joomla\Registry\Registry; $registry = new Registry; // Load by string $registry->loadString('{"foo" : "bar"}'); $registry->loadString('<root></root>', 'xml'); // Load by object or array $registry->loadObject($object); $registry->loadArray($array); // Load by file $registry->loadFile($root . '/config/config.json', 'json');

Accessing a Registry by getter & setter

Get value

``` php $registry->get('foo');, (*6)

// Get a non-exists value and return default $registry->get('foo', 'default');, (*7)

// OR, (*8)

$registry->get('foo') ?: 'default';, (*9)


### Set value ``` php // Set value $registry->set('bar', $value); // Sets a default value if not already assigned. $registry->def('bar', $default);

Accessing children value by path

``` php $json = '{ "parent" : { "child" : "Foo" } }';, (*10)

$registry = new Registry($json);, (*11)

$registry->get('parent.child'); // return 'Foo', (*12)

$registry->set('parent.child', $value);, (*13)


## Removing values from Registry ``` php // Set value $registry->set('bar', $value); // Remove the key $registry->remove('bar'); // Works for nested keys too $registry->set('nested.bar', $value); $registry->remove('nested.bar');

Accessing a Registry as an Array

The Registry class implements ArrayAccess so the properties of the registry can be accessed as an array. Consider the following examples:, (*14)

``` php // Set a value in the registry. $registry['foo'] = 'bar';, (*15)

// Get a value from the registry; $value = $registry['foo'];, (*16)

// Check if a key in the registry is set. if (isset($registry['foo'])) { echo 'Say bar.'; }, (*17)


## Merge Registry #### Using load* methods to merge two config files. ``` php $json1 = '{ "field" : { "keyA" : "valueA", "keyB" : "valueB" } }'; $json2 = '{ "field" : { "keyB" : "a new valueB" } }'; $registry->loadString($json1); $registry->loadString($json2);

Output, (*18)

Array(
    field => Array(
        keyA => valueA
        keyB => a new valueB
    )
)

Merge another Registry

``` php $object1 = '{ "foo" : "foo value", "bar" : { "bar1" : "bar value 1", "bar2" : "bar value 2" } }';, (*19)

$object2 = '{ "foo" : "foo value", "bar" : { "bar2" : "new bar value 2" } }';, (*20)

$registry1 = new Registry(json_decode($object1)); $registry2 = new Registry(json_decode($object2));, (*21)

$registry1->merge($registry2);, (*22)


If you just want to merge first level, do not hope recursive: ``` php $registry1->merge($registry2, false); // Set param 2 to false that Registry will only merge first level

Dump to file.

``` php $registry->toString();, (*23)

$registry->toString('xml');, (*24)

$registry->toString('ini');, (*25)


## Dump to one dimension ``` php $array = array( 'flower' => array( 'sunflower' => 'light', 'sakura' => 'samurai' ) ); $registry = new Registry($array); // Make data to one dimension $flatted = $registry->flatten(); print_r($flatted);

The result:, (*26)

Array
(
    [flower.sunflower] => light
    [flower.sakura] => samurai
)

Using YAML

Add Symfony YAML component in composer.json, (*27)

``` json { "require-dev": { "symfony/yaml": "~2.0" } }, (*28)


Using `yaml` format ``` php $registry->loadFile($yamlFile, 'yaml'); $registry->loadString('foo: bar', 'yaml'); // Convert to string $registry->toString('yaml');

Using XML

Keep in mind that due to XML complexity, special format must be kept when loading into Registry. By default, the parent XML element should be named "registry" and all child elements should be named "node". The nodes should include a "name" attribute, for the name of the value. The nodes can be optionally filtered with a "type" attribute. Valid types are:, (*29)

  • array
  • boolean
  • double
  • integer
  • object (default)
  • string

Loading input, (*30)

``` xml bar 1 42 3.1415 value value , (*31)


with `Registry` ``` php $registry = new Registry; // Load file or string $registry->loadFile($xmlFile, 'xml'); $registry->loadString($xmlString, 'xml');

Outputs, (*32)

Array(
    foo_1 => bar
    foo_2 => 1
    foo_3 => 42
    foo_4 => 3.1415
    foo_5 => Array(
        foo_5_a => value
    )
    foo_6 => Array(
        foo_6_a => value
    )
)

The names of the XML import nodes can be customised using options. For example:, (*33)

``` php $registry = new Registry(array( 'name' => 'data', 'nodeName' => 'value' ));, (*34)

$registry->loadString('bar, 'xml');, (*35)


## Custom Formats To load your own custom format you must implement the `Joomla\Registry\FormatInterface`. This can then be loaded through the `Joomla\Registry\Factory` class. To load a custom format not provided by Joomla then you can load it by using `Factory::getFormat($type, $options)` In this scenario `$type` contains the format (and class) name. Whilst `$options` is an array with the key `format_namespace` which contains the namespace that the format is in. ## Installation via Composer Add `"joomla/registry": "~1.0"` to the require block in your composer.json and then run `composer install`. ```json { "require": { "joomla/registry": "~1.0" } }

Alternatively, you can simply run the following from the command line:, (*36)

composer require joomla/registry "~1.0"

The Versions

14/07 2018

dev-2.0-dev

dev-2.0-dev https://github.com/joomla-framework/registry

Joomla Registry Package

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

 

The Development Requires

framework registry joomla

08/03 2017

dev-registry-into-registry

dev-registry-into-registry https://github.com/joomla-framework/registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

19/04 2016
19/05 2014

1.1.3

1.1.3.0 https://github.com/joomla-framework/registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

09/02 2014

1.1.2

1.1.2.0 https://github.com/joomla-framework/registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

09/02 2014

1.1.1

1.1.1.0 https://github.com/joomla/joomla-framework-registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

08/02 2014

1.1.0

1.1.0.0 https://github.com/joomla/joomla-framework-registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

28/11 2013

1.0

1.0.0.0 https://github.com/joomla/joomla-framework-registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

22/10 2013

1.0-beta3

1.0.0.0-beta3 https://github.com/joomla/joomla-framework-registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

16/08 2013

1.0-beta2

1.0.0.0-beta2 https://github.com/joomla/joomla-framework-registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

16/08 2013

1.0-beta

1.0.0.0-beta https://github.com/joomla/joomla-framework-registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla

04/06 2013

1.0-alpha

1.0.0.0-alpha https://github.com/joomla/joomla-framework-registry

Joomla Registry Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework registry joomla