コード例 #1
0
ファイル: config.php プロジェクト: cepharum/txf
 /**
  * Compiles current configuration from different sources selected by
  * current context and overloading/extending each other.
  *
  */
 protected function import()
 {
     /*
      * prepare coordinates for collecting all interesting sources/files
      */
     // may have separate sources in TXF and application context
     $patterns = array(TXF_FRAMEWORK_PATH . '/config/%A/%H.xml', TXF_APPLICATION_PATH . '/config/%H.xml');
     // may have sources depending on application's name
     $applications = array('default', TXF_APPLICATION);
     // may have sources depending on used hostname
     $hosts = array();
     $temp = explode('.', $_SERVER['HTTP_HOST']);
     while (count($temp)) {
         $hosts[] = implode('.', $temp);
         array_shift($temp);
     }
     $hosts[] = 'default';
     $hosts = array_reverse($hosts);
     /*
      * select all files to read configuration from with latter overlaying former
      */
     $files = array();
     foreach ($patterns as $pattern) {
         foreach ($applications as $application) {
             foreach ($hosts as $host) {
                 $filename = strtr($pattern, array('%A' => $application, '%H' => $host));
                 if ($files[$filename]) {
                     // always include repeating file in its highest priority
                     unset($files[$filename]);
                 } else {
                     // haven't tested before whether file exists or not
                     // --> check now
                     if (!file_exists($filename)) {
                         continue;
                     }
                 }
                 $files[$filename] = $filename;
             }
         }
     }
     /*
      * read selected files each extending/overlaying its predecessors' setup
      */
     $setup = new set();
     foreach ($files as $file) {
         $xml = simplexml_load_file($file);
         $setup->extendFromXml($xml);
     }
     // save read configuration in runtime
     $this->cached = $setup;
 }