* @return $isReadable Whether the file is readable (and therefor exists)
*/
public static function isReadableFile (SplFileInfo $fileInstance) {
- // Default is not readable
- $isReadable = false;
-
// Check if it is a file and readable
+ //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, get_class($fileInstance));
$isReadable = (
(
self::isReachableFilePath($fileInstance)
);
// Return status
+ //* NOISY-DEBUG: */ printf('[%s:%d]: isReadable=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, intval($isReadable));
return $isReadable;
}
* 1) Load class loader and scan framework classes, interfaces and
* exceptions.
*/
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
self::scanFrameworkClasses();
/*
* found, continue below with next step.
*/
self::validateApplicationParameter();
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
* Now check and load all files, found deprecated files will throw a
* warning at the user.
*/
- /* NOISY-DEBUG: */ printf('[%s:%d]: self::configAppIncludes()=%d' . PHP_EOL, __METHOD__, __LINE__, count(self::$configAppIncludes));
+ //* NOISY-DEBUG: */ printf('[%s:%d]: self::configAppIncludes()=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, count(self::$configAppIncludes));
foreach (self::$configAppIncludes as $fileName => $status) {
// Construct file instance
//* NOISY-DEBUG: */ printf('[%s:%d]: fileName=%s,status=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $status);
// Scan for application's classes, exceptions and interfaces
ClassLoader::scanApplicationClasses();
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
* Initializes database instance, no need to double-call this method
*
* @return void
+ * @throws BadMethodCallException If this method was invoked twice
*/
public static function initDatabaseInstance () {
// Get application instance
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
$applicationInstance = ApplicationHelper::getSelfInstance();
// Is the database instance already set?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: self::databaseInstance[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype(self::getDatabaseInstance()));
if (self::getDatabaseInstance() instanceof DatabaseConnector) {
// Yes, then abort here
throw new BadMethodCallException('Method called twice.');
$connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance);
// Set it in application helper
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Setting connectionInstance=%s ...' . PHP_EOL, __METHOD__, __LINE__, $connectionInstance->__toString());
self::setDatabaseInstance($connectionInstance);
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
*/
public static function detectServerAddress () {
// Is the entry set?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
if (!isset(self::$serverAddress)) {
// Is it set in $_SERVER?
if (!empty($_SERVER['SERVER_ADDR'])) {
// Set it from $_SERVER
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Setting self::serverAddress=%s from SERVER_ADDR ...' . PHP_EOL, __METHOD__, __LINE__, $_SERVER['SERVER_ADDR']);
self::$serverAddress = $_SERVER['SERVER_ADDR'];
} elseif (isset($_SERVER['SERVER_NAME'])) {
// Resolve IP address
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Resolving SERVER_NAME=%s ...' . PHP_EOL, __METHOD__, __LINE__, $_SERVER['SERVER_NAME']);
$serverIp = ConsoleTools::resolveIpAddress($_SERVER['SERVER_NAME']);
// Is it valid?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: serverId[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($serverIp), $serverIp);
if ($serverIp === false) {
/*
* Why is gethostbyname() returning the host name and not
}
// Al fine, set it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Setting self::serverAddress=%s from resolver ...' . PHP_EOL, __METHOD__, __LINE__, $serverAddress);
self::$serverAddress = $serverIp;
} else {
// Run auto-detecting through console tools lib
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking ConsoleTools::acquireSelfIpAddress() ...' . PHP_EOL, __METHOD__, __LINE__);
self::$serverAddress = ConsoleTools::acquireSelfIpAddress();
}
}
// Return it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: self::serverAddress=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$serverAddress);
return self::$serverAddress;
}
*/
public static function setDefaultTimezone (string $timezone) {
// Is it set?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: timezone=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $timezone);
if (empty($timezone)) {
// Entry is empty
throw new InvalidArgumentException('Parameter "timezone" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
$success = date_default_timezone_set($timezone);
// Return status
+ //* NOISY-DEBUG: */ printf('[%s:%d]: success=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, intval($success));
return $success;
}
* @todo Test more fields
*/
public static function isHttpSecured () {
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
return (
(
(
*/
public static function detectBaseUrl () {
// Initialize the URL
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
$protocol = 'http';
// Do we have HTTPS?
$baseUrl = sprintf('%s://%s%s', $protocol, self::detectDomain(), self::detectScriptPath());
// Return the URL
+ //* NOISY-DEBUG: */ printf('[%s:%d]: baseUrl=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $baseUrl);
return $baseUrl;
}
*/
public static function detectDomain () {
// Full domain is localnet.invalid by default
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
$fullDomain = 'localnet.invalid';
// Is the server name there?
}
// Return it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: fullDomain=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $fullDomain);
return $fullDomain;
}
*/
public static function detectScriptPath () {
// Default is empty
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
$scriptPath = '';
// Is the scriptname set?
}
// Return it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: scriptPath=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $scriptPath);
return $scriptPath;
}
*/
private static function scanFrameworkClasses () {
// Include class loader
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
require self::getConfigurationInstance()->getConfigEntry('framework_base_path') . 'loader/class_ClassLoader.php';
// Register auto-load function with the SPL
// Scan for all framework classes, exceptions and interfaces
ClassLoader::scanFrameworkClasses();
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
*/
private static function determineRequestType () {
// Determine request type
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
$request = self::getRequestTypeFromSystem();
$requestType = self::getRequestTypeFromSystem();
// Create a new request object
+ //* NOISY-DEBUG: */ printf('[%s:%d]: request=%s,requestType=%s' . PHP_EOL, __METHOD__, __LINE__, $request, $requestType);
$requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', StringUtils::convertToClassName($request)));
// Remember request instance here
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Setting requestInstance=%s ...' . PHP_EOL, __METHOD__, __LINE__, $requestInstance->__toString());
self::setRequestInstance($requestInstance);
// Do we have another response?
}
// ... and a new response object
+ //* NOISY-DEBUG: */ printf('[%s:%d]: request=%s,requestType=%s - AFTER!' . PHP_EOL, __METHOD__, __LINE__, $request, $requestType);
$responseInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', StringUtils::convertToClassName($request)));
// Remember response instance here
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Setting responseInstance=%s ...' . PHP_EOL, __METHOD__, __LINE__, $responseInstance->__toString());
self::setResponseInstance($responseInstance);
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
*/
private static function validateApplicationParameter () {
// Is the parameter set?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
if (!self::getRequestInstance()->isRequestElementSet('app')) {
/*
* Don't continue here, the application 'selector' is no longer
$applicationName = self::getRequestInstance()->getRequestElement('app');
// Secure it, by keeping out tags
+ //* NOISY-DEBUG: */ printf('[%s:%d]: applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationName);
$applicationName = htmlentities(strip_tags($applicationName), ENT_QUOTES);
// Secure it a little more with a reg.exp.
+ //* NOISY-DEBUG: */ printf('[%s:%d]: applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationName);
$applicationName = preg_replace('/([^a-z0-9_-])+/i', '', $applicationName);
// Construct FQPN (Full-Qualified Path Name) for ApplicationHelper class
+ //* NOISY-DEBUG: */ printf('[%s:%d]: applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationName);
$applicationPath = sprintf(
'%s%s%s',
self::getConfigurationInstance()->getConfigEntry('application_base_path'),
// Full path for application
// Is the path there? This secures a bit the parameter (from untrusted source).
+ //* NOISY-DEBUG: */ printf('[%s:%d]: applicationPath=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationPath);
if ((!is_dir($applicationPath)) || (!is_readable($applicationPath))) {
// Not found or not readable
ApplicationEntryPoint::exitApplication(sprintf('Application "%s" not found.', $applicationName));
}
// Set the detected application's name and full path for later usage
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Setting applicationPath=%s,applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationPath, $applicationName);
self::$detectedApplicationPath = $applicationPath;
self::$detectedApplicationName = $applicationName;
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
*/
public static final function exitApplication (string $message = '', int $code = -1, string $extraData = '', bool $silentMode = false) {
// Is this method already called?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,code=%d,extraData=%s,silentMode=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, $code, $extraData, intval($silentMode));
if (isset($GLOBALS['app_die_called'])) {
// Then output the text directly
print $message . PHP_EOL;
// Do we have debug installation?
if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) {
// Abort here
+ //* NOISY-DEBUG: */ printf('[%s:%d]: product_install_mode=%d,silentMode=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $configInstance->getConfigEntry('product_install_mode'), intval($silentMode));
exit(255);
}
printf('[Main:] Emergency exit reached: <span class="emergency_span">%s</span>', $message);
exit(255);
}
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
*/
public static final function detectFrameworkPath () {
// Is it not set?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath);
if (empty(self::$frameworkPath)) {
// Auto-detect core path (first application-common)
- foreach (array('core', __DIR__, '/usr/local/share/php/core', '/usr/share/php/core') as $possiblePath) {
+ foreach (['core', self::getRootPath(), '/usr/local/share/php/core', '/usr/share/php/core'] as $possiblePath) {
// Create full path for testing
+ //* NOISY-DEBUG: */ printf('[%s:%d]: possiblePath=%s' . PHP_EOL, __METHOD__, __LINE__, $possiblePath);
$realPath = realpath($possiblePath);
// Is it false?
//* NOISY-DEBUG: */ printf('[%s:%d]: realPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($realPath), $realPath);
if ($realPath === false) {
// Then, not found.
+ //* NOISY-DEBUG: */ printf('[%s:%d]: possiblePath=%s was not found. - SKIPPED!' . PHP_EOL, __METHOD__, __LINE__, $possiblePath);
continue;
}
$frameworkPath = sprintf('%s%sframework%s', $realPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
// First create full-qualified file name (FQFN) to framework/config-global.php
+ //* NOISY-DEBUG: */ printf('[%s:%d]: frameworkPath=%s' . PHP_EOL, __METHOD__, __LINE__, $frameworkPath);
$configFile = $frameworkPath . 'config-global.php';
// Is it readable?
self::$frameworkPath = $frameworkPath;
// Abort here
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Setting self::frameworkPath=%s - BREAK!' . PHP_EOL, __METHOD__, __LINE__, $frameworkPath);
break;
}
}
// Able to find?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - Checking ...' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath);
if (!is_dir(self::$frameworkPath)) {
// Is no directory
throw new Exception('Cannot find framework.');
}
// Return it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath);
return self::$frameworkPath;
}
*/
public static final function main () {
// Load bootstrap file
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
require sprintf('%sbootstrap%sbootstrap.inc.php', self::detectFrameworkPath(), DIRECTORY_SEPARATOR);
/*
* register the application instance in registry.
*/
FrameworkBootstrap::startApplication();
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
}
// Log all exceptions (only debug! This option can create large error logs)
//define('LOG_EXCEPTIONS', true);
-//xdebug_start_trace();
-
// Call above main() method
ApplicationEntryPoint::main();