From 47a6960661d9daa28ad7d2aedef359a3ec888642 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 10 Aug 2009 14:15:39 +0000 Subject: [PATCH] New method detectServerAddress() added which should rewrite your code ito. --- .../main/rng/class_RandomNumberGenerator.php | 2 +- inc/config/class_FrameworkConfiguration.php | 50 +++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index 27a36728..857478fb 100644 --- a/inc/classes/main/rng/class_RandomNumberGenerator.php +++ b/inc/classes/main/rng/class_RandomNumberGenerator.php @@ -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 diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index 0494722e..283ad69a 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -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; } /** -- 2.39.5