3 * This class contains static helper functions for console applications
5 class ConsoleTools extends BaseFrameworkSystem {
11 private function __construct () {
12 // Call parent constructor
13 parent::constructor(__CLASS__);
16 $this->setPartDescr("Console-Tools");
18 // Create an unique ID
19 $this->createUniqueID();
23 * Aquires the IP address of this host by reading the /etc/hostname file and solving it
25 * @return $ip The resolved IP address
27 public static function aquireSelfIPAddress () {
28 // Local IP by default
32 $helper = new ConsoleTools();
36 $io = FrameworkFileInputPointer::createFrameworkFileInputPointer("/etc/hostname");
39 $hostname = trim($io->readFromFile());
40 $helper->getDebugInstance()->output(sprintf("[%s:] Our host name is: <strong>%s</strong><br />\n",
41 $helper->__toString(),
49 $ipResolved = gethostbyname($hostname);
50 if (($ipResolved !== false) && ($ipResolved != $hostname)) {
55 $helper->getDebugInstance()->output(sprintf("[%s:] Resolved IP address is: <strong>%s</strong><br />\n",
56 $helper->__toString(),
60 } catch (FrameworkException $e) {
64 // Return the IP address