Re: [PHP] configuration class - skeleton code for first OOP adventure

2003-10-09 Thread anders thoresson
This will not work. For example if you have:

option1 = value;
option2 = value2;
then ereg_replace('value', 'changed', $contents); will make it:

option1 = changed;
option2 = changed2;
 My plan is to have option1 = value; as old value and option1 = 
changed; as new value. Not only the change value.

--
anders thoresson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] configuration class - skeleton code for first OOP adventure

2003-10-09 Thread anders thoresson
Save yourself a lot of headache learn how to use PEAR and OOP all in one 
fell swoop by using PEAR::Config
 I've already had a look at it, but it's to big for me to get. Though 
learning by doing would be a better way.

--
anders thoresson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] configuration class - skeleton code for first OOP adventure

2003-10-08 Thread anders thoresson
Hi,

My first larger project is growing out of control. I've spent some weeks 
reading OOP tutorials, and feel ready to make my first dive into a new 
programming style. One of the things that led me this way was the need for 
user configuration of my project. Therefor, I'll start with a class that 
let's me read and write a configuration file.

Is this a good start, or should I change anything?

class configuration
{
  var $configurationFile;
  function configuration($configurationFile)
  {
$this-setConfigurationFile($configurationFile);
  }
  function setConfigurationFile($configurationFile)
  {
// Code to check that $configurationFile points to a valid file
  }
  function readConfigurationFile()
  {
$configurationArray = parse_ini_file($this-configurationFile, TRUE);
return $configurationArray;
  }
  function writeConfigurationFile($changedValues)
  {
$fp = fopen($this-configurationFile, r );
$contents = fread($fp, filesize($this-configurationFile));
fclose($fp);
foreach ($changedValues as $changedValue)
{
  $new_contents = ereg_replace($changedValue[old], $changedValue[new], 
$contents);
  $contents = $new_contents;
}

$fp = fopen($this-configurationFile, w );
fwrite($fp, $contents);
fclose($fp);
  }
}
Best regards,

--
anders thoresson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] configuration class - skeleton code for first OOP adventure

2003-10-08 Thread Marek Kilimajer
anders thoresson wrote:
foreach ($changedValues as $changedValue)
{
  $new_contents = ereg_replace($changedValue[old], 
$changedValue[new], $contents);
  $contents = $new_contents;
}
This will not work. For example if you have:

option1 = value;
option2 = value2;
then ereg_replace('value', 'changed', $contents); will make it:

option1 = changed;
option2 = changed2;
Marek

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] configuration class - skeleton code for first OOP adventure

2003-10-08 Thread Burhan Khalid
anders thoresson wrote:

My first larger project is growing out of control. I've spent some weeks 
reading OOP tutorials, and feel ready to make my first dive into a new 
programming style. One of the things that led me this way was the need 
for user configuration of my project. Therefor, I'll start with a class 
that let's me read and write a configuration file.
Save yourself a lot of headache learn how to use PEAR and OOP all in one 
fell swoop by using PEAR::Config

http://pear.php.net

--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php