]> git.mxchange.org Git - core.git/commitdiff
Rewritten to static method
authorRoland Häder <roland@mxchange.org>
Thu, 17 Jun 2010 01:31:45 +0000 (01:31 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 17 Jun 2010 01:31:45 +0000 (01:31 +0000)
inc/classes/main/console/class_ConsoleTools.php

index 52e8b0dc2acb182b04863ad1ce51bf9140519d1a..1fa79eec3b391186acd36e75ad6f8dc7bb82c87d 100644 (file)
@@ -87,7 +87,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                $ip = '127.0.0.1';
 
                // Get a new instance
-               $helper = new ConsoleTools();
+               $helperInstance = new ConsoleTools();
 
                try {
                        // Get a file pointer
@@ -100,22 +100,22 @@ class ConsoleTools extends BaseFrameworkSystem {
                        $io->closeFile();
 
                        // Resolve the IP number
-                       $ip = $helper->resolveIpAddress($hostname);
+                       $ip = $helperInstance->resolveIpAddress($hostname);
                } catch (FileIoException $e) {
                        // Fall-back to 'SESSION_SVR' which found on my Sun Station
                        if (isset($_SERVER['SESSION_SVR'])) {
                                // Resolve it
-                               $ip = $helper->resolveIpAddress($_SERVER['SESSION_SVR']);
+                               $ip = $helperInstance->resolveIpAddress($_SERVER['SESSION_SVR']);
                        } else {
                                // Could not find our hostname
-                               $helper->debugOutput(sprintf("[%s:] WARNING: Cannot resolve my own IP address.",
-                                       $helper->__toString()
+                               $helperInstance->debugOutput(sprintf("[%s:] WARNING: Cannot resolve my own IP address.",
+                                       $helperInstance->__toString()
                                ));
                        }
                } catch (FrameworkException $e) {
                        // Output debug message
-                       $helper->debugOutput(sprintf("[%s:] Problem while resolving own IP address: [%s|%s]:%s",
-                               $helper->__toString(),
+                       $helperInstance->debugOutput(sprintf("[%s:] Problem while resolving own IP address: [%s|%s]:%s",
+                               $helperInstance->__toString(),
                                $e->__toString(),
                                $e->getHexCode(),
                                $e->getMessage()
@@ -141,14 +141,17 @@ class ConsoleTools extends BaseFrameworkSystem {
         * @return      $externalAddress        The determined external IP address
         * @throws      InvalidSocketException  If socket initialization wents wrong or if an errors occurs
         */
-       public function determineExternalIp ($dest = '217.172.186.31', $port = 80) {
+       public static function determineExternalIp ($dest = '217.172.186.31', $port = 80) {
+               // Get helper instance
+               $helperInstance = new ConsoleTools();
+
                // First get a socket
                $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
 
                // Is it valid?
                if (!is_resource($socket)) {
                        // Throw InvalidSocketException
-                       throw new InvalidSocketException (array($this, gettype($socket), 0, 'unknown'));
+                       throw new InvalidSocketException (array($helperInstance, gettype($socket), 0, 'unknown'));
                } // END - if
 
                // Get socket error code for verification
@@ -157,7 +160,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                // Check if there was an error else
                if ($socketError > 0) {
                        // Then throw again
-                       throw new InvalidSocketException(array($this, gettype($socket), $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($helperInstance, gettype($socket), $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Connect to the destination