123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- class Pgma_Model
- {
-
- public $properties;
-
- protected $hash;
-
- static protected function getConfigFileName()
- {
-
- $name = $_SERVER['SCRIPT_NAME'];
- $name = pathinfo($name, PATHINFO_FILENAME);
- $name .= '.ini';
- return $name;
- }
-
-
- function __construct()
- {
- $name = self::getConfigFileName();
- $this->properties = file_exists($name) ? parse_ini_file($name, TRUE) : NULL;
- $this->hash = md5(var_export($this->properties, TRUE));
- }
-
-
- function __destruct()
- {
-
- if ($this->hash == md5(var_export($this->properties, TRUE)))
- {
- return;
- }
- else
- {
- echo "Saving application settings\n";
- }
-
- $name = self::getConfigFileName();
- $s = '';
- foreach ($this->properties as $sectionKey => $sectionValue)
- {
- $s .= "[$sectionKey]" . PHP_EOL;
- foreach ($sectionValue as $key => $value)
- {
- $s .= $key . ' = ';
- if (is_bool($value))
- {
- $s .= $value ? 'TRUE' : 'FALSE';
- }
- elseif (is_numeric($value))
- {
- $s .= $value;
- }
- elseif (is_string($value))
- {
- $s .= '"' . $value . '"';
- }
- else
- {
- die('Unsupported property type for '
- . "$sectionKey/$key: " . gettype($value)
- );
- }
- $s .= PHP_EOL;
- }
- }
- file_put_contents($name, $s);
- }
- }
|