X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ftools%2Fconsole%2Fclass_ConsoleTools.php;h=d730677cac1be44d8da8a50bb31d66f5daa58ff2;hp=e783dad392eed4fc4d3f7ce53525070176bfcc1b;hb=b9bfbe86c031c9d83c3670602906df191a33ba2a;hpb=c6edcfe27f630eb68192783b155795273da28c2d diff --git a/framework/main/classes/tools/console/class_ConsoleTools.php b/framework/main/classes/tools/console/class_ConsoleTools.php index e783dad3..d730677c 100644 --- a/framework/main/classes/tools/console/class_ConsoleTools.php +++ b/framework/main/classes/tools/console/class_ConsoleTools.php @@ -10,6 +10,9 @@ use CoreFramework\Generic\FrameworkException; use CoreFramework\Object\BaseFrameworkSystem; use CoreFramework\Socket\InvalidSocketException; +// Import SPL stuff +use \SplFileInfo; + /** * This class contains static helper functions for console applications * @@ -37,6 +40,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 +53,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 +179,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 +212,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,16 +238,19 @@ 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'; // Get a new instance $helperInstance = new ConsoleTools(); + // Get SplFileInfo instance + $infoInstance = new SplFileInfo($helperInstance->getConfigInstance()->getConfigEntry('hostname_file')); + try { // Get a file pointer - $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($helperInstance->getConfigInstance()->getConfigEntry('hostname_file'))); + $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($infoInstance)); // Read the file $rawData = trim($fileInstance->readFromFile()); @@ -267,9 +287,6 @@ class ConsoleTools extends BaseFrameworkSystem { )); } - // Set it in configuration - FrameworkConfiguration::getSelfInstance()->setServerAddress($ipAddress); - // Return it return $ipAddress; }