PHP code example of pklink / dotor

1. Go to this page and download the library: Download pklink/dotor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pklink / dotor example snippets




// 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);

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

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

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

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

$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

$config->getBoolean('oneString', false);   // returns true
$config->getBoolean('twoString', false);   // returns false
$config->getBoolean('twoString');          // returns true
sh
php composer.phar install
bash
php composer.phar install --dev
php vendor/bin/phpunit tests/
bash
php composer.phar install --dev
php vendor/bin/phpunit --coverage-html output tests/