Allow DNS resolver to become quiet about its operations
authorRoland Häder <roland@mxchange.org>
Sun, 16 Jul 2017 16:40:15 +0000 (18:40 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 16 Jul 2017 16:40:15 +0000 (18:40 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
framework/bootstrap/class_FrameworkBootstrap.php
framework/config-global.php
framework/config/class_FrameworkConfiguration.php
framework/main/classes/tools/console/class_ConsoleTools.php
tests/framework/config/FrameworkConfigurationTest.php

index 0864970fd68d75490852bce15549e29e9c15242d..16e5863d0e3e4d6589f044e70088dc04e880137e 100644 (file)
@@ -179,8 +179,6 @@ final class FrameworkBootstrap {
                                is_file($fileName)
                        ) && (
                                is_readable($fileName)
                                is_file($fileName)
                        ) && (
                                is_readable($fileName)
-                       ) && (
-                               filesize($fileName) > 100
                        )
                );
 
                        )
                );
 
index 68af380e17908d69ace120acd30975ad5cc14673..31a7fdc0957aad1b3525528c68a972d2483942af 100644 (file)
@@ -458,5 +458,8 @@ $cfg->setConfigEntry('extension_uuid_loaded', false);
 // CFG: REGISTRY-ITERATOR-CLASS
 $cfg->setConfigEntry('registry_iterator_class', 'CoreFramework\Iterator\Registry\RegistryIterator');
 
 // CFG: REGISTRY-ITERATOR-CLASS
 $cfg->setConfigEntry('registry_iterator_class', 'CoreFramework\Iterator\Registry\RegistryIterator');
 
+// CFG: QUIET-DNS-RESOLVER
+$cfg->setConfigEntry('quiet_dns_resolver', FALSE);
+
 // Remove config from this name-space. Don't worry, no configuration is cleared.
 unset($cfg);
 // Remove config from this name-space. Don't worry, no configuration is cleared.
 unset($cfg);
index 0e7f4dc6aba56ac4b6cd7ae213edd36f0a77feb2..9736e39551b5b12871034c24f08ba4f13e365adf 100644 (file)
@@ -335,7 +335,7 @@ class FrameworkConfiguration implements Registerable {
                                $this->setServerAddress($serverIp);
                        } else {
                                // Run auto-detecting through console tools lib
                                $this->setServerAddress($serverIp);
                        } else {
                                // Run auto-detecting through console tools lib
-                               ConsoleTools::acquireSelfIPAddress();
+                               ConsoleTools::acquireSelfIpAddress();
                        }
                } // END - if
 
                        }
                } // END - if
 
index e783dad392eed4fc4d3f7ce53525070176bfcc1b..8b5a2a456295a3b6d7e0bd53297afca3bf1f6161 100644 (file)
@@ -37,6 +37,11 @@ class ConsoleTools extends BaseFrameworkSystem {
        const HTTP_EOL = "\r\n";
        const HTTP_USER_AGENT = 'ConsoleTools/1.0';
 
        const HTTP_EOL = "\r\n";
        const HTTP_USER_AGENT = 'ConsoleTools/1.0';
 
+       /**
+        * Default is that this class is noisy
+        */
+       private static $quietResolver = FALSE;
+
        /**
         * Protected constructor
         *
        /**
         * Protected constructor
         *
@@ -45,6 +50,9 @@ class ConsoleTools extends BaseFrameworkSystem {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Cache configuration entry
+               self::$quietResolver = FrameworkConfiguration::getSelfInstance()->getConfigEntry('quiet_dns_resolver');
        }
 
        /**
        }
 
        /**
@@ -168,11 +176,14 @@ class ConsoleTools extends BaseFrameworkSystem {
         * @todo        This should be connected to a caching class to cache DNS requests
         */
        public static function resolveIpAddress ($hostname) {
         * @todo        This should be connected to a caching class to cache DNS requests
         */
        public static function resolveIpAddress ($hostname) {
-               // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Host name to resolve is: %s',
-                       __CLASS__,
-                       $hostname
-               ));
+               // Quiet?
+               if (self::$quietResolver !== TRUE) {
+                       // Debug message
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Host name to resolve is: %s',
+                               __CLASS__,
+                               $hostname
+                       ));
+               } // END - if
 
                // Default is false
                $ipAddress = false;
 
                // Default is false
                $ipAddress = false;
@@ -198,11 +209,14 @@ class ConsoleTools extends BaseFrameworkSystem {
                        // Okay, this works!
                        $ipAddress = $ipResolved;
 
                        // Okay, this works!
                        $ipAddress = $ipResolved;
 
-                       // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Resolved IP address is: %s',
-                               __CLASS__,
-                               $ipAddress
-                       ));
+                       // Quiet?
+                       if (self::$quietResolver !== TRUE) {
+                               // Debug message
+                               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Resolved IP address is: %s',
+                                       __CLASS__,
+                                       $ipAddress
+                               ));
+                       } // END - if
                } else {
                        // Problem while resolving IP address
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Problem resolving IP address for host %s. Please check your /etc/hosts file.',
                } else {
                        // Problem while resolving IP address
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Problem resolving IP address for host %s. Please check your /etc/hosts file.',
@@ -221,7 +235,7 @@ class ConsoleTools extends BaseFrameworkSystem {
         *
         * @return      $ipAddress      Aquired IPv4 address
         */
         *
         * @return      $ipAddress      Aquired IPv4 address
         */
-       public static function acquireSelfIPAddress () {
+       public static function acquireSelfIpAddress () {
                // Local IP by default
                $ipAddress = '127.0.0.1';
 
                // Local IP by default
                $ipAddress = '127.0.0.1';
 
index 8e33a28acb65351244b01d33507bfb59c6711e51..324a8fe0ad52c49e21e1736dc6ff19d29db4a114 100644 (file)
@@ -4,6 +4,7 @@
 namespace CoreFramework\Configuration;
 
 // Inport framework stuff
 namespace CoreFramework\Configuration;
 
 // Inport framework stuff
+use CoreFramework\Console\Tools\ConsoleTools;
 use CoreFramework\Loader\ClassLoader;
 use CoreFramework\Generic\NullPointerException;
 
 use CoreFramework\Loader\ClassLoader;
 use CoreFramework\Generic\NullPointerException;
 
@@ -38,6 +39,11 @@ class FrameworkConfigurationTest extends TestCase {
         */
        private static $configInstance = NULL;
 
         */
        private static $configInstance = NULL;
 
+       /**
+        * Own IP address
+        */
+       private static $ipAddress = FALSE;
+
        /**
         * Setup test case
         */
        /**
         * Setup test case
         */
@@ -72,6 +78,12 @@ class FrameworkConfigurationTest extends TestCase {
                 */
                ClassLoader::enableStrictNamingConventionCheck(FALSE);
 
                 */
                ClassLoader::enableStrictNamingConventionCheck(FALSE);
 
+               // Quiet DNS resolver as this is not wanted here
+               self::$configInstance->setConfigEntry('quiet_dns_resolver', TRUE);
+
+               // Lookup own IP address
+               self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
+
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
        }
                // Trace message
                //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
        }
@@ -630,7 +642,7 @@ class FrameworkConfigurationTest extends TestCase {
                $serverAddress = self::$configInstance->detectServerAddress();
 
                // Should be the same
                $serverAddress = self::$configInstance->detectServerAddress();
 
                // Should be the same
-               $this->assertEquals('127.0.0.1', $serverAddress);
+               $this->assertEquals(self::$ipAddress, $serverAddress);
        }
 
        /**
        }
 
        /**
@@ -643,7 +655,7 @@ class FrameworkConfigurationTest extends TestCase {
                $serverAddress = self::$configInstance->detectServerAddress();
 
                // Should be the same
                $serverAddress = self::$configInstance->detectServerAddress();
 
                // Should be the same
-               $this->assertEquals('127.0.0.1', $serverAddress);
+               $this->assertEquals(self::$ipAddress, $serverAddress);
        }
 
        /**
        }
 
        /**
@@ -749,6 +761,9 @@ class FrameworkConfigurationTest extends TestCase {
 
                // Should be equal
                $this->assertEquals('127.0.0.1', $serverAddress);
 
                // Should be equal
                $this->assertEquals('127.0.0.1', $serverAddress);
+
+               // Set old back
+               self::$configInstance->setServerAddress(self::$ipAddress);
        }
 
 }
        }
 
 }