]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/tools/console/class_ConsoleTools.php
Rewritten:
[core.git] / framework / main / classes / tools / console / class_ConsoleTools.php
index c1d252d51e8db3267a8bd3230928f00ab4721b59..d730677cac1be44d8da8a50bb31d66f5daa58ff2 100644 (file)
@@ -5,10 +5,14 @@ namespace CoreFramework\Console\Tools;
 // Import framework stuff
 use CoreFramework\Configuration\FrameworkConfiguration;
 use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Filesystem\FileNotFoundException;
 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
  *
@@ -36,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
         *
@@ -44,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');
        }
 
        /**
@@ -167,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;
@@ -197,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.',
@@ -220,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());
@@ -266,9 +287,6 @@ class ConsoleTools extends BaseFrameworkSystem {
                        ));
                }
 
-               // Set it in configuration
-               FrameworkConfiguration::getSelfInstance()->setServerAddress($ipAddress);
-
                // Return it
                return $ipAddress;
        }