should be more encapsulated (abstracted)
authorRoland Häder <roland@mxchange.org>
Mon, 3 Aug 2009 18:25:42 +0000 (18:25 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 3 Aug 2009 18:25:42 +0000 (18:25 +0000)
inc/classes/main/console/class_ConsoleTools.php
inc/classes/main/request/console/class_ConsoleRequest.php
inc/classes/main/response/http/class_HttpResponse.php
inc/classes/main/response/image/class_ImageResponse.php
inc/classes/main/rng/class_RandomNumberGenerator.php
inc/config.php
inc/config/class_FrameworkConfiguration.php
inc/includes.php

index e00e757e8100211028ed9c0c16dc5051ae697420..cce0765df47d0032d3d9f12dbc3e9bf13b49aaaa 100644 (file)
@@ -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);
        }
 
        /**
index aaa1540e44979ff826d76b47b918c0032c7095d1..605a074c0a02e91f0512c030fda0dc9f8ef50c68 100644 (file)
@@ -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';
        }
 
        /**
index 3d37fded9b440366b5a790f051a0662394cae93a..5822f1efdbb26bae0c21325eb3951f7a3bf7b47e 100644 (file)
@@ -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);
index ac46e101187cd817d247cbe2d6ba65cdc41541e0..a496d3f49ef185eb150e4db11606564e2c06ad5f 100644 (file)
@@ -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
index 53ef6e76ac66efe223a8a2b7ae5502248f20e37f..fd416433a52d49f55495d12fc8456d27ca92306c 100644 (file)
@@ -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
index 1226b15066946346527a0a63bbc671137962a02b..3d68249aec9572bde3d78e6999e32eeecdd8b5fd 100644 (file)
@@ -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');
index 12d7044218d0e9db4e617a1cb6ec2c796e31c987..7692132a1941dc9647206660909182360d510454 100644 (file)
@@ -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
index 29572e19ce1672faf6f7862d172f7fdf360a7ec9..baa8a6362b6fd3a422a3dcd5d61d2387192cb819 100644 (file)
@@ -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'];