class_FrameworkConfiguration.php

Go to the documentation of this file.
00001 <?php
00028 class FrameworkConfiguration implements Registerable {
00034         private $config = array();
00035 
00039         private static $cfgInstance = null;
00040 
00041         // Some constants for the configuration system
00042         const EXCEPTION_CONFIG_ENTRY_IS_EMPTY      = 0x130;
00043         const EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND = 0x131;
00044 
00050         protected function __construct () {
00051                 // Empty for now
00052         }
00053 
00059         public final static function getInstance () {
00060                 // is the instance there?
00061                 if (is_null(self::$cfgInstance))  {
00062                         // Create a config instance
00063                         self::$cfgInstance = new FrameworkConfiguration();
00064                 } // END - if
00065 
00066                 return self::$cfgInstance;
00067         }
00068 
00075         public final function setDefaultTimezone ($zone) {
00076                 // At least 5.1.0 is required for this!
00077                 if (version_compare(phpversion(), "5.1.0")) {
00078                         @date_default_timezone_set($zone);
00079                 } // END - if
00080         }
00081 
00085         public final function setMagicQuotesRuntime ($enableQuotes) {
00086                 // Cast it to boolean
00087                 $enableQuotes = (boolean) $enableQuotes;
00088 
00089                 // Set it
00090                 @set_magic_quotes_runtime($enableQuotes);
00091         }
00092 
00099         private function loadIncludes (ArrayObject $arrayObject) {
00100                 // Load only if there are includes defined
00101                 if (!is_null($arrayObject)) {
00102                         for ($idx = $arrayObject->getIterator(); $idx->valid(); $idx->next()) {
00103                                 // Get include file
00104                                 $inc = $idx->current();
00105 
00106                                 // Is the file name really set?
00107                                 if (!empty($inc)) {
00108                                         // Base path is by default added
00109                                         $fqfn = $inc;
00110 
00111                                         // Base path added? (Uni* / Windows)
00112                                         if ((substr($inc, 0, 1) != "/") && (substr($inc, 1, 1) != ":")) {
00113                                                 // Generate FQFN
00114                                                 $fqfn = sprintf("%s/inc/extra/%s", $this->readConfig('base_path'), $inc);
00115                                         } // END - if
00116                                 } // END - if
00117 
00118                                 // Include them all here
00119                                 require($fqfn);
00120                         }
00121                 } // END - if
00122         }
00123 
00133         public function readConfig ($cfgEntry) {
00134                 // Cast to string
00135                 $cfgEntry = (string) $cfgEntry;
00136 
00137                 // Is a valid configuration entry provided?
00138                 if (empty($cfgEntry)) {
00139                         // Entry is empty
00140                         throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_ENTRY_IS_EMPTY);
00141                 } elseif (!isset($this->config[$cfgEntry])) {
00142                         // Entry was not found!
00143                         throw new ConfigEntryNotFoundException(array(__CLASS__, $cfgEntry), self::EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND);
00144                 }
00145 
00146                 // Debug message
00147                 if ((defined('DEBUG_CONFIG')) || (defined('DEBUG_ALL'))) {
00148                         echo "[".__METHOD__."] Configuration entry ".$cfgEntry." requested.<br />\n";
00149                 } // END - if
00150 
00151                 // Return the requested value
00152                 return $this->config[$cfgEntry];
00153         }
00154 
00163         public final function setConfigEntry ($cfgEntry, $cfgValue) {
00164                 // Cast to string
00165                 $cfgEntry = (string) $cfgEntry;
00166                 $cfgValue = (string) $cfgValue;
00167 
00168                 // Is a valid configuration entry provided?
00169                 if (empty($cfgEntry)) {
00170                         // Entry is empty
00171                         throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_ENTRY_IS_EMPTY);
00172                 } // END - if
00173 
00174                 // Set the configuration value
00175                 $this->config[$cfgEntry] = $cfgValue;
00176 
00177                 // Resort the array
00178                 ksort($this->config);
00179         }
00180 
00186         public function __toString () {
00187                 return get_class($this);
00188         }
00189 
00195         public function detectBaseUrl() {
00196                 // Initialize the URL
00197                 $baseUrl = "http";
00198 
00199                 // Do we have HTTPS?
00200                 if (isset($_SERVER['HTTPS'])) {
00201                         // Add the >s< for HTTPS
00202                         $baseUrl .= "s";
00203                 } // END - if
00204 
00205                 // Construct the full URL now and secure it against CSRF attacks
00206                 $baseUrl = $baseUrl . "://" . $this->detectDomain() . $this->detectScriptPath();
00207 
00208                 // Return the URL
00209                 return $baseUrl;
00210         }
00211 
00217         public function detectDomain () {
00218                 // Full domain is localnet.invalid by default
00219                 $fullDomain = "localnet.invalid";
00220 
00221                 // Is the server name there?
00222                 if (isset($_SERVER['SERVER_NAME'])) {
00223                         // Detect the full domain
00224                         $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES);
00225                 } // END - if
00226 
00227                 // Return it
00228                 return $fullDomain;
00229         }
00230 
00235         public function detectScriptPath () {
00236                 // Default is empty
00237                 $scriptPath = "";
00238 
00239                 // Is the scriptname set?
00240                 if (isset($_SERVER['SCRIPT_NAME'])) {
00241                         // Get dirname of it
00242                         $scriptPath = dirname($_SERVER['SCRIPT_NAME']);
00243                 } // END - if
00244 
00245                 // Return it
00246                 return $scriptPath;
00247         }
00248 
00255         function getField ($fieldName) {
00256                 // Dummy method!
00257         }
00258 
00266         public function updateDatabaseField ($fieldName, $fieldValue) {
00267                 // Dummy method!
00268         }
00269 }
00270 
00271 // [EOF]
00272 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6