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
00042 const EXCEPTION_CONFIG_ENTRY_IS_EMPTY = 0x130;
00043 const EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND = 0x131;
00044
00050 protected function __construct () {
00051
00052 }
00053
00059 public final static function getInstance () {
00060
00061 if (is_null(self::$cfgInstance)) {
00062
00063 self::$cfgInstance = new FrameworkConfiguration();
00064 }
00065
00066 return self::$cfgInstance;
00067 }
00068
00075 public final function setDefaultTimezone ($zone) {
00076
00077 if (version_compare(phpversion(), "5.1.0")) {
00078 @date_default_timezone_set($zone);
00079 }
00080 }
00081
00085 public final function setMagicQuotesRuntime ($enableQuotes) {
00086
00087 $enableQuotes = (boolean) $enableQuotes;
00088
00089
00090 @set_magic_quotes_runtime($enableQuotes);
00091 }
00092
00099 private function loadIncludes (ArrayObject $arrayObject) {
00100
00101 if (!is_null($arrayObject)) {
00102 for ($idx = $arrayObject->getIterator(); $idx->valid(); $idx->next()) {
00103
00104 $inc = $idx->current();
00105
00106
00107 if (!empty($inc)) {
00108
00109 $fqfn = $inc;
00110
00111
00112 if ((substr($inc, 0, 1) != "/") && (substr($inc, 1, 1) != ":")) {
00113
00114 $fqfn = sprintf("%s/inc/extra/%s", $this->readConfig('base_path'), $inc);
00115 }
00116 }
00117
00118
00119 require($fqfn);
00120 }
00121 }
00122 }
00123
00133 public function readConfig ($cfgEntry) {
00134
00135 $cfgEntry = (string) $cfgEntry;
00136
00137
00138 if (empty($cfgEntry)) {
00139
00140 throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_ENTRY_IS_EMPTY);
00141 } elseif (!isset($this->config[$cfgEntry])) {
00142
00143 throw new ConfigEntryNotFoundException(array(__CLASS__, $cfgEntry), self::EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND);
00144 }
00145
00146
00147 if ((defined('DEBUG_CONFIG')) || (defined('DEBUG_ALL'))) {
00148 echo "[".__METHOD__."] Configuration entry ".$cfgEntry." requested.<br />\n";
00149 }
00150
00151
00152 return $this->config[$cfgEntry];
00153 }
00154
00163 public final function setConfigEntry ($cfgEntry, $cfgValue) {
00164
00165 $cfgEntry = (string) $cfgEntry;
00166 $cfgValue = (string) $cfgValue;
00167
00168
00169 if (empty($cfgEntry)) {
00170
00171 throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_ENTRY_IS_EMPTY);
00172 }
00173
00174
00175 $this->config[$cfgEntry] = $cfgValue;
00176
00177
00178 ksort($this->config);
00179 }
00180
00186 public function __toString () {
00187 return get_class($this);
00188 }
00189
00195 public function detectBaseUrl() {
00196
00197 $baseUrl = "http";
00198
00199
00200 if (isset($_SERVER['HTTPS'])) {
00201
00202 $baseUrl .= "s";
00203 }
00204
00205
00206 $baseUrl = $baseUrl . "://" . $this->detectDomain() . $this->detectScriptPath();
00207
00208
00209 return $baseUrl;
00210 }
00211
00217 public function detectDomain () {
00218
00219 $fullDomain = "localnet.invalid";
00220
00221
00222 if (isset($_SERVER['SERVER_NAME'])) {
00223
00224 $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES);
00225 }
00226
00227
00228 return $fullDomain;
00229 }
00230
00235 public function detectScriptPath () {
00236
00237 $scriptPath = "";
00238
00239
00240 if (isset($_SERVER['SCRIPT_NAME'])) {
00241
00242 $scriptPath = dirname($_SERVER['SCRIPT_NAME']);
00243 }
00244
00245
00246 return $scriptPath;
00247 }
00248
00255 function getField ($fieldName) {
00256
00257 }
00258
00266 public function updateDatabaseField ($fieldName, $fieldValue) {
00267
00268 }
00269 }
00270
00271
00272 ?>