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 0864970..16e5863 100644 (file)
@@ -179,8 +179,6 @@ final class FrameworkBootstrap {
                                is_file($fileName)
                        ) && (
                                is_readable($fileName)
-                       ) && (
-                               filesize($fileName) > 100
                        )
                );
 
index 68af380..31a7fdc 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: QUIET-DNS-RESOLVER
+$cfg->setConfigEntry('quiet_dns_resolver', FALSE);
+
 // Remove config from this name-space. Don't worry, no configuration is cleared.
 unset($cfg);
index 0e7f4dc..9736e39 100644 (file)
@@ -335,7 +335,7 @@ class FrameworkConfiguration implements Registerable {
                                $this->setServerAddress($serverIp);
                        } else {
                                // Run auto-detecting through console tools lib
-                               ConsoleTools::acquireSelfIPAddress();
+                               ConsoleTools::acquireSelfIpAddress();
                        }
                } // END - if
 
index e783dad..8b5a2a4 100644 (file)
@@ -38,6 +38,11 @@ class ConsoleTools extends BaseFrameworkSystem {
        const HTTP_USER_AGENT = 'ConsoleTools/1.0';
 
        /**
+        * Default is that this class is noisy
+        */
+       private static $quietResolver = FALSE;
+
+       /**
         * Protected constructor
         *
         * @return      void
@@ -45,6 +50,9 @@ class ConsoleTools extends BaseFrameworkSystem {
        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) {
-               // 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;
@@ -198,11 +209,14 @@ class ConsoleTools extends BaseFrameworkSystem {
                        // 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.',
@@ -221,7 +235,7 @@ class ConsoleTools extends BaseFrameworkSystem {
         *
         * @return      $ipAddress      Aquired IPv4 address
         */
-       public static function acquireSelfIPAddress () {
+       public static function acquireSelfIpAddress () {
                // Local IP by default
                $ipAddress = '127.0.0.1';
 
index 8e33a28..324a8fe 100644 (file)
@@ -4,6 +4,7 @@
 namespace CoreFramework\Configuration;
 
 // Inport framework stuff
+use CoreFramework\Console\Tools\ConsoleTools;
 use CoreFramework\Loader\ClassLoader;
 use CoreFramework\Generic\NullPointerException;
 
@@ -39,6 +40,11 @@ class FrameworkConfigurationTest extends TestCase {
        private static $configInstance = NULL;
 
        /**
+        * Own IP address
+        */
+       private static $ipAddress = FALSE;
+
+       /**
         * Setup test case
         */
        public function setUp() {
@@ -72,6 +78,12 @@ class FrameworkConfigurationTest extends TestCase {
                 */
                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__);
        }
@@ -630,7 +642,7 @@ class FrameworkConfigurationTest extends TestCase {
                $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
-               $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);
+
+               // Set old back
+               self::$configInstance->setServerAddress(self::$ipAddress);
        }
 
 }