| 1 | 
<? | 
| 2 | 
// --------------------------------------------------------------------------- | 
| 3 | 
//  $Id: Config.php,v 1.2 2003/02/03 04:59:29 joko Exp $ | 
| 4 | 
// --------------------------------------------------------------------------- | 
| 5 | 
//  $Log: Config.php,v $ | 
| 6 | 
//  Revision 1.2  2003/02/03 04:59:29  joko | 
| 7 | 
//  + fixed: constructor can now get passed variable of *any type* | 
| 8 | 
// | 
| 9 | 
//  Revision 1.1  2003/02/03 03:51:36  joko | 
| 10 | 
//  + initial commit | 
| 11 | 
// | 
| 12 | 
// --------------------------------------------------------------------------- | 
| 13 | 
 | 
| 14 | 
 | 
| 15 | 
/* | 
| 16 | 
 | 
| 17 | 
  ------------------------------------------------------------ | 
| 18 | 
    How to use this? | 
| 19 | 
  ------------------------------------------------------------ | 
| 20 | 
 | 
| 21 | 
    require_once("../etc/defaults.php"); | 
| 22 | 
    require_once("../etc/includes.php"); | 
| 23 | 
 | 
| 24 | 
    $appConfig = mkObject('Application::Config'); | 
| 25 | 
    print "appConfig:<br/>" . Dumper($appConfig) . "<hr/>"; | 
| 26 | 
 | 
| 27 | 
  ------------------------------------------------------------ | 
| 28 | 
 | 
| 29 | 
*/ | 
| 30 | 
 | 
| 31 | 
 | 
| 32 | 
class Application_Config { | 
| 33 | 
   | 
| 34 | 
  var $_store; | 
| 35 | 
   | 
| 36 | 
  function Application_Config($initCfg = null) { | 
| 37 | 
    //print "Hello World!<hr/>"; | 
| 38 | 
    //print "initCfg:<br/>" . Dumper($initCfg) . "<hr/>"; | 
| 39 | 
    $this->_store = $initCfg; | 
| 40 | 
  } | 
| 41 | 
   | 
| 42 | 
  function merge() { | 
| 43 | 
    //$this->_store[run] = array_merge($this->_store['default'], $this->_store['init']); | 
| 44 | 
    foreach ($this->_store[_init][configkeys] as $configKey) { | 
| 45 | 
      //$this->_store[runtime] = array_merge($this->_store[runtime], $this->_store[$configKey]); | 
| 46 | 
      //$this->_store[runtime] = array_merge_recursive($this->_store[runtime], $this->_store[$configKey]); | 
| 47 | 
      $this->_store[runtime] = array_join_merge($this->_store[runtime], $this->_store[$configKey]); | 
| 48 | 
    } | 
| 49 | 
    //print Dumper($this); | 
| 50 | 
  } | 
| 51 | 
   | 
| 52 | 
  function getPart($var = null) { | 
| 53 | 
    //$this->merge(); | 
| 54 | 
    if ($var) { | 
| 55 | 
      return $this->getVar("runtime.$var"); | 
| 56 | 
    } else { | 
| 57 | 
      return $this->getVar("runtime"); | 
| 58 | 
    } | 
| 59 | 
  } | 
| 60 | 
   | 
| 61 | 
  function setVar($var, $val) { | 
| 62 | 
    //$this->_store[runtime][$var] = $val; | 
| 63 | 
    //$deep = new Data_Deep($this->_store[runtime]); | 
| 64 | 
    $deep = new Data_Deep($this->_store); | 
| 65 | 
    $deep->set($var, $val); | 
| 66 | 
  } | 
| 67 | 
   | 
| 68 | 
  function getVar($var) { | 
| 69 | 
    //$this->_store[runtime][$var] = $val; | 
| 70 | 
    //$deep = new Data_Deep($this->_store[runtime]); | 
| 71 | 
    $deep = new Data_Deep($this->_store); | 
| 72 | 
    return $deep->get($var); | 
| 73 | 
  } | 
| 74 | 
   | 
| 75 | 
} | 
| 76 | 
 | 
| 77 | 
?> |