]> git.mxchange.org Git - core.git/commitdiff
New method detectServerAddress() added which should rewrite your code ito.
authorRoland Häder <roland@mxchange.org>
Mon, 10 Aug 2009 14:15:39 +0000 (14:15 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 10 Aug 2009 14:15:39 +0000 (14:15 +0000)
inc/classes/main/rng/class_RandomNumberGenerator.php
inc/config/class_FrameworkConfiguration.php

index 27a3672817ce027c31f3cc2203e9b1539805c7a0..857478fb61069df8fc1ac2fd0064940820f60a2d 100644 (file)
@@ -103,7 +103,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                // Do we have a single server?
                if ($this->getConfigInstance()->getConfigEntry('is_single_server') == 'Y') {
                        // Then use that IP for extra security
-                       $serverIp = $this->getConfigInstance()->getServerAddress();
+                       $serverIp = $this->getConfigInstance()->detectServerAddress();
                } // END - if
 
                // Yet-another fixed salt. This is not dependend on server software or date
index 0494722ee770334cd03df4917af483e4718cedcb..283ad69a95b8cd8333345a77a2e519d9e2f65a79 100644 (file)
@@ -51,6 +51,15 @@ class FrameworkConfiguration implements Registerable {
                // Empty for now
        }
 
+       /**
+        * Compatiblity method to return this class' name
+        *
+        * @return      __CLASS__               This class' name
+        */
+       public function __toString () {
+               return get_class($this);
+       }
+
        /**
         * Getter for an instance of this class
         *
@@ -123,6 +132,20 @@ class FrameworkConfiguration implements Registerable {
                } // END - if
        }
 
+       /**
+        * Checks wether the given configuration entry is set
+        *
+        * @param       $configEntry    The configuration entry we shall check
+        * @return      $isset                  Wether the given configuration entry is set
+        */
+       protected function isConfigurationEntrySet ($configEntry) {
+               // Is it set?
+               $isset = isset($this->config[$configEntry]);
+
+               // Return the result
+               return $isset;
+       }
+
        /**
         * Read a configuration element.
         *
@@ -140,7 +163,7 @@ class FrameworkConfiguration implements Registerable {
                if (empty($cfgEntry)) {
                        // Entry is empty
                        throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_ENTRY_IS_EMPTY);
-               } elseif (!isset($this->config[$cfgEntry])) {
+               } elseif (!$this->isConfigEntrySet($cfgEntry)) {
                        // Entry was not found!
                        throw new ConfigEntryNotFoundException(array(__CLASS__, $cfgEntry), self::EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND);
                }
@@ -176,12 +199,29 @@ class FrameworkConfiguration implements Registerable {
        }
 
        /**
-        * Compatiblity method to return this class' name
+        * Detects the server address (SERVER_ADDR) and set it in configuration
         *
-        * @return      __CLASS__               This class' name
+        * @return      $serverAddress  The detected server address
+        * @todo        We have to add some more entries from $_SERVER here
         */
-       public function __toString () {
-               return get_class($this);
+       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 (class_exists('ConsoleTools')) {
+                               // Run auto-detecting through console tools lib
+                               ConsoleTools::acquireSelfIPAddress();
+                       }
+               } // END - if
+
+               // Now get it from configuration
+               $serverAddress = $this->getServerAddress();
+
+               // Return it
+               return $serverAddress;
        }
 
        /**