* @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'); $conf['stdcontent']['para'][0] = 'This is really cool !'; $conf['stdcontent']['para'][1] = 'It just rocks...'; $c = new Config(); $root =& $c->parseConfig($conf, 'phparray'); $storage =& $root->getItem('section', 'storage'); $storage->removeItem();
/** * Method to create initial IniFile config elements. This method will create * blank ini params. * @example * $config_container ="MAIL"/"Settings" * $settings = array("name"=>"Bruce Banner","email"=> "*****@*****.**") * $iniPath = "/config/" * $iniName ="my.ini" * @param string $config_container. This describes the main header section of the iniFile * @param array $settings. The values that need initializing * @param string $iniPath. File path * @param string $iniName. File name */ public function createConfig($config_container = false, $settings, $iniPath = false, $iniName) { try { //define the main header setting if (isset($config_container)) { $Section = new Config_Container("section", "Settings"); } else { $Section = new Config_Container("section", "{$config_container}"); } // create variables/values if (is_array($settings)) { foreach ($settings as $key => $value) { $Section->createDirective("{$key}", "{$value}"); } } // reassign root $this->objConf->setRoot($Section); // write configuration to file $result = $this->objConf->writeConfig("{$iniPath}" . "{$iniName}", "INIFile"); if ($result == false) { throw new customException($this->objLanguage->languageText("mod_userparamsadmin_writeerror", "userparamsadmin")); log_debug($this->objLanguage->languageText("mod_userparamsadmin_writeerror", "userparamsadmin")); } } catch (customException $e) { customException::cleanUp(); exit; } }
/** * Method to create initial IniFile config elements. This method will create * blank ini params. * @example * $config_container = "MAIL"/"Settings" * $settings = array("name"=>"Bruce Banner", "email"=>"*****@*****.**") * $iniPath = "/config/" * $iniName = "my.ini" * @param string $config_container. This describes the main header section of the iniFile * @param array $settings. The values that need initializing * @param string $iniPath. File path * @param string $iniName. File name */ public function createConfig($config_container = false, $settings, $iniPath = false, $iniName) { try { //define the main header setting if (isset($config_container)) { $Section = new Config_Container("section", "Settings"); } else { $Section = new Config_Container("section", "{$config_container}"); } // create variables/values if (is_array($settings)) { foreach ($settings as $key => $value) { $Section->createDirective("{$key}", "{$value}"); } } // reassign root $this->objConf->setRoot($Section); // write configuration to file $result = $this->objConf->writeConfig("{$iniPath}" . "{$iniName}", "INIFile"); if ($result == false) { throw new Exception($this->Text('word_read_fail')); } } catch (Exception $e) { $this->errorCallback($e); } }