From 2a4a84d632f4e2319b974c3ffd5d93613b1e785b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 7 Nov 2020 16:00:05 +0100 Subject: [PATCH] Continued: - ApplicationHelper no longer should hold application's data and a "self instance" as this is now all done in BaseApplication class - BaseFrameworkSystem->getConfigInstance() is now removed, always use non-monolithic FrameworkBootstrap::getConfigurationInstance() instead - convertToClassName() is now in StringUtils - updated core framework MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- application/city/class_ApplicationHelper.php | 91 ++----------------- .../city_daemon/class_BaseCityDaemon.php | 2 +- .../class_CityHtmlCityUserLoginCommand.php | 2 +- .../html/class_CityHtmlLoginAreaCommand.php | 2 +- .../html/class_CityHtmlResendLinkCommand.php | 3 +- .../class_CitySectionsDatabaseWrapper.php | 7 +- .../city_daemon/class_CityDaemonFactory.php | 9 +- .../login/helper/class_CityLoginHelper.php | 2 +- .../registration/class_CityRegistration.php | 4 +- application/city/config.php | 3 + core | 2 +- 11 files changed, 28 insertions(+), 99 deletions(-) diff --git a/application/city/class_ApplicationHelper.php b/application/city/class_ApplicationHelper.php index 17bf18b..9156d89 100644 --- a/application/city/class_ApplicationHelper.php +++ b/application/city/class_ApplicationHelper.php @@ -10,6 +10,7 @@ use Org\Mxchange\CoreFramework\Loader\ClassLoader; use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Utils\String\StringUtils; /** * A class holding general data about the application and some methods for @@ -51,26 +52,6 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ class ApplicationHelper extends BaseApplication implements ManageableApplication, Registerable { - /** - * The version number of this application - */ - private $appVersion = ''; - - /** - * The human-readable name for this application - */ - private $appName = ''; - - /** - * The short uni*-like name for this application - */ - private $shortName = ''; - - /** - * An instance of this class - */ - private static $selfInstance = NULL; - /** * Private constructor * @@ -88,71 +69,13 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication */ public static final function getSelfInstance () { // Is the instance there? - if (is_null(self::$selfInstance)) { - self::$selfInstance = new ApplicationHelper(); - } // END - if + if (is_null(self::getApplicationInstance())) { + // Set it + self::setApplicationInstance(new ApplicationHelper()); + } // Return the instance - return self::$selfInstance; - } - - /** - * Getter for the version number - * - * @return $appVersion The application's version number - */ - public final function getAppVersion () { - return $this->appVersion; - } - /** - * Setter for the version number - * - * @param $appVersion The application's version number - * @return void - */ - public final function setAppVersion ($appVersion) { - // Cast and set it - $this->appVersion = (string) $appVersion; - } - - /** - * Getter for human-readable name - * - * @return $appName The application's human-readable name - */ - public final function getAppName () { - return $this->appName; - } - - /** - * Setter for human-readable name - * - * @param $appName The application's human-readable name - * @return void - */ - public final function setAppName ($appName) { - // Cast and set it - $this->appName = (string) $appName;; - } - - /** - * Getter for short uni*-like name - * - * @return $shortName The application's short uni*-like name - */ - public final function getAppShortName () { - return $this->shortName; - } - - /** - * Setter for short uni*-like name - * - * @param $shortName The application's short uni*-like name - * @return void - */ - public final function setAppShortName ($shortName) { - // Cast and set it - $this->shortName = (string) $shortName; + return self::getApplicationInstance(); } /** @@ -208,7 +131,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication // Get a controller resolver $resolverClass = sprintf( 'Org\Mxchange\City\Resolver\Controller\%s', - self::convertToClassName(sprintf( + StringUtils::convertToClassName(sprintf( '%s_%s_controller_resolver', $this->getAppShortName(), FrameworkBootstrap::getRequestTypeFromSystem() diff --git a/application/city/classes/city_daemon/class_BaseCityDaemon.php b/application/city/classes/city_daemon/class_BaseCityDaemon.php index d4c5382..5e743d1 100644 --- a/application/city/classes/city_daemon/class_BaseCityDaemon.php +++ b/application/city/classes/city_daemon/class_BaseCityDaemon.php @@ -222,7 +222,7 @@ abstract class BaseCityDaemon extends BaseCitySystem implements Updateable, Adda */ public function updateCityData () { // Set some dummy configuration entries, e.g. city_status - $this->getConfigInstance()->setConfigEntry('city_status', $this->getStateInstance()->getStateName()); + FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('city_status', $this->getStateInstance()->getStateName()); } /** diff --git a/application/city/classes/commands/html/class_CityHtmlCityUserLoginCommand.php b/application/city/classes/commands/html/class_CityHtmlCityUserLoginCommand.php index c0949a6..edb4c67 100644 --- a/application/city/classes/commands/html/class_CityHtmlCityUserLoginCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlCityUserLoginCommand.php @@ -107,7 +107,7 @@ class CityHtmlCityUserLoginCommand extends BaseCommand implements Commandable { */ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Which login type do we have? - switch ($this->getConfigInstance()->getConfigEntry('login_type')) { + switch (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_type')) { case 'username': // Login via username $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_verifier_filter_class')); break; diff --git a/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php b/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php index a3fb669..bfa8ca1 100644 --- a/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php @@ -182,7 +182,7 @@ class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable { $applicationInstance = $registryInstance->getInstance('application'); // Default action is the one from configuration - $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action'); + $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_default_action'); // Get "action" from request $actReq = $requestInstance->getRequestElement('action'); diff --git a/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php b/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php index 172ecc6..55f82f0 100644 --- a/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php @@ -3,6 +3,7 @@ namespace Org\Mxchange\City\Command; // Import framework stuff +use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Command\BaseCommand; use Org\Mxchange\CoreFramework\Command\Commandable; use Org\Mxchange\CoreFramework\Controller\Controller; @@ -93,7 +94,7 @@ class CityHtmlResendLinkCommand extends BaseCommand implements Commandable { $userInstance->updateDatabaseField(UserDatabaseWrapper::DB_COLUMN_CONFIRM_HASH, $hashedString); // Re-set config entry to mailer engine - $this->getConfigInstance()->setConfigEntry('html_template_class', $this->getConfigInstance()->getConfigEntry('mail_template_class')); + FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('html_template_class', FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('mail_template_class')); // Prepare the template engine $templateInstance = $this->prepareTemplateInstance($applicationInstance); diff --git a/application/city/classes/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php b/application/city/classes/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php index 6f29ee8..2b4d671 100644 --- a/application/city/classes/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php +++ b/application/city/classes/database/frontend/city_entities/sections/class_CitySectionsDatabaseWrapper.php @@ -3,6 +3,7 @@ namespace Org\Mxchange\City\Database\Frontend\Sections; // Import framework stuff +use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseWrapper; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Registry\Registerable; @@ -165,11 +166,11 @@ class CitySectionsDatabaseWrapper extends BaseDatabaseWrapper implements CitySec * * totalInitialSections = (radius + 1) * (radius + 1) */ - $radius = $this->getConfigInstance()->getConfigEntry('city_max_initial_xy_expansion_radius'); + $radius = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('city_max_initial_xy_expansion_radius'); // Max up and down ... - $maxUp = $this->getConfigInstance()->getConfigEntry('city_max_initial_up_expansion'); - $maxDown = $this->getConfigInstance()->getConfigEntry('city_max_initial_down_expansion'); + $maxUp = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('city_max_initial_up_expansion'); + $maxDown = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('city_max_initial_down_expansion'); // Calculate total sections $totalSections = (($radius + 1) * ($radius + 1) * $maxUp * ($maxDown + 1)); diff --git a/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php b/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php index bd84eac..a44ae87 100644 --- a/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php +++ b/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php @@ -3,6 +3,7 @@ namespace Org\Mxchange\City\Daemon\Factory; // Import framework stuff +use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; @@ -59,7 +60,7 @@ class CityDaemonFactory extends ObjectFactory { $cityInstance = GenericRegistry::getRegistry()->getInstance('city'); } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) { // The default city-mode is from our configuration - $cityMode = $factoryInstance->getConfigInstance()->getConfigEntry('city_default_mode'); + $cityMode = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('city_default_mode'); // Is the city 'mode' parameter set? if ($requestInstance->isRequestElementSet('mode')) { @@ -70,11 +71,11 @@ class CityDaemonFactory extends ObjectFactory { $requestInstance->setRequestElement('mode', $cityMode); } - // Now convert the city-mode in a class name - $className = 'Org\Mxchange\City\Daemon\Simulation\Simulation' . $factoryInstance->convertToClassName($cityMode) . 'CityDaemon'; + // Now convert the city-mode in a configuration entry + $configEntry = sprintf('city_%s_daemon_mode_class', $cityMode); // Get the city instance - $cityInstance = ObjectFactory::createObjectByName($className, array($requestInstance)); + $cityInstance = ObjectFactory::createObjectByConfiguredName($configEntry, array($requestInstance)); // Get a registry $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); diff --git a/application/city/classes/login/helper/class_CityLoginHelper.php b/application/city/classes/login/helper/class_CityLoginHelper.php index 1a2db89..49876c1 100644 --- a/application/city/classes/login/helper/class_CityLoginHelper.php +++ b/application/city/classes/login/helper/class_CityLoginHelper.php @@ -95,7 +95,7 @@ class CityLoginHelper extends BaseLoginHelper implements HelpableLogin { * @return void */ protected function setDefaultAuthMethod () { - $this->authMethod = $this->getConfigInstance()->getConfigEntry('auth_method_class'); + $this->authMethod = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('auth_method_class'); } /** diff --git a/application/city/classes/registration/class_CityRegistration.php b/application/city/classes/registration/class_CityRegistration.php index 3b4ca6d..5c1e74b 100644 --- a/application/city/classes/registration/class_CityRegistration.php +++ b/application/city/classes/registration/class_CityRegistration.php @@ -177,7 +177,7 @@ class CityRegistration extends BaseRegistration implements UserRegister { $configEntry = 'user_status_unconfirmed'; // Is the confirmation process entirely disabled? - if ($this->getConfigInstance()->getConfigEntry('confirm_email_enabled') === 'N') { + if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('confirm_email_enabled') === 'N') { // No confirmation of email needed $configEntry = 'user_status_confirmed'; } // END - if @@ -200,7 +200,7 @@ class CityRegistration extends BaseRegistration implements UserRegister { } // Is this a guest account? - if ((($element == 'username') || ($alias == 'username')) && (FrameworkBootstrap::getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->getConfigEntry('guest_login_user'))) { + if ((($element == 'username') || ($alias == 'username')) && (FrameworkBootstrap::getRequestInstance()->getRequestElement($element) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('guest_login_user'))) { // Yes, then set the config entry to guest status $configEntry = 'user_status_guest'; } // END - if diff --git a/application/city/config.php b/application/city/config.php index bbadaf1..6a602fd 100644 --- a/application/city/config.php +++ b/application/city/config.php @@ -513,6 +513,9 @@ $cfg->setConfigEntry('default_city_console_command', 'daemon'); // CFG: DEFAULT-CITY-CONSOLE-CONTROLLER $cfg->setConfigEntry('default_city_console_controller', 'daemon'); +// CFG: CITY-DEFAULT-DAEMON-MODE-CLASS +$cfg->setConfigEntry('city_default_daemon_mode_class', 'Org\Mxchange\City\Daemon\Simulation\SimulationDefaultCityDaemon'); + // CFG: CITY-CONSOLE-CMD-DAEMON-RESOLVER-CLASS $cfg->setConfigEntry('city_console_cmd_daemon_resolver_class', 'Org\Mxchange\City\Resolver\Command\CityConsoleCommandResolver'); diff --git a/core b/core index c15d023..5138128 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c15d02389e67a880e7b4c6b19f2b06722efa4e6f +Subproject commit 513812814a5a17022d414727e5a4c6d0823fe5f6 -- 2.39.5