2017 © Pedro Peláez
 

library dotor

Easy access to array values using dot notation. Useful for handling configurations or something like that

image

pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or something like that

  • Sunday, January 3, 2016
  • by pklink
  • Repository
  • 1 Watchers
  • 3 Stars
  • 659 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Dotor Build Status Scrutinizer Quality Score

Dotor is a library for PHP 5.6 and higher to access an array by using dot notification. This can be useful for handling array configurations or something like that, (*1)

Installation

Install Dotor with Composer, (*2)

Create or update your composer.json, (*3)

{
    "require": {
        "pklink/dotor": "2.*"
    }
}

And run Composer, (*4)

php composer.phar install

Finally include Composers autoloader, (*5)

include __DIR__ . '/vendor/autoload.php';

Usage

Using `Dotor is very simple. Create an instance with your (configurarion) array..., (*6)

// config-sample.php
return [
    'name' => 'sample configuration',
    'database' => [
        'server'   => 'localhost',
        'username' => 'root',
        'password' => 'password',
        'database' => 'blah',
        'type'     => 'sqlite'
    ],
    'object' => new stdClass(),
    'false'      => false,
    'true'       => true,
    'zeroString' => '0',
    'zeroInt'    => 0,
    'oneString'  => '1',
    'oneInt'     => 1,
    'twoString'  => '2',
];
$loader = ArrayLoader::createFromFile('./config-sample.php');
$config = new Dotor($loader);

... and get the content by the get()-method., (*7)

$config->get('name');
$config->get('database.server');

Default values

$config->get('asdasdas');         // returns null
$config->get('asdasdas', 'blah'); // returns 'blah'

Scalar values

$config->getScalar('object');           // returns ''
$config->getScalar('object', 'blah');   // returns 'blah'
$config->getScalar('not-existing');     // returns ''
$config->getScalar('not-existing', []); // throw InvalidArgumentException

Arrays

$config->getArray('database');      // returns the database array
$config->getArray('notexit');       // returns []
$config->getArray('notexit', [1]);  // returns [1]

Boolean

$config->getBoolean('database', false);   // returns false
$config->getBool('database', true);       // returns true
$config->getBoolean('zeroString', true);  // returns false
$config->getBoolean('zeroInt', true);     // returns false
$config->getBoolean('oneString', false);  // returns true
$config->getBoolean('oneInt', false);     // returns true

The getBoolean()-method and their alias getBool() handle the string '1' and the integer 1 as true. Otherwise this method returns the given $default or true., (*8)

$config->getBoolean('oneString', false);   // returns true
$config->getBoolean('twoString', false);   // returns false
$config->getBoolean('twoString');          // returns true

Run tests

php composer.phar install --dev
php vendor/bin/phpunit tests/

or with code-coverage-report, (*9)

php composer.phar install --dev
php vendor/bin/phpunit --coverage-html output tests/

License

This package is licensed under the BSD 2-Clause License. See the LICENSE file for details., (*10)

Credits

This package is inspired by php-dotty, (*11)

The Versions

03/01 2016

dev-master

9999999-dev https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or something like that

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

dot settings configuration config array dot-notation

03/01 2016

2.0.0

2.0.0.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or something like that

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

dot settings configuration config array dot-notation

27/06 2014

1.1.0

1.1.0.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

dot settings configuration config array dot-notation

16/02 2014

1.0.0

1.0.0.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

dot settings configuration config array dot-notation

15/03 2013

0.2

0.2.0.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

dot settings configuration config array dot-notation

26/02 2013

0.1.3.1

0.1.3.1 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

dot settings configuration config array dot-notation

26/02 2013

0.1.3

0.1.3.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

dot settings configuration config array dot-notation

23/02 2013

0.1.2

0.1.2.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

dot settings configuration config array dot-notation

11/02 2013

0.1.1

0.1.1.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.4.0

 

The Development Requires

dot settings configuration config array dot-notation

11/02 2013

0.1

0.1.0.0 https://github.com/pklink/dotor

Easy access to array values using dot notation. Useful for handling configurations or so

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

dot settings configuration config array dot-notation