$Date$
This example introduce a facility to initialize default configuration data of an application. You may choice source and format of data (see PEAR::Config for containers list and options).
[Top]
$registry = &Registry::singleton(); $app = 'sw4p'; $registry->registerApplication($app, [$name = '', [$fileroot = '.']]); ... $name = 'data/default1.php'; $imp = $registry->setDefaults($app, [$name = null, [$type = 'phpArray', [$options = array()]]]);
[Top]
string $app The target application string $name (optional) Resource to read from string $type (optional) Type of data source (phpArray, Ini, XML, ...) array $options (optional) Options for the parser
[Top]
<?php
/**
* Example C5 for Config_Registry : import default configuration data
*
* @version 0.1
* @author Laurent Laville <pear@laurent-laville.org>
* @access public
* @package Config_Registry
* @license http://www.php.net/license/3_0.txt PHP License 3.0
*
* $Id$
*/
require_once 'Config/Registry.php';
require_once '../handleError.php';
print "<h1>Import easily defaults configuration data </h1>";
$registry =& Config_Registry::singleton();
$app = 'sw4p';
$reg = $registry->registerApplication($app, '', realpath('.'));
handleError($reg);
print "<h2>try 1</h2>";
$data2 = 'data/default.php';
$type = 'phpArray';
$init = $registry->setDefaults($app, $data2, $type, array('name' => 'def'));
handleError($init);
echo '<font color="blue"><b>Initialize "'.$app.'" defaults from file "'.$data2 .'" ('.$type.')<br/></b></font>';
$conf = $registry->getConfigLayer('default', $app);
print "<pre>";
var_dump($conf);
print "</pre>";
?>
[Top]