Ejemplo n.º 1
0
<?php

function v()
{
    //call_user_func_array('var_dump', func_get_args());
}
include '../../vendor/autoload.php';
use Requtize\Config\Config;
use Requtize\Config\Loader\PhpLoader;
use Requtize\Config\Loader\IniLoader;
use Requtize\Config\Loader\YamlLoader;
$config1 = new Config();
$config1->appendFromLoader(new PhpLoader(realpath('../resources/full-same-php.php')));
$config2 = new Config();
$config2->appendFromLoader(new IniLoader(realpath('../resources/full-same-ini.ini')));
$config3 = new Config();
$config3->appendFromLoader(new YamlLoader(realpath('../resources/full-same-yaml.yaml')));
v('PHP', $config1->all(), 'INI', $config2->all(), 'YAML', $config3->all());
v('--', '--', '----------------------------------------------------', '--', '--', $config1->get('float'), $config1->get('string'), $config1->get('first.keyTwo'), $config1->get('first.innerOne.innerTwo.innerThree'), $config1->get('database.bkp2.pass'));
v('--', '--', '----------------------------------------------------', '--', '--', $config2->get('float'), $config2->get('string'), $config2->get('first.keyTwo'), $config2->get('first.innerOne.innerTwo.innerThree'), $config2->get('database.bkp2.pass'));
v('--', '--', '----------------------------------------------------', '--', '--', $config3->get('float'), $config3->get('string'), $config3->get('first.keyTwo'), $config3->get('first.innerOne.innerTwo.innerThree'), $config3->get('database.bkp2.pass'));
v('--', '--', '------------------------MERGED-CONFIGS----------------------------', '--', '--', $config1->merge($config2)->merge($config3)->all());
//$config1->setCacheFilepath(__DIR__.'/!cache-file')->saveToCache();
echo 'asd';
$configCached = new Config(__DIR__ . '/!cache-file');
$configCached->appendFromLoader(new PhpLoader(realpath('../resources/full-same-php.php')));
$configCached->appendFromLoader(new IniLoader(realpath('../resources/full-same-ini.ini')));
$configCached->appendFromLoader(new YamlLoader(realpath('../resources/full-same-yaml.yaml')));
v('--', '--', '------------------------CACHED-CONFIGS----------------------------', '--', '--', $configCached->all());
$configCached->saveToCache();
Ejemplo n.º 2
0
use Requtize\Config\Config;
use Requtize\Config\Loader\PhpLoader;
use Requtize\Config\Loader\IniLoader;
use Requtize\Config\Loader\YamlLoader;
if (is_file(__DIR__ . '/!cache-file')) {
    unlink(__DIR__ . '/!cache-file');
}
$times = [];
$start = microtime(true);
$config = new Config(__DIR__ . '/!cache-file');
$config->import(realpath('../resources/full-same-php.php'));
$config->import(realpath('../resources/full-same-ini.ini'));
$config->import(realpath('../resources/full-same-yaml.yaml'));
$times['import-6-files'] = number_format(microtime(true) - $start, 4);
$start = microtime(true);
$config->saveToCache();
$times['save-to-cache'] = number_format(microtime(true) - $start, 4);
$start = microtime(true);
$config = new Config(__DIR__ . '/!cache-file');
$config->import(realpath('../resources/full-same-php.php'));
$config->import(realpath('../resources/full-same-ini.ini'));
$config->import(realpath('../resources/full-same-yaml.yaml'));
$times['get-from-cache'] = number_format(microtime(true) - $start, 4);
touch(realpath('../resources/full-same-yaml.yaml'));
$start = microtime(true);
$config = new Config(__DIR__ . '/!cache-file');
$config->import(realpath('../resources/full-same-php.php'));
$config->import(realpath('../resources/full-same-ini.ini'));
$config->import(realpath('../resources/full-same-yaml.yaml'));
$times['get-from-cache-with-1-file-modified'] = number_format(microtime(true) - $start, 4);
var_dump($times);
Ejemplo n.º 3
0
    public function testSaveToCache()
    {
        $reflectionAnyFileChanged = new ReflectionProperty('Requtize\\Config\\Config', 'anyFileChanged');
        $reflectionAnyFileChanged->setAccessible(true);
        $config = new Config();
        $file1 = <<<EOF
<?php return [ 'child1' => 'value-from-child-1' ];
EOF;
        $child1 = pathinfo($this->createTmpFile($file1), PATHINFO_BASENAME);
        $file = <<<EOF
<?php return [
    'parent' => 'value-from-parent',
    'imports' => [
        'files' => [
            '{$child1}'
        ]
    ]
];
EOF;
        // Save file with configuration
        $path = $this->createTmpFile($file);
        // Create empty file for cache data.
        $cacheFile = $this->createTmpFile('');
        $config->setCacheFilepath($cacheFile);
        $config->appendFromLoader(new PhpLoader($path));
        // Before save cache, this file should be empty
        $this->assertEquals('', file_get_contents($cacheFile));
        $config->saveToCache();
        // After save cache, file should not be empty...
        $this->assertNotEquals('', file_get_contents($cacheFile));
        // ...and Config::anyFileChanged should be true
        $this->assertEquals(true, $reflectionAnyFileChanged->getValue($config));
        // Reset cache file and Config::anyFileChanged property
        file_put_contents($cacheFile, '');
        $reflectionAnyFileChanged->setValue($config, false);
        // Ensure that resetting done ok.
        $this->assertEquals(false, $reflectionAnyFileChanged->getValue($config));
        $this->assertEquals('', file_get_contents($cacheFile));
        // Save to cache again and...
        $config->saveToCache();
        // ...should not be saved, because nothing changed, no new files was added.
        $this->assertEquals(false, $reflectionAnyFileChanged->getValue($config));
        $this->assertEquals('', file_get_contents($cacheFile));
    }