]> git.mxchange.org Git - core.git/blobdiff - framework/config/class_FrameworkConfiguration.php
... now call-back array ...
[core.git] / framework / config / class_FrameworkConfiguration.php
index ee7439e8106b07551f4f0a30daab02011292bf62..15894ff483bcaf7c8684f2491dbe32e5ce2c9b46 100644 (file)
@@ -3,8 +3,11 @@
 namespace CoreFramework\Configuration;
 
 // Import framework stuff
+use CoreFramework\Console\Tools\ConsoleTools;
+use CoreFramework\Dns\UnknownHostnameException;
 use CoreFramework\Generic\FrameworkInterface;
 use CoreFramework\Generic\NullPointerException;
+use CoreFramework\Generic\UnsupportedOperationException;
 use CoreFramework\Registry\Registerable;
 
 /**
@@ -209,6 +212,16 @@ class FrameworkConfiguration implements Registerable {
                ksort($this->config);
        }
 
+       /**
+        * Getter for whole configuration array
+        *
+        * @return      $config         Configuration array
+        */
+       public final function getConfigurationArray () {
+               // Return it
+               return $this->config;
+       }
+
        /**
         * Unset a configuration key, the entry must be there or else an
         * exception is thrown.
@@ -235,7 +248,8 @@ class FrameworkConfiguration implements Registerable {
         * Detects the server address (SERVER_ADDR) and set it in configuration
         *
         * @return      $serverAddress  The detected server address
-        * @todo        We have to add some more entries from $_SERVER here
+        * @throws      UnknownHostnameException        If SERVER_NAME cannot be resolved to an IP address
+        * @todo        Have to check some more entries from $_SERVER here
         */
        public function detectServerAddress () {
                // Is the entry set?
@@ -244,7 +258,22 @@ class FrameworkConfiguration implements Registerable {
                        if (isset($_SERVER['SERVER_ADDR'])) {
                                // Set it from $_SERVER
                                $this->setServerAddress($_SERVER['SERVER_ADDR']);
-                       } elseif (class_exists('ConsoleTools')) {
+                       } elseif (isset($_SERVER['SERVER_NAME'])) {
+                               // Resolve IP address
+                               $serverIp = ConsoleTools::resolveIpAddress($_SERVER['SERVER_NAME']);
+
+                               // Is it valid?
+                               if ($serverIp === false) {
+                                       /*
+                                        * Why is gethostbyname() returning the host name and not
+                                        * false as many other PHP functions are doing? ;-(
+                                        */
+                                       throw new UnknownHostnameException(sprintf('Cannot resolve "%s" to an IP address. Please fix your setup.', $_SERVER['SERVER_NAME']));
+                               } // END - if
+
+                               // Al fine, set it
+                               $this->setServerAddress($serverIp);
+                       } else {
                                // Run auto-detecting through console tools lib
                                ConsoleTools::acquireSelfIPAddress();
                        }
@@ -279,20 +308,20 @@ class FrameworkConfiguration implements Registerable {
        /**
         * Detects the HTTPS flag
         *
-        * @return      $https  The detected HTTPS flag or null if failed
+        * @return      $isSecured      The detected HTTPS flag or null if failed
         */
        public function detectHttpSecured () {
                // Default is null
-               $https = NULL;
+               $isSecured = NULL;
 
                // Is HTTPS set?
                if ($this->isHttpSecured()) {
                        // Then use it
-                       $https = $_SERVER['HTTPS'];
+                       $isSecured = $_SERVER['HTTPS'];
                } // END - if
 
                // Return it
-               return $https;
+               return $isSecured;
        }
 
        /**
@@ -373,7 +402,7 @@ class FrameworkConfiguration implements Registerable {
         * @throws      NullPointerException    If the result instance is null
         */
        public final function getField ($fieldName) {
-               // Our super interface "FrameworkInterface" requires this
+               // The super interface "FrameworkInterface" requires this
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
@@ -385,7 +414,7 @@ class FrameworkConfiguration implements Registerable {
         * @throws      NullPointerException    If the result instance is null
         */
        public function isFieldSet ($fieldName) {
-               // Our super interface "FrameworkInterface" requires this
+               // The super interface "FrameworkInterface" requires this
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
@@ -408,9 +437,9 @@ class FrameworkConfiguration implements Registerable {
        public function equals (FrameworkInterface $objectInstance) {
                // Now test it
                $equals = ((
-                       $this->__toString() == $objectInstance->__toString()
+                       $this->__toString() === $objectInstance->__toString()
                ) && (
-                       $this->hashCode() == $objectInstance->hashCode()
+                       $this->hashCode() === $objectInstance->hashCode()
                ));
 
                // Return the result