* * @package Configuration * @subpackage Examples */ require 'autoload.php'; // A small example which reads an INI file and reads out some settings // It uses the array reader/writer to cache the INI file. // // If something goes wrong (file reading or setting access) it will catch // the exception and show the problem. try { $ini = new ezcConfigurationArrayReader(dirname(__FILE__) . '/settings.php'); if (!$ini->configExists()) { print "Cache does not exist, generating\n"; // Cache is not present so we read the original file $ini = new ezcConfigurationIniReader(dirname(__FILE__) . '/settings.ini'); $conf = $ini->load(); // Write back the cache $cache = new ezcConfigurationArrayWriter(dirname(__FILE__) . '/settings.php', $conf); $cache->save(); } else { print "Reading from cache\n"; $conf = $ini->load(); } $title = $conf->getSetting('site', 'title'); print "Title is {$title}\n"; } catch (Exception $e) { print "Caught exception while reading INI file\n"; print $e->getMessage() . "(" . $e->getCode() . ")\n"; print $e->getTraceAsString() . "\n"; }
public function testValidationNonStrict() { $settings = array('3D' => array('Decimal' => array(42, 0), 'Array' => array('Decimal' => array('a' => 42, 'b' => 0), 'Mixed' => array('b' => false, 2 => "Derick \"Tiger\" Rethans")))); $comments = array('3D' => array('Decimal' => array(" One with a comment", " Second one with a comment"), 'Array' => array('Mixed' => array(2 => " One with a comment")))); $test = new ezcConfiguration($settings, $comments); $path = $this->tempDir . '/multi-dim2.php'; $backend = new ezcConfigurationArrayWriter($path, $test); $backend->save(); $backend = new ezcConfigurationArrayReader($path); $return = $backend->validate(false); $expected = new ezcConfigurationValidationResult($backend->getLocation(), $backend->getName(), $path); $expected->isValid = true; $this->assertEquals($expected, $return); }
<?php require_once 'tutorial_autoload.php'; $writer = new ezcConfigurationArrayWriter(); $writer->init(dirname(__FILE__), "settings", $cfg); $writer->save();