function bench($repeats)
{
    echo 'Running bench with ', $repeats, ' repeats', PHP_EOL;
    $configs_dir = __DIR__ . '/config/';
    $merged_file = __DIR__ . '/config_merged.php';
    $cached_file = __DIR__ . '/config_cached.php';
    $simple_loader = new FilesLoader($configs_dir);
    $merged_loader = new \Pinepain\SimpleConfig\Loaders\MergedFilesLoader($simple_loader, $merged_file);
    $cached_loader = new \Pinepain\SimpleConfig\Loaders\FileCacheLoader($simple_loader, $cached_file);
    $t = microtime(true);
    for ($i = 0; $i < $repeats; $i++) {
        $simple_loader->load();
    }
    echo '    Simple loading: ', microtime(true) - $t, PHP_EOL;
    $t = microtime(true);
    for ($i = 0; $i < $repeats; $i++) {
        $merged_loader->load();
    }
    echo '    Merged loading: ', microtime(true) - $t, PHP_EOL;
    $t = microtime(true);
    for ($i = 0; $i < $repeats; $i++) {
        $cached_loader->load();
    }
    echo '    Cached loading: ', microtime(true) - $t, PHP_EOL;
    echo PHP_EOL;
}
 public function testGetConfigFiles()
 {
     $loader = new FilesLoader('config directory path not in use in this case');
     $expected = ['test' => 'vfs://root/test.php', 'foo' => 'vfs://root/foo.php', 'bar' => 'vfs://root/bar.php'];
     $this->assertSame($expected, $loader->getConfigFiles(vfsStream::url('root')));
 }
Example #3
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pinepain\SimpleConfig\Loaders\FilesLoader;
use Pinepain\SimpleConfig\Config;
// it's good idea to use some dotenv library here and load env-specific env variables to use them later
// in configs
// Ok, let's load our config. Note, that we load only files that do not starts with `.` (dot) and have
// .php extension
$loader = new FilesLoader(__DIR__ . '/config');
$config_items = $loader->load();
// No we have all config items stored as array in $config_items
// In fact, Config is just tinny wrapper for array dot notation, so no magic here, just sugar
$config = new Config($config_items);
// Hey, do we have default database connection config section?
var_export($config->has('db.connections.default'));
// Output:
//true
echo PHP_EOL;
echo PHP_EOL;
var_export($config->get('db.connections.default'));
// Output:
//array(
//    'driver' => 'mysql',
//    'host' => 'localhost',
//    'port' => 3306,
//    'user' => 'guest',
//    'password' => 'secret',
//)
echo PHP_EOL;
echo PHP_EOL;