Fw: [PEAR-DEV] Proposal for an INI format for pear.ini & pearsys.ini
| From: | Vincent Blavet | Date: | Tue, 19 Feb 2002 06:38:57 +0000 |
| Subject: | Fw: [PEAR-DEV] Proposal for an INI format for pear.ini & pearsys.ini | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-4801@lists.php.net to get a copy of this message | ||
I really do have problems with the attachment .... here is a cut and paste of the interesting parts.
Sorry,
Vincent
From Config.php
// {{{ readConfigFile([file], [defaults])
function readConfigFile($file = null, $defaults = false)
{
if ($file === null) {
$file = $this->config_file;
}
$this->configuration = $this->readIni($file);
/*
$fp = @fopen($file, "r");
if (!$fp) {
return $this->raiseError($php_errormsg);
}
$size = filesize($file);
$contents = fread($fp, $size);
$data = unserialize($contents);
if ($data === false && $size > 1) {
return $this->raiseError("PEAR_Config::readConfigFile: bad data");
}
$this->configuration = $data;
*/
if ($defaults) {
foreach ($data as $key => $value) {
$this->defaulted[$key] = true;
}
}
}
// }}}
// {{{ writeConfigFile([file], [what_keys])
function writeConfigFile($file = null, $what_keys = 'userdefined')
{
if ($what_keys == 'both') {
$this->writeConfigFile($file, 'userdefined');
$this->writeConfigFile($file, 'default');
return;
}
if ($file === null) {
if ($what_keys == 'default') {
$file = $this->defaults_file;
} else {
$file = $this->config_file;
}
}
if ($what_keys == 'default') {
$keys_to_store = array_intersect(array_keys($this->configuration),
array_keys($this->defaulted));
} elseif ($what_keys == 'all') {
$keys_to_store = array_keys($this->configuration);
} else { // user-defined keys
$keys_to_store = array_diff(array_keys($this->configuration),
array_keys($this->defaulted));
}
$data = array();
foreach ($keys_to_store as $key) {
$data[$key] = $this->configuration[$key];
}
return $this->writeIni($file, $data);
/*
$fp = @fopen($file, "w");
if (!$fp) {
return $this->raiseError("PEAR_Config::writeConfigFile
fopen('$file','w') failed");
}
if (!@fwrite($fp, serialize($data))) {
return $this->raiseError("PEAR_Config::writeConfigFile serialize failed");
}
return true;
*/
}
// }}}
// {{{ readIni
function readIni($file)
{
$data = parse_ini_file($file);
return $data;
}
// }}}
// {{{ writeIni
function writeIni($file, $data)
{
$fp = @fopen($file, "w");
if (!$fp) {
return $this->raiseError("PEAR_Config::writeIni
fopen('$file','w') failed");
}
$section = "[PEAR]";
if (!@fwrite($fp, $section."\n")) {
return $this->raiseError("PEAR_Config::writeIni fwrite() failed");
}
$warn = "";
$warn .= ';;;;;;;;;;;'."\n";
$warn .= '; WARNING ;'."\n";
$warn .= ';;;;;;;;;;;'."\n";
$warn .= '; This is the configuration file for PEAR.'."\n";
$warn .= '; For more information: http://pear.php.net'."\n";
$warn .= "\n";
if (!@fwrite($fp, $warn."\n")) {
return $this->raiseError("PEAR_Config::writeIni fwrite() failed");
}
foreach ($data as $key => $value) {
$item = $key.' = '.$value."\n";
if (!@fwrite($fp, $item)) {
return $this->raiseError("PEAR_Config::writeIni fwrite() failed");
}
}
return true;
}
// }}}
Sample of a pear.ini :
[PEAR]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the configuration file for PEAR.
; For more information: http://pear.php.net
php_dir = d:\php\bin\php\pear
ext_dir = d:\php\bin\php\extensions
master_server = pear.php.net
----- Original Message -----
From: Vincent Blavet
To: pear-dev@lists.php.net
Sent: Tuesday, February 19, 2002 7:19 AM
Subject: Fw: [PEAR-DEV] Proposal for an INI format for pear.ini & pearsys.ini
It seems I forgot the attachment .... :-(
Config.php
and an example of pear.ini
Vincent
----- Original Message -----
From: Vincent Blavet
To: pear-dev@lists.php.net
Sent: Tuesday, February 19, 2002 12:42 AM
Subject: [PEAR-DEV] Proposal for an INI format for pear.ini & pearsys.ini
I modified Config.phpin order to support pear.ini and pearsys.ini files in stanadrd INI format.
I did not commit the change because it needs to be validated (Stig, Thomas, Martin ... ?), so you
will find the file attached.
Modified fucntions : readConfigFile(), writeConfigFile(), added functions readIni() and writeIni()
I think a FileIni Class may be created to be more generic. Today the commentaries are lost.
I'm waiting for feedback or a go/no go for committing that.
Vincent
--------------------------------------------------------------------------------
--
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--------------------------------------------------------------------------------
--
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php