X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fconfig%2Fclass_FrameworkConfiguration.php;h=be9d7d6dc137c73a39f464a1d14873efc3f638b8;hb=9a62415e59d249f13512f41181f4406680e3d5fd;hp=26c47d4268062f14b4cb6eda492d96fef71e13db;hpb=887340f2efadd02aa4a1e6d6d86529570184efa5;p=core.git diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index 26c47d42..be9d7d6d 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -1,16 +1,14 @@ config[$configKey])) || (array_key_exists($configKey, $this->config))); + $isset = ((isset(self::$config[$configKey])) || (array_key_exists($configKey, self::$config))); // Return the result return $isset; @@ -212,7 +128,7 @@ class FrameworkConfiguration implements Registerable { } // Convert dashes to underscore - $configKey = self::convertDashesToUnderscores($configKey); + $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey); // Is a valid configuration key provided? if (!$this->isConfigurationEntrySet($configKey)) { @@ -221,7 +137,7 @@ class FrameworkConfiguration implements Registerable { } // END - if // Return the requested value - return $this->config[$configKey]; + return self::$config[$configKey]; } /** @@ -251,14 +167,14 @@ class FrameworkConfiguration implements Registerable { } // Cast to string - $configKey = self::convertDashesToUnderscores($configKey); + $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey); // Set the configuration value //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL); - $this->config[$configKey] = $configValue; + self::$config[$configKey] = $configValue; // Resort the array - ksort($this->config); + ksort(self::$config); } /** @@ -268,7 +184,7 @@ class FrameworkConfiguration implements Registerable { */ public final function getConfigurationArray () { // Return it - return $this->config; + return self::$config; } /** @@ -295,7 +211,7 @@ class FrameworkConfiguration implements Registerable { } // Convert dashes to underscore - $configKey = self::convertDashesToUnderscores($configKey); + $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey); // Is the configuration key there? if (!$this->isConfigurationEntrySet($configKey)) { @@ -304,171 +220,7 @@ class FrameworkConfiguration implements Registerable { } // END - if // Unset it - unset($this->config[$configKey]); - } - - /** - * Detects the server address (SERVER_ADDR) and set it in configuration - * - * @return $serverAddress The detected server address - * @throws UnknownHostnameException If SERVER_NAME cannot be resolved to an IP address - * @todo Have to check some more entries from $_SERVER here - */ - public function detectServerAddress () { - // Is the entry set? - if (!$this->isConfigurationEntrySet('server_addr')) { - // Is it set in $_SERVER? - if (isset($_SERVER['SERVER_ADDR'])) { - // Set it from $_SERVER - $this->setServerAddress($_SERVER['SERVER_ADDR']); - } elseif (isset($_SERVER['SERVER_NAME'])) { - // Resolve IP address - $serverIp = ConsoleTools::resolveIpAddress($_SERVER['SERVER_NAME']); - - // Is it valid? - if ($serverIp === false) { - /* - * Why is gethostbyname() returning the host name and not - * false as many other PHP functions are doing? ;-( - */ - throw new UnknownHostnameException(sprintf('Cannot resolve "%s" to an IP address. Please fix your setup.', $_SERVER['SERVER_NAME'])); - } // END - if - - // Al fine, set it - $this->setServerAddress($serverIp); - } else { - // Run auto-detecting through console tools lib - ConsoleTools::acquireSelfIpAddress(); - } - } // END - if - - // Now get it from configuration - $serverAddress = $this->getServerAddress(); - - // Return it - return $serverAddress; - } - - /** - * Setter for SERVER_ADDR - * - * @param $serverAddress New SERVER_ADDR value to set - * @return void - */ - public function setServerAddress ($serverAddress) { - // Is a valid configuration key key provided? - if (is_null($serverAddress)) { - // Configuration key is null - throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_string($serverAddress)) { - // Is not a string - throw new InvalidArgumentException(sprintf('serverAddress[]=%s is not a string', gettype($serverAddress)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY); - } elseif ((is_string($serverAddress)) && (empty($serverAddress))) { - // Entry is empty - throw new InvalidArgumentException('serverAddress is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); - } - - // Set it, please don't do it yourself here - $this->setConfigEntry('server_addr', (string) $serverAddress); - } - - /** - * Getter for SERVER_ADDR - * - * @return $serverAddress New SERVER_ADDR value to set - */ - public function getServerAddress () { - return $this->getConfigEntry('server_addr'); - } - - /** - * Detects the HTTPS flag - * - * @return $https The detected HTTPS flag or null if failed - */ - public function detectHttpSecured () { - // Default is null - $https = NULL; - - // Is HTTPS set? - if ($this->isHttpSecured()) { - // Then use it - $https = $_SERVER['HTTPS']; - } // END - if - - // Return it - return $https; - } - - /** - * Checks whether HTTPS is set in $_SERVER - * - * @return $isset Whether HTTPS is set - * @todo Test more fields - */ - public function isHttpSecured () { - return (isset($_SERVER['HTTPS'])); - } - - /** - * Dectect and return the base URL for all URLs and forms - * - * @return $baseUrl Detected base URL - */ - public function detectBaseUrl () { - // Initialize the URL - $protocol = 'http'; - - // Do we have HTTPS? - if ($this->isHttpSecured()) { - // Add the >s< for HTTPS - $protocol = 's'; - } // END - if - - // Construct the full URL and secure it against CSRF attacks - $baseUrl = $protocol . '://' . $this->detectDomain() . $this->detectScriptPath(); - - // Return the URL - return $baseUrl; - } - - /** - * Detect safely and return the full domain where this script is installed - * - * @return $fullDomain The detected full domain - */ - public function detectDomain () { - // Full domain is localnet.invalid by default - $fullDomain = 'localnet.invalid'; - - // Is the server name there? - if (isset($_SERVER['SERVER_NAME'])) { - // Detect the full domain - $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES); - } // END - if - - // Return it - return $fullDomain; - } - - /** - * Detect safely the script path without trailing slash which is the glue - * between "http://your-domain.invalid/" and "script-name.php" - * - * @return $scriptPath The script path extracted from $_SERVER['SCRIPT_NAME'] - */ - public function detectScriptPath () { - // Default is empty - $scriptPath = ''; - - // Is the scriptname set? - if (isset($_SERVER['SCRIPT_NAME'])) { - // Get dirname from it and replace back-slashes with slashes for lame OSes... - $scriptPath = str_replace("\\", '/', dirname($_SERVER['SCRIPT_NAME'])); - } // END - if - - // Return it - return $scriptPath; + unset(self::$config[$configKey]); } /**