use Org\Mxchange\CoreFramework\Console\Tools\ConsoleTools;
use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
use Org\Mxchange\CoreFramework\Localization\ManageableLanguage;
use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Request\Requestable;
use Org\Mxchange\CoreFramework\Response\Responseable;
use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*/
public static function isReachableFilePath (SplFileInfo $fileInstance) {
// Is not reachable by default
+ //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, get_class($fileInstance));
$isReachable = false;
// Get open_basedir parameter
$openBaseDir = trim(ini_get('open_basedir'));
// Is it set?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: openBaseDir=%s' . PHP_EOL, __METHOD__, __LINE__, $openBaseDir);
if (!empty($openBaseDir)) {
// Check all entries
foreach (explode(PATH_SEPARATOR, $openBaseDir) as $dir) {
// Check on existence
+ //* NOISY-DEBUG: */ printf('[%s:%d]: dir=%s' . PHP_EOL, __METHOD__, __LINE__, $dir);
if (substr($fileInstance->getPathname(), 0, strlen($dir)) == $dir) {
// Is reachable
$isReachable = true;
// Abort lookup as it has been found in open_basedir
+ //* NOISY-DEBUG: */ printf('[%s:%d]: BREAK!' . PHP_EOL, __METHOD__, __LINE__);
break;
}
}
} else {
// If open_basedir is not set, all is allowed
+ //* NOISY-DEBUG: */ printf('[%s:%d]: All is allowed - BREAK!' . PHP_EOL, __METHOD__, __LINE__);
$isReachable = true;
}
// Return status
+ //* NOISY-DEBUG: */ printf('[%s:%d]: isReachable=%d - EXIT' . PHP_EOL, __METHOD__, __LINE__, intval($isReachable));
return $isReachable;
}
* @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;
}
*/
public static function loadInclude (SplFileInfo $fileInstance) {
// Should be there ...
- //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance);
+ //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance->__toString());
if (!self::isReadableFile($fileInstance)) {
// Abort here
throw new InvalidArgumentException(sprintf('Cannot find fileInstance.pathname=%s.', $fileInstance->getPathname()));
+ } elseif (!$fileInstance->isFile()) {
+ // Not a file
+ throw new InvalidArgumentException(sprintf('fileInstance.pathname=%s is not a file', $fileInstance->getPathname()));
+ } elseif (substr($fileInstance->__toString(), -4, 4) != '.php') {
+ // Not PHP script
+ throw new InvalidArgumentException(sprintf('fileInstance.pathname=%s is not a PHP script', $fileInstance->getPathname()));
}
// Load it
* 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 - 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);
$fileInstance = new SplFileInfo(sprintf('%s%s.php', self::getDetectedApplicationPath(), $fileName));
// Determine if this file is wanted/readable/deprecated
ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileInstance->getBasename(), self::getDetectedApplicationName()));
} elseif (($status != 'required') && (!self::isReadableFile($fileInstance))) {
// Not found but optional/deprecated file, skip it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: fileName=%s,status=%s - SKIPPED!' . PHP_EOL, __METHOD__, __LINE__, $fileName, $status);
continue;
}
}
// Load it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking self::loadInclude(%s) ...' . PHP_EOL, __METHOD__, __LINE__, $fileInstance->__toString());
self::loadInclude($fileInstance);
}
+ // After this, sort the configuration array
+ self::getConfigurationInstance()->sortConfigurationArray();
+
// Scan for application's classes, exceptions and interfaces
ClassLoader::scanApplicationClasses();
+
+ // Trace message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
/**
*/
public static function startApplication () {
// Is there an application helper instance?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
$applicationInstance = call_user_func_array(
- array(
+ [
'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper', 'getSelfInstance'
- ), []
+ ], []
);
// Some sanity checks
+ //* NOISY-DEBUG: */ printf('[%s:%d]: applicationInstance=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationInstance->__toString());
if ((empty($applicationInstance)) || (is_null($applicationInstance))) {
// Something went wrong!
ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because the helper class <span class="class_name">%s</span> is not loaded.',
}
// Now call all methods in one go
+ //* NOISY-DEBUG: */ printf('[%s:%d]: Initializing application ...' . PHP_EOL, __METHOD__, __LINE__);
foreach (['setupApplicationData', 'initApplication', 'launchApplication'] as $methodName) {
// Call method
- //*NOISY-DEBUG: */ printf('[%s:%d]: Calling methodName=%s ...' . PHP_EOL, __METHOD__, __LINE__, $methodName);
+ //*NOISY-DEBUG: */ printf('[%s:%d]: Invoking methodName=%s ...' . PHP_EOL, __METHOD__, __LINE__, $methodName);
call_user_func([$applicationInstance, $methodName]);
}
+
+ // 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.');
$databaseInstance = ObjectFactory::createObjectByConfiguredName(self::getConfigurationInstance()->getConfigEntry('database_type') . '_class');
// Prepare database instance
- $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance);
+ $connectionInstance = DatabaseConnection::createDatabaseConnection($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('timezone is empty');
+ throw new InvalidArgumentException('Parameter "timezone" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
}
// Default success
$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__);
}
/**