private static function _bootstrap()
 {
     if (self::$bootrap) {
         return TRUE;
     }
     self::$bootrap = TRUE;
     if (!is_dir(self::$location) or !is_really_writable(self::$location)) {
         self::$enabled = FALSE;
     }
 }
Example #2
0
 public static function enable()
 {
     self::$enabled = true;
 }
 /**
  * Load server settings from specified ini file
  *
  * @param string $cfgfile ini file to load from
  * @return array server config block (also stored as $this->servers)
  */
 function LoadServers($cfgfile, $assign = true)
 {
     //Profiler::StartTimer("ConfigManager::LoadServers()");
     $servers = array();
     $this->hostname = $hostname = php_uname("n");
     if (file_exists($cfgfile)) {
         $mtime = filemtime($cfgfile);
         if (!empty($mtime)) {
             // NOTE - This uses APC directly, since the datamanager object requires this function to execute before initializing
             $apcenabled = ini_get("apc.enabled");
             $apckey = "servers.ini.{$mtime}";
             //print "check apc for '$apckey'<br />";
             if ($apcenabled && ($apccontents = apc_fetch($apckey)) != false) {
                 //print "found in apc, unserialize ($apccontents)<br />";
                 $servers = unserialize($apccontents);
             } else {
                 //print "not found in apc, parse it<br />";
                 $settings = parse_ini_file($cfgfile, true);
                 Logger::Info("Loading server config: {$hostname}");
                 // First load the defaults
                 if (!empty($settings["default"])) {
                     array_set_multi($servers, $settings["default"]);
                 }
                 // set the role
                 $servers["role"] = $settings["mapping"][$hostname] ? $settings["mapping"][$hostname] : "live";
                 // default to live so the site will work if hostname couldn't be determined
                 // If our host is part of a grouping, load those settings up
                 if (!empty($settings["mapping"]) && !empty($settings["mapping"][$hostname]) && !empty($settings[$settings["mapping"][$hostname]])) {
                     Logger::Info("{$hostname} is currently in the '" . $settings["mapping"][$hostname] . "' group");
                     array_set_multi($servers, $settings[$settings["mapping"][$hostname]]);
                 }
                 // And finally, load any host-specific settings
                 if (!empty($settings[$hostname])) {
                     array_set_multi($servers, $settings[$hostname]);
                 }
                 if ($apcenabled) {
                     apc_store($apckey, serialize($servers));
                 }
             }
         }
         if ($assign) {
             $this->servers =& $servers;
         }
         $this->current =& $this->servers;
         //Profiler::StopTimer("ConfigManager::LoadServers()");
         if (isset($this->servers["logger"]["enabled"]) && empty($this->servers["logger"]["enabled"])) {
             Logger::$enabled = false;
         }
         if (isset($this->servers["profiler"]["enabled"]) && empty($this->servers["profiler"]["enabled"])) {
             Profiler::$enabled = false;
         }
     }
     // Update locations to reflect any new settings we got from the ini file
     $this->locations = $this->getLocations();
     // Merge any path settings from the config file into our environment
     if (!empty($this->servers["elation"]["path"])) {
         $elationpath = explode(":", $this->servers["elation"]["path"]);
         $oldincludepath = get_include_path();
         $includepath = explode(":", $oldincludepath);
         $newincludepath = implode(":", array_merge(array_diff($elationpath, $includepath), $includepath));
         if ($newincludepath != $oldincludepath) {
             //        set_include_path($newincludepath);
         }
     }
     if (!empty($_COOKIE["tf-dev"])) {
         $tfdev = json_decode($_COOKIE["tf-dev"], true);
         if (!empty($tfdev["serveroverrides"])) {
             $this->SetServerOverride($tfdev["serveroverrides"]);
         }
     }
     return $servers;
 }
 /**
  * Load server settings from specified ini file
  *
  * @param string $cfgfile ini file to load from
  * @return array server config block (also stored as $this->servers)
  */
 function LoadServers($assign = true)
 {
     //Profiler::StartTimer("ConfigManager::LoadServers()");
     $servers = array();
     // new method
     $this->LoadSettings($this->locations["config"] . "/servers.ini");
     $this->role = $this->GetRoleFromHostname();
     $servers = array_merge_recursive_distinct($servers, $this->GetRoleSettings("default"));
     $servers = array_merge_recursive_distinct($servers, $this->GetRoleSettings($this->role));
     $this->locations = $this->getlocations();
     // DISABLED - old method, had better caching of combined role config
     /*
     if (file_exists($cfgfile)) {
       $mtime = filemtime($cfgfile);
       if (!empty($mtime)) {
         // NOTE - This uses APC directly, since the datamanager object requires this function to execute before initializing
         $apckey = $cfgfile . "." . $mtime;
         //print "check apc for '$apckey'<br />";
         if ($this->apcenabled && ($apccontents = apc_fetch($apckey)) != false) {
           //print "found in apc, unserialize ($apccontents)<br />";
           $servers = unserialize($apccontents);
         } else {
           //print "not found in apc, parse it<br />";
     
           $settings = parse_ini_file($cfgfile, true);
     
           Logger::Info("Loading server config: $hostname");
           // First load the defaults
           if (!empty($settings["default"])) {
             array_set_multi($servers, $settings["default"]);
           }
     
           // set the role
           //$servers["role"] = ($settings["mapping"][$hostname]) ? $settings["mapping"][$hostname] : "live"; // default to live so the site will work if /etc/hostname is missing
           // If our host is part of a grouping, load those settings up
           if (!empty($settings["mapping"]) && !empty($settings["mapping"][$hostname]) && !empty($settings[$settings["mapping"][$hostname]])) {
             Logger::Info("$hostname is currently in the '" . $settings["mapping"][$hostname] . "' group");
             array_set_multi($servers, $settings[$settings["mapping"][$hostname]]);
           }
     
           // And finally, load any host-specific settings
           if (!empty($settings[$hostname])) {
             array_set_multi($servers, $settings[$hostname]);
           }
     
           if ($this->apcenabled) {
             apc_store($apckey, serialize($servers));
           }
         }
       }
     }
     */
     if ($assign) {
         $this->servers =& $servers;
         if (!empty($this->servers["role"])) {
             // ini file specified overridden role
             $this->role = $this->servers["role"];
         }
     }
     //Profiler::StopTimer("ConfigManager::LoadServers()");
     // set logger/profiler settings
     if (isset($this->servers["logger"]["enabled"]) && empty($this->servers["logger"]["enabled"])) {
         Logger::$enabled = false;
     }
     if (isset($this->servers["profiler"]["enabled"]) && empty($this->servers["profiler"]["enabled"])) {
         Profiler::$enabled = false;
     }
     // Update locations to reflect any new settings we got from the ini file
     $this->locations = $this->getLocations();
     // Merge any path settings from the config file into our environment
     if (!empty($this->servers["elation"]["path"])) {
         $elationpath = explode(":", $this->servers["elation"]["path"]);
         $oldincludepath = get_include_path();
         $includepath = explode(":", $oldincludepath);
         $newincludepath = implode(":", array_merge(array_diff($elationpath, $includepath), $includepath));
         if ($newincludepath != $oldincludepath) {
             //        set_include_path($newincludepath);
         }
     }
     // Merge any settings which are overridden by a dev cookie
     if (!empty($_COOKIE["tf-dev"])) {
         $tfdev = json_decode($_COOKIE["tf-dev"], true);
         if (!empty($tfdev["serveroverrides"])) {
             $this->SetServerOverride($tfdev["serveroverrides"]);
         }
     }
     return $servers;
 }
Example #5
0
 /**
  * Set enabled value
  *
  * @param boolean $value
  * @return null
  */
 static function setEnabled($value)
 {
     self::$enabled = (bool) $value;
 }