X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fconfig%2Fclass_FrameworkConfiguration.php;h=283ad69a95b8cd8333345a77a2e519d9e2f65a79;hp=0494722ee770334cd03df4917af483e4718cedcb;hb=47a6960661d9daa28ad7d2aedef359a3ec888642;hpb=3396c983d18a252c26b81215fdc38f25f184122a 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; } /**