From: Roland Häder Date: Mon, 3 Aug 2009 18:25:42 +0000 (+0000) Subject: should be more encapsulated (abstracted) X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=73bb9000fb82cfb51d3e55f0d1f7f6d09974368e;ds=sidebyside should be more encapsulated (abstracted) --- diff --git a/inc/classes/main/console/class_ConsoleTools.php b/inc/classes/main/console/class_ConsoleTools.php index e00e757e..cce0765d 100644 --- a/inc/classes/main/console/class_ConsoleTools.php +++ b/inc/classes/main/console/class_ConsoleTools.php @@ -77,9 +77,10 @@ class ConsoleTools extends BaseFrameworkSystem { } /** - * Aquires the IP address of this host by reading the /etc/hostname file and solving it + * Aquires the IP address of this host by reading the /etc/hostname file + * and solving it. It is now stored in configuration * - * @return $ip The resolved IP address + * @return void */ public static function acquireSelfIPAddress () { // Local IP by default @@ -121,8 +122,8 @@ class ConsoleTools extends BaseFrameworkSystem { )); } - // Return the IP address - return $ip; + // Set it in configuration + FrameworkConfiguration::getInstance()->setServerAddress($ip); } /** diff --git a/inc/classes/main/request/console/class_ConsoleRequest.php b/inc/classes/main/request/console/class_ConsoleRequest.php index aaa1540e..605a074c 100644 --- a/inc/classes/main/request/console/class_ConsoleRequest.php +++ b/inc/classes/main/request/console/class_ConsoleRequest.php @@ -65,7 +65,7 @@ class ConsoleRequest extends BaseRequest implements Requestable { } // END - if // Is the first element "index.php" ? - if ($args[0] == "index.php") { + if ($args[0] == 'index.php') { // Then remove it array_shift($args); } // END - if @@ -73,12 +73,12 @@ class ConsoleRequest extends BaseRequest implements Requestable { // Try to determine next parameters foreach ($args as $arg) { // Seperate arguemnt name from value - $argArray = explode("=", $arg); + $argArray = explode('=', $arg); // Is the second one set? if (!isset($argArray[1])) { // Add it likewise, but empty value - $this->setRequestElement($argArray[0], ""); + $this->setRequestElement($argArray[0], ''); } else { // Set a name=value pair escaped and secured $this->setRequestElement($argArray[0], escapeshellcmd($argArray[1])); @@ -93,7 +93,7 @@ class ConsoleRequest extends BaseRequest implements Requestable { * @return $headerValue Value of the header or 'null' if not found */ public function getHeader ($headerName) { - $this->partialStub("Please implement this method."); + $this->partialStub('Please implement this method.'); } /** @@ -102,7 +102,7 @@ class ConsoleRequest extends BaseRequest implements Requestable { * @return $requestMethod Used request method */ public final function getRequestMethod () { - return "LOCAL"; + return 'LOCAL'; } /** diff --git a/inc/classes/main/response/http/class_HttpResponse.php b/inc/classes/main/response/http/class_HttpResponse.php index 3d37fded..5822f1ef 100644 --- a/inc/classes/main/response/http/class_HttpResponse.php +++ b/inc/classes/main/response/http/class_HttpResponse.php @@ -90,6 +90,8 @@ class HttpResponse extends BaseResponse implements Responseable { // Shall we encrypt the cookie? if ($encrypted === true) { + // Unsupported at the moment + $this->partialStub('Encryption is unsupported at the moment.'); } // END - if // For slow browsers set the cookie array element first @@ -109,7 +111,7 @@ class HttpResponse extends BaseResponse implements Responseable { // Now construct the full header $cookieString = $cookieName . '=' . $cookieValue . '; '; - $cookieString .= "expires=" . date("D, d-F-Y H:i:s", $expires) . " GMT"; + $cookieString .= 'expires=' . date('D, d-F-Y H:i:s', $expires) . ' GMT'; // $cookieString .= "; path=".$path."; domain=".$domain; // Set the cookie as a header @@ -135,7 +137,7 @@ class HttpResponse extends BaseResponse implements Responseable { $this->getTemplateInstance()->assignApplicationData($this->getApplicationInstance()); // Get the url from config - $url = $this->getConfigInstance()->getConfigEntry($configEntry . "_url"); + $url = $this->getConfigInstance()->getConfigEntry($configEntry . '_url'); // Compile the URL $url = $this->getTemplateInstance()->compileRawCode($url); diff --git a/inc/classes/main/response/image/class_ImageResponse.php b/inc/classes/main/response/image/class_ImageResponse.php index ac46e101..a496d3f4 100644 --- a/inc/classes/main/response/image/class_ImageResponse.php +++ b/inc/classes/main/response/image/class_ImageResponse.php @@ -104,6 +104,8 @@ class ImageResponse extends BaseResponse implements Responseable { // Shall we encrypt the cookie? if ($encrypted === true) { + // Unsupported at the moment + $this->partialStub('Encryption is unsupported at the moment.'); } // END - if // For slow browsers set the cookie array element first diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index 53ef6e76..fd416433 100644 --- a/inc/classes/main/rng/class_RandomNumberGenerator.php +++ b/inc/classes/main/rng/class_RandomNumberGenerator.php @@ -98,12 +98,12 @@ class RandomNumberGenerator extends BaseFrameworkSystem { mt_srand((double) sqrt(microtime() * 100000000 * $this->extraNumber)); // Set the server IP to cluster - $serverIp = "cluster"; + $serverIp = 'cluster'; // Do we have a single server? if ($this->getConfigInstance()->getConfigEntry('is_single_server') == 'Y') { // Then use that IP for extra security - $serverIp = getenv('SERVER_ADDR'); + $serverIp = $this->getConfigInstance()->getServerAddress(); } // END - if // Yet-another fixed salt. This is not dependend on server software or date diff --git a/inc/config.php b/inc/config.php index 1226b150..3d68249a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -276,7 +276,7 @@ $cfg->setConfigEntry('cookie_path', $cfg->detectScriptPath() . '/'); $cfg->setConfigEntry('cookie_domain', $cfg->detectDomain()); // Is mostly the same... // CFG: COOKIE-SSL -$cfg->setConfigEntry('cookie_ssl', (isset($_SERVER['HTTPS']))); +$cfg->setConfigEntry('cookie_ssl', $cfg->isHttpSecured()); // CFG: CRYPT-FIXED-SALT $cfg->setConfigEntry('crypt_fixed_salt', 'N'); diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index 12d70442..7692132a 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -74,8 +74,8 @@ class FrameworkConfiguration implements Registerable { */ public final function setDefaultTimezone ($zone) { // At least 5.1.0 is required for this! - if (version_compare(phpversion(), "5.1.0")) { - @date_default_timezone_set($zone); + if (version_compare(phpversion(), '5.1.0')) { + date_default_timezone_set($zone); } // END - if } @@ -87,7 +87,7 @@ class FrameworkConfiguration implements Registerable { $enableQuotes = (boolean) $enableQuotes; // Set it - @set_magic_quotes_runtime($enableQuotes); + set_magic_quotes_runtime($enableQuotes); } /** @@ -95,6 +95,8 @@ class FrameworkConfiguration implements Registerable { * * @param $arrayObject The array object with all include files * @return void + * @deprecated + * @see ClassLoader */ private function loadIncludes (ArrayObject $arrayObject) { // Load only if there are includes defined @@ -182,17 +184,64 @@ class FrameworkConfiguration implements Registerable { return get_class($this); } + /** + * Setter for SERVER_ADDR + * + * @param $serverAddress New SERVER_ADDR value to set + * @return void + */ + public function setServerAddress ($serverAddress) { + $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 wether HTTPS is set in $_SERVER + * + * @return $isset Wether HTTPS is set + */ + 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() { + public function detectBaseUrl () { // Initialize the URL $baseUrl = 'http'; // Do we have HTTPS? - if (isset($_SERVER['HTTPS'])) { + if ($this->isHttpSecured()) { // Add the >s< for HTTPS $baseUrl .= 's'; } // END - if diff --git a/inc/includes.php b/inc/includes.php index 29572e19..baa8a636 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -33,6 +33,7 @@ ClassLoader::getInstance()->loadExtraConfigs(); require(FrameworkConfiguration::getInstance()->getConfigEntry('base_path') . 'inc/hooks.php'); // Does the user has an application specified? +// @TODO Find a nicer OOP-ed way for this if (!empty($_GET['app'])) { // Set the application from string $application = (string) $_GET['app'];