From: Roland Häder Date: Sun, 16 Jul 2017 16:40:15 +0000 (+0200) Subject: Allow DNS resolver to become quiet about its operations X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d368d588ce51693181e74a6bee9f96e8e78b96d4;p=core.git Allow DNS resolver to become quiet about its operations Signed-off-by: Roland Häder --- diff --git a/framework/bootstrap/class_FrameworkBootstrap.php b/framework/bootstrap/class_FrameworkBootstrap.php index 0864970f..16e5863d 100644 --- a/framework/bootstrap/class_FrameworkBootstrap.php +++ b/framework/bootstrap/class_FrameworkBootstrap.php @@ -179,8 +179,6 @@ final class FrameworkBootstrap { is_file($fileName) ) && ( is_readable($fileName) - ) && ( - filesize($fileName) > 100 ) ); diff --git a/framework/config-global.php b/framework/config-global.php index 68af380e..31a7fdc0 100644 --- a/framework/config-global.php +++ b/framework/config-global.php @@ -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); diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index 0e7f4dc6..9736e395 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -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 diff --git a/framework/main/classes/tools/console/class_ConsoleTools.php b/framework/main/classes/tools/console/class_ConsoleTools.php index e783dad3..8b5a2a45 100644 --- a/framework/main/classes/tools/console/class_ConsoleTools.php +++ b/framework/main/classes/tools/console/class_ConsoleTools.php @@ -37,6 +37,11 @@ class ConsoleTools extends BaseFrameworkSystem { 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 * @@ -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'; diff --git a/tests/framework/config/FrameworkConfigurationTest.php b/tests/framework/config/FrameworkConfigurationTest.php index 8e33a28a..324a8fe0 100644 --- a/tests/framework/config/FrameworkConfigurationTest.php +++ b/tests/framework/config/FrameworkConfigurationTest.php @@ -4,6 +4,7 @@ namespace CoreFramework\Configuration; // Inport framework stuff +use CoreFramework\Console\Tools\ConsoleTools; use CoreFramework\Loader\ClassLoader; use CoreFramework\Generic\NullPointerException; @@ -38,6 +39,11 @@ class FrameworkConfigurationTest extends TestCase { */ private static $configInstance = NULL; + /** + * Own IP address + */ + private static $ipAddress = FALSE; + /** * Setup test case */ @@ -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); } }