/** * Config.php example * * Lots of different manipulations to show Config features. * * @author Bertrand Mansion <*****@*****.**> * @package Config */ // $Id: IniFromScratch.php,v 1.2 2003/03/21 18:04:21 mansion Exp $ require_once 'Config.php'; // Creates a PHPArray config with attributes, from scratch $dsn = array('type' => 'mysql', 'host' => 'localhost', 'user' => 'mamasam', 'pass' => 'foobar'); $c = new Config_Container('section', 'root'); $c->createComment('DB Config'); $db =& $c->createSection('DB', $dsn); $fields =& $db->createSection('fields'); $fields->createDirective('username', 'USERNAME', array('type' => 'varchar', 'size' => 32)); $fields->createDirective('password', 'PASSWD', array('type' => 'varchar', 'size' => 32)); $c->createBlank(); $c->createComment('Support config'); $c->createDirective('support', 'See my wishlist...'); echo '<pre>' . $c->toString('phparray') . '</pre>'; unset($c); // Parses and writes an existing php array $conf $conf['storage']['driver'] = 'sql'; $conf['storage']['params']['phptype'] = 'mysql'; $conf['storage']['params']['hostspec'] = 'localhost'; $conf['storage']['params']['username'] = '******'; $conf['storage']['params']['password'] = '******'; $conf['menu']['apps'] = array('imp', 'turba');
/** * Create config for adm * */ public function createAdmConfig($servarray) { //check for the directory structure if (!file_exists($this->objConfig->getcontentBasePath() . 'adm/')) { mkdir($this->objConfig->getcontentBasePath() . 'adm/', 0777); } // write the server list file $cfile = $this->objConfig->getcontentBasePath() . 'adm/adm.xml'; if (!file_exists($cfile)) { $conf = new Config_Container('section', 'adm'); //$servarray['name']); $conf_serv =& $conf->createSection($servarray['name']); $conf_serv->createDirective('servername', $servarray['name']); $conf_serv->createDirective('serverapiurl', $servarray['url']); $conf_serv->createDirective('serveremail', $servarray['email']); $conf_serv->createDirective('regtime', date('r')); $config = new Config(); $config->setRoot($conf); // write the container to an XML document $config->writeConfig($cfile, 'XML'); } else { // update the xml with the new server $root =& $config->parseConfig($cfile, 'XML', array('name' => 'adm')); log_debug($root); $conf_serv =& $root->createSection($servarray['name']); $conf_serv->createDirective('servername', $servarray['name']); $conf_serv->createDirective('serverapiurl', $servarray['url']); $conf_serv->createDirective('serveremail', $servarray['email']); $conf_serv->createDirective('regtime', date('r')); $config = new Config(); $config->setRoot($root); // write the container to an XML document $config->writeConfig($cfile, 'XML'); } }