*/
protected function extractHostnameFromRawData (string $rawData) {
// Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: rawData=%s - CALLED!', $rawData));
if (empty($rawData)) {
// Throw IAE
throw new InvalidArgumentException('Parameter "rawData" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
$data = explode(PHP_EOL, $rawData);
// "Walk" through it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: data()=%d', count($data)));
foreach ($data as $line) {
// Trim it
$line = trim($line);
// Begins with a hash (#) = comment?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: line=%s', $line));
if (substr($line, 0, 1) == '#') {
// Then skip it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: line=%s - SKIPPED!', $line));
continue;
}
$hostData = explode('=', $line);
// Make sure only a key=value pair goes through
- assert(count($hostData) == 2);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostData()=%d', count($hostData)));
+ if (count($hostData) < 2) {
+ // Ops, wrong count
+ throw new UnexpectedValueException(sprintf('hostData()=%d is unexpected, line=%s', count($hostData), $line), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+ }
// Try to get it and abort
$hostname = str_replace(
['', ''],
$hostData[1]
);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from hostData - BREAK!', $hostname));
break;
} else {
// Use it directly
$hostname = $line;
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from line - BREAK!', $line));
break;
}
}
// Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - EXIT!', $hostname));
return $hostname;
}
*/
public static function resolveIpAddress (string $hostname) {
// Validate parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - CALLED!', $hostname));
if (empty($hostname)) {
// Throw IAE
throw new InvalidArgumentException('Parameter "hostname" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
// Resolve it
// @TODO Here should the cacher be implemented
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s', $hostname));
$ipResolved = gethostbyname($hostname);
// Was it fine?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: ipResolved[%s]=%s', gettype($ipResolved), $ipResolved));
if (($ipResolved !== false) && ($ipResolved != $hostname)) {
// Okay, this works!
$ipAddress = $ipResolved;
}
// Return resolved IP
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: ipAddress=%s - EXIT!', $ipAddress));
return $ipAddress;
}
*/
public static function acquireHostname () {
// Is cache there?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
if (!isset(self::$cache[__METHOD__])) {
// Get a new instance
$toolsInstance = new ConsoleTools();
$infoInstance = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('hostname_file'));
// Init host name
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: infoInstance=%s', $infoInstance->__toString()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: infoInstance=%s', $infoInstance->__toString()));
$hostname = 'host.invalid';
// Try to check /etc/hostname first
$fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', [$infoInstance]);
// Read the file
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: fileInstance=%s', $fileInstance->__toString()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: fileInstance=%s', $fileInstance->__toString()));
$rawData = trim($fileInstance->readFromFile());
// Close the file
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: rawData=%s', $rawData));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: rawData=%s', $rawData));
$fileInstance->closeFile();
// Extract hostname from it
$hostname = $toolsInstance->extractHostnameFromRawData($rawData);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from /etc/hostname', $hostname));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from /etc/hostname', $hostname));
} catch (FileNotFoundException $e) {
// Fall-back to 'SESSION_SVR' which found on my Sun Station
if (isset($_SERVER['SESSION_SVR'])) {
}
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from _SERVER array', $hostname));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from _SERVER array', $hostname));
} catch (FrameworkException $e) {
// Output debug message
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Problem while resolving own IP address: [%s|%s]:%s',
}
// Set cache
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting hostname=%s ...', $hostname));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting hostname=%s ...', $hostname));
self::$cache[__METHOD__] = $hostname;
} else {
// Get from cache
}
// Return it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - EXIT!', $hostname));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: hostname=%s - EXIT!', $hostname));
return $hostname;
}
*/
public static function acquireSelfIpAddress () {
// Is cache there?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
if (!isset(self::$cache[__METHOD__])) {
// Get host name
$hostname = self::acquireHostname();
// Resolve the IP number
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s', $hostname));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s', $hostname));
$ipAddress = self::resolveIpAddress($hostname);
// Set cache
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting ipAddress=%s ...', $ipAddress));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Setting ipAddress=%s ...', $ipAddress));
self::$cache[__METHOD__] = $ipAddress;
} else {
// Get it from cache
}
// Return it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: ipAddress=%s - EXIT!', $ipAddress));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: ipAddress=%s - EXIT!', $ipAddress));
return $ipAddress;
}
* Setup test case
*/
public static function setUpBeforeClass() {
- // Trace message
- /* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
-
// Call parent method
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
parent::setUpBeforeClass();
// Lookup own hostname
self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
// Trace message
- /* NOISY-DEBUG: */ printf('[%s:%d]: self::ipAddress[%s]=%s,self::hostname=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, gettype(self::$ipAddress), self::$ipAddress, self::$hostname);
+ //* NOISY-DEBUG: */ printf('[%s:%d]: self::ipAddress[%s]=%s,self::hostname=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, gettype(self::$ipAddress), self::$ipAddress, self::$hostname);
}
/**
$infoInstance = new SplFileInfo('/does/not/exist/');
// Invoke method
- /* NOISY-DEBUG: */ printf('[%s:%d]: infoInstance=%s' . PHP_EOL, __METHOD__, __LINE__, get_class($infoInstance));
+ //* NOISY-DEBUG: */ printf('[%s:%d]: infoInstance=%s' . PHP_EOL, __METHOD__, __LINE__, get_class($infoInstance));
$isReachable = FrameworkBootstrap::isReachableFilePath($infoInstance);
// Test if it is not reachable
- /* NOISY-DEBUG: */ printf('[%s:%d]: isReachable=%d' . PHP_EOL, __METHOD__, __LINE__, intval($isReachable));
+ //* NOISY-DEBUG: */ printf('[%s:%d]: isReachable=%d' . PHP_EOL, __METHOD__, __LINE__, intval($isReachable));
$this->assertTrue($isReachable, 'Returned true on a non-existing path');
// Trace message
$rootScriptPath = realpath(dirname(dirname(FrameworkBootstrap::detectScriptPath())));
// Set it
- /* NOISY-DEBUG: */ printf('[%s:%d]: open_basedir=%s,rootScriptPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, ini_get('open_basedir'), gettype($rootScriptPath), $rootScriptPath);
+ //* NOISY-DEBUG: */ printf('[%s:%d]: open_basedir=%s,rootScriptPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, ini_get('open_basedir'), gettype($rootScriptPath), $rootScriptPath);
$result = ini_set('open_basedir', $rootScriptPath . ':/etc/');
// Was it set?