use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
+use Org\Mxchange\CoreFramework\Localization\ManageableLanguage;
use Org\Mxchange\CoreFramework\Loader\ClassLoader;
use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Request\Requestable;
use Org\Mxchange\CoreFramework\Response\Responseable;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \BadMethodCallException;
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*/
private static $configurationInstance = NULL;
+ /**
+ * Database instance
+ */
+ private static $databaseInstance = NULL;
+
+ /**
+ * Language system instance
+ */
+ private static $languageInstance = NULL;
+
/*
* Includes applications may have. They will be tried in the given order,
* some will become soon deprecated.
return self::$configurationInstance;
}
- /**
- * Getter for request instance
- *
- * @return $requestInstance An instance of a Requestable class
- */
- public static function getRequestInstance () {
- return self::$requestInstance;
- }
-
- /**
- * Getter for response instance
- *
- * @return $responseInstance An instance of a Responseable class
- */
- public static function getResponseInstance () {
- return self::$responseInstance;
- }
-
/**
* "Getter" to get response/request type from analysis of the system.
*
// Load basic include files to continue bootstrapping
self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sclass_FrameworkInterface.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sclass_BaseFrameworkSystem.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
+ self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sutils%sstring%sclass_StringUtils.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sregistry%sclass_Registerable.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
self::loadInclude(new SplFileInfo(sprintf('%sconfig%sclass_FrameworkConfiguration.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR)));
/*
* 3) Now, that there are all request parameters being available, check
- * if 'app' is supplied. If it is not found, abort execution, if
+ * if 'application' is supplied. If it is not found, abort execution, if
* found, continue below with next step.
*/
self::validateApplicationParameter();
$applicationInstance = call_user_func_array(
array(
'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper', 'getSelfInstance'
- ), array()
+ ), []
);
// Some sanity checks
));
}
- // Set it in registry
- GenericRegistry::getRegistry()->addInstance('application', $applicationInstance);
-
// Now call all methods in one go
foreach (array('setupApplicationData', 'initApplication', 'launchApplication') as $methodName) {
// Debug message
$applicationInstance = ApplicationHelper::getSelfInstance();
// Is the database instance already set?
- if ($applicationInstance instanceof DatabaseConnector) {
+ if (self::getDatabaseInstance() instanceof DatabaseConnector) {
// Yes, then abort here
throw new BadMethodCallException('Method called twice.');
} // END - if
$connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance);
// Set it in application helper
- $applicationInstance->setDatabaseInstance($connectionInstance);
+ self::setDatabaseInstance($connectionInstance);
}
/**
*
* @param $timezone The timezone string (e.g. Europe/Berlin)
* @return $success If timezone was accepted
- * @throws NullPointerException If $timezone is NULL
* @throws InvalidArgumentException If $timezone is empty
*/
- public static function setDefaultTimezone ($timezone) {
- // Is it null?
- if (is_null($timezone)) {
- // Throw NPE
- throw new NullPointerException(NULL, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_string($timezone)) {
- // Is not a string
- throw new InvalidArgumentException(sprintf('timezone[]=%s is not a string', gettype($timezone)));
- } elseif ((is_string($timezone)) && (empty($timezone))) {
+ public static function setDefaultTimezone (string $timezone) {
+ // Is it set?
+ if (empty($timezone)) {
// Entry is empty
throw new InvalidArgumentException('timezone is empty');
}
* @todo Test more fields
*/
public static function isHttpSecured () {
- return (isset($_SERVER['HTTPS']));
+ return (
+ (
+ (
+ isset($_SERVER['HTTPS'])
+ ) && (
+ strtolower($_SERVER['HTTPS']) == 'on'
+ )
+ ) || (
+ (
+ isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
+ ) && (
+ strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https'
+ )
+ )
+ );
}
/**
// Do we have HTTPS?
if (self::isHttpSecured()) {
// Add the >s< for HTTPS
- $protocol = 's';
+ $protocol = 'https';
} // END - if
// Construct the full URL and secure it against CSRF attacks
$requestType = self::getRequestTypeFromSystem();
// Create a new request object
- $requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', BaseFrameworkSystem::convertToClassName($request)));
+ $requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', StringUtils::convertToClassName($request)));
// Remember request instance here
self::setRequestInstance($requestInstance);
} // END - if
// ... and a new response object
- $responseClass = sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', BaseFrameworkSystem::convertToClassName($request));
+ $responseClass = sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', StringUtils::convertToClassName($request));
$responseInstance = ObjectFactory::createObjectByName($responseClass);
// Remember response instance here
}
/**
- * 3) Validate parameter 'app' if it is set and the application is there.
+ * 3) Validate parameter 'application' if it is set and the application is there.
*
* @return void
*/
self::getConfigurationInstance()->setConfigEntry('detected_full_app_path', $applicationPath);
self::getConfigurationInstance()->setConfigEntry('detected_app_name' , $application);
}
+
+ /**
+ * Getter for request instance
+ *
+ * @return $requestInstance An instance of a Requestable class
+ */
+ public static function getRequestInstance () {
+ return self::$requestInstance;
+ }
+
+ /**
+ * Getter for response instance
+ *
+ * @return $responseInstance An instance of a Responseable class
+ */
+ public static function getResponseInstance () {
+ return self::$responseInstance;
+ }
+
/**
* Setter for request instance
*
self::$responseInstance = $responseInstance;
}
+ /**
+ * Setter for database instance
+ *
+ * @param $databaseInstance An instance of a DatabaseConnection class
+ * @return void
+ */
+ public static function setDatabaseInstance (DatabaseConnection $databaseInstance) {
+ self::$databaseInstance = $databaseInstance;
+ }
+
+ /**
+ * Getter for database instance
+ *
+ * @return $databaseInstance An instance of a DatabaseConnection class
+ */
+ public static function getDatabaseInstance () {
+ // Return instance
+ return self::$databaseInstance;
+ }
+
+ /**
+ * Private getter for language instance
+ *
+ * @return $languageInstance An instance of a ManageableLanguage class
+ */
+ public static function getLanguageInstance () {
+ return self::$languageInstance;
+ }
+
+ /**
+ * Setter for language instance
+ *
+ * @param $languageInstance An instance of a ManageableLanguage class
+ * @return void
+ */
+ public static function setLanguageInstance (ManageableLanguage $languageInstance) {
+ self::$languageInstance = $languageInstance;
+ }
+
}