public function testLazySet()
 {
     $this->conf->lazySet('db.options.tables.author', function ($len) {
         return ['columns' => ['id' => 'INT(9) UNSIGNED NOT NULL PRIMARY KEY', 'name' => "VARCHAR({$len}) NOT NULL"]];
     }, [50]);
     $this->assertInstanceOf(ConfigRepository::LAZY_VAL_CLASS, $this->conf->asArray()['db']['options']['tables']['author']);
     $this->assertEquals('VARCHAR(50) NOT NULL', $this->conf->get('db.options.tables.author.columns.name'));
     $this->assertEquals('VARCHAR(50) NOT NULL', $this->conf->asArray()['db']['options']['tables']['author']['columns']['name']);
     $this->conf->lazySet('db.options.tables.book', function () {
         return ['columns' => ['id' => 'INT(9) UNSIGNED NOT NULL PRIMARY KEY', 'title' => 'VARCHAR(50) NOT NULL', 'author' => 'VARCHAR(50)']];
     }, null, true);
     $this->assertInstanceOf(ConfigRepository::LAZY_VAL_CLASS, $this->conf->asArray()['db']['options']['tables']['book']);
     $this->assertEquals('VARCHAR(50)', $this->conf->get('db.options.tables.book.columns.author'));
     $this->assertInstanceOf(ConfigRepository::LAZY_VAL_CLASS, $this->conf->asArray()['db']['options']['tables']['book']);
 }
Ejemplo n.º 2
0
<?php

require_once 'config-repository.php';
echo '<pre>';
$conf = new ConfigRepository();
// set/get
$conf->set('email', '*****@*****.**');
var_export($conf->get('email'));
// '*****@*****.**'
echo PHP_EOL;
// get deep item
$conf->set('db', ['host' => '127.0.0.1', 'username' => 'admin', 'password' => 'qwerty12345']);
var_export($conf->get('db.username'));
// 'admin'
echo PHP_EOL;
// default value
var_export($conf->get('db.charset'));
// NULL
echo PHP_EOL;
var_export($conf->get('db.charset', 'UTF-8'));
// 'UTF-8'
echo PHP_EOL;
// remove
$conf->remove('db.password');
var_export($conf->get('db.password'));
// NULL
echo PHP_EOL;
// set deep item
$conf->set('db.options.attr.' . PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
var_export($conf->get('db.options.attr', []));
// array(3 => 2,)