New method detectServerAddress() added which should rewrite your code ito.
[core.git] / inc / config / class_FrameworkConfiguration.php
index 0494722..283ad69 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;
        }
 
        /**