From: Roland Häder Date: Thu, 17 Jun 2010 01:31:45 +0000 (+0000) Subject: Rewritten to static method X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;ds=sidebyside;h=9a31052e73b3f0743d2b9155e73c9f07c5edcc2d;p=core.git Rewritten to static method --- diff --git a/inc/classes/main/console/class_ConsoleTools.php b/inc/classes/main/console/class_ConsoleTools.php index 52e8b0dc..1fa79eec 100644 --- a/inc/classes/main/console/class_ConsoleTools.php +++ b/inc/classes/main/console/class_ConsoleTools.php @@ -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