public function testGet() { $this->conf->set('db.options.tables.book', ['columns' => ['id' => 'INT(9) UNSIGNED NOT NULL PRIMARY KEY', 'title' => 'VARCHAR(50) NOT NULL', 'author' => 'VARCHAR(50)']]); $this->assertArrayHasKey('book', $this->conf->get('db.options.tables')); $this->assertEquals('VARCHAR(50)', $this->conf->get('db.options.tables.book.columns.author')); $this->assertNull($this->conf->get('db.options.tables.author')); $this->assertEquals('__default__', $this->conf->get('db.options.tables.author', '__default__')); $this->assertEquals('__custom__', $this->conf->get('db.options.tables.author', function ($a, $b, $c) { return "{$a}{$b}{$c}"; }, ['__', 'custom', '__'])); $this->conf->lazySet('db.options.tables.author', function () { return ['columns' => ['id' => 'INT(9) UNSIGNED NOT NULL PRIMARY KEY', 'name' => "VARCHAR(50) NOT NULL"]]; }); $this->assertInternalType('array', $this->conf->get('db.options.tables.author')); $this->assertEquals('INT(9) UNSIGNED NOT NULL PRIMARY KEY', $this->conf->get('db.options.tables.author.columns.id')); }
<?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,)