From 9e9f3d45f19046eec33c9979a261224c645bb351 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 1 Jul 2015 02:49:12 +0200 Subject: [PATCH] Renamed class + introduced BaseCityTask which expands BaseTask. This requires that (an exception of the rules) an attribute must be defined at a 2nd location. Signed-off-by: Roland Haeder --- .../class_CityConsoleDaemonCommand.php | 2 +- .../factories/{city => city_daemon}/.htaccess | 0 .../class_CityDaemonFactory.php} | 4 +- .../states/city/class_CityStateFactory.php | 2 +- ...ss_CityDaemonBootstrapInitDaemonFilter.php | 2 +- .../class_CityDaemonInitializationFilter.php | 2 +- .../class_CityDaemonWelcomeTeaserFilter.php | 2 +- .../class_CityDaemonShutdownCityFilter.php | 2 +- ...CityDaemonTaskHandlerInitializerFilter.php | 2 +- .../city/active/class_CityActiveState.php | 2 +- .../city/main/tasks/class_BaseCityTask.php | 62 +++++++++++++++++++ .../class_CityDaemonBuildingGrowthTask.php | 2 +- .../class_CityDaemonHouseholdGrowthTask.php | 2 +- .../{city_map => map_expander}/.htaccess | 0 .../class_CityDaemonMapExpanderTask.php | 19 +++++- 15 files changed, 90 insertions(+), 15 deletions(-) rename application/city/main/factories/{city => city_daemon}/.htaccess (100%) rename application/city/main/factories/{city/class_CityDaemonObjectFactory.php => city_daemon/class_CityDaemonFactory.php} (96%) create mode 100644 application/city/main/tasks/class_BaseCityTask.php rename application/city/main/tasks/daemon/{city_map => map_expander}/.htaccess (100%) rename application/city/main/tasks/daemon/{city_map => map_expander}/class_CityDaemonMapExpanderTask.php (79%) diff --git a/application/city/main/commands/console/class_CityConsoleDaemonCommand.php b/application/city/main/commands/console/class_CityConsoleDaemonCommand.php index a0f444b..08f564e 100644 --- a/application/city/main/commands/console/class_CityConsoleDaemonCommand.php +++ b/application/city/main/commands/console/class_CityConsoleDaemonCommand.php @@ -72,7 +72,7 @@ class CityConsoleDaemonCommand extends BaseCommand implements Commandable { self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); // Get city instance - $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance(); + $cityInstance = CityDaemonFactory::createCityDaemonInstance(); // Add some city-specific filters, e.g. announcement $cityInstance->addExtraCityFilters(); diff --git a/application/city/main/factories/city/.htaccess b/application/city/main/factories/city_daemon/.htaccess similarity index 100% rename from application/city/main/factories/city/.htaccess rename to application/city/main/factories/city_daemon/.htaccess diff --git a/application/city/main/factories/city/class_CityDaemonObjectFactory.php b/application/city/main/factories/city_daemon/class_CityDaemonFactory.php similarity index 96% rename from application/city/main/factories/city/class_CityDaemonObjectFactory.php rename to application/city/main/factories/city_daemon/class_CityDaemonFactory.php index 0acfe5f..ac34e8f 100644 --- a/application/city/main/factories/city/class_CityDaemonObjectFactory.php +++ b/application/city/main/factories/city_daemon/class_CityDaemonFactory.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CityDaemonObjectFactory extends ObjectFactory { +class CityDaemonFactory extends ObjectFactory { /** * Protected constructor * @@ -42,7 +42,7 @@ class CityDaemonObjectFactory extends ObjectFactory { */ public static final function createCityDaemonInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) { // Get new factory instance - $factoryInstance = new CityDaemonObjectFactory(); + $factoryInstance = new CityDaemonFactory(); // If there is no handler? if (Registry::getRegistry()->instanceExists('city')) { diff --git a/application/city/main/factories/states/city/class_CityStateFactory.php b/application/city/main/factories/states/city/class_CityStateFactory.php index 64c42d8..8332257 100644 --- a/application/city/main/factories/states/city/class_CityStateFactory.php +++ b/application/city/main/factories/states/city/class_CityStateFactory.php @@ -47,7 +47,7 @@ class CityStateFactory extends ObjectFactory { $stateInstance = self::createObjectByConfiguredName($className); // Get city instance - $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance(); + $cityInstance = CityDaemonFactory::createCityDaemonInstance(); // Debug message self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: City state has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); diff --git a/application/city/main/filter/bootstrap/init/class_CityDaemonBootstrapInitDaemonFilter.php b/application/city/main/filter/bootstrap/init/class_CityDaemonBootstrapInitDaemonFilter.php index 69c20ca..5bc30aa 100644 --- a/application/city/main/filter/bootstrap/init/class_CityDaemonBootstrapInitDaemonFilter.php +++ b/application/city/main/filter/bootstrap/init/class_CityDaemonBootstrapInitDaemonFilter.php @@ -56,7 +56,7 @@ class CityDaemonBootstrapInitDaemonFilter extends BaseCityFilter implements Filt */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get city instance - $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance(); + $cityInstance = CityDaemonFactory::createCityDaemonInstance(); // Now bootstrap the daemon $cityInstance->bootstrapInitCityDaemon(); diff --git a/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php b/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php index 2a64d19..74a905e 100644 --- a/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php +++ b/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php @@ -56,7 +56,7 @@ class CityDaemonInitializationFilter extends BaseCityFilter implements Filterabl // Try to instance it by using a factory try { // Get an instance - $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance($requestInstance, $responseInstance); + $cityInstance = CityDaemonFactory::createCityDaemonInstance($requestInstance, $responseInstance); } catch (ClassNotFoundException $e) { // This exception means, the city mode is invalid. // @TODO Can we rewrite this to app_exit() ? diff --git a/application/city/main/filter/city_daemon/class_CityDaemonWelcomeTeaserFilter.php b/application/city/main/filter/city_daemon/class_CityDaemonWelcomeTeaserFilter.php index caf11ed..d2b1533 100644 --- a/application/city/main/filter/city_daemon/class_CityDaemonWelcomeTeaserFilter.php +++ b/application/city/main/filter/city_daemon/class_CityDaemonWelcomeTeaserFilter.php @@ -56,7 +56,7 @@ class CityDaemonWelcomeTeaserFilter extends BaseCityFilter implements Filterable */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get city instance - $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance(); + $cityInstance = CityDaemonFactory::createCityDaemonInstance(); // Now output the teaser $cityInstance->outputConsoleTeaser(); diff --git a/application/city/main/filter/shutdown/city/class_CityDaemonShutdownCityFilter.php b/application/city/main/filter/shutdown/city/class_CityDaemonShutdownCityFilter.php index 9a0faed..e92c27a 100644 --- a/application/city/main/filter/shutdown/city/class_CityDaemonShutdownCityFilter.php +++ b/application/city/main/filter/shutdown/city/class_CityDaemonShutdownCityFilter.php @@ -57,7 +57,7 @@ class CityDaemonShutdownCityFilter extends BaseCityFilter implements Filterable */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get city instance - $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance(); + $cityInstance = CityDaemonFactory::createCityDaemonInstance(); // Shutdown the city. This should be the last line $cityInstance->doShutdown(); diff --git a/application/city/main/filter/task/city_daemon/class_CityDaemonTaskHandlerInitializerFilter.php b/application/city/main/filter/task/city_daemon/class_CityDaemonTaskHandlerInitializerFilter.php index f4b8fbf..1a0eeef 100644 --- a/application/city/main/filter/task/city_daemon/class_CityDaemonTaskHandlerInitializerFilter.php +++ b/application/city/main/filter/task/city_daemon/class_CityDaemonTaskHandlerInitializerFilter.php @@ -56,7 +56,7 @@ class CityDaemonTaskHandlerInitializerFilter extends BaseCityFilter implements F */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get city instance - $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance(); + $cityInstance = CityDaemonFactory::createCityDaemonInstance(); // Get a new task handler instance $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class'); diff --git a/application/city/main/states/city/active/class_CityActiveState.php b/application/city/main/states/city/active/class_CityActiveState.php index b3956da..cbf3b67 100644 --- a/application/city/main/states/city/active/class_CityActiveState.php +++ b/application/city/main/states/city/active/class_CityActiveState.php @@ -45,7 +45,7 @@ class CityActiveState extends BaseCityState implements Stateable { $stateInstance = new CityActiveState(); // Get city instance and set 'active' flag - CityDaemonObjectFactory::createCityDaemonInstance()->enableIsActive(); + CityDaemonFactory::createCityDaemonInstance()->enableIsActive(); // Return the prepared instance return $stateInstance; diff --git a/application/city/main/tasks/class_BaseCityTask.php b/application/city/main/tasks/class_BaseCityTask.php new file mode 100644 index 0000000..1be4e51 --- /dev/null +++ b/application/city/main/tasks/class_BaseCityTask.php @@ -0,0 +1,62 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class BaseCityTask extends BaseTask { + /** + * An instance of a city + */ + private $cityInstance = NULL; + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Getter for city instance + * + * @return $cityInstance An instance of a city city + */ + public final function getCityInstance () { + return $this->cityInstance; + } + + /** + * Setter for city instance + * + * @param $cityInstance An instance of a city city + * @return void + */ + protected final function setCityInstance (CityHelper $cityInstance) { + $this->cityInstance = $cityInstance; + } +} + +// [EOF] +?> diff --git a/application/city/main/tasks/daemon/building/class_CityDaemonBuildingGrowthTask.php b/application/city/main/tasks/daemon/building/class_CityDaemonBuildingGrowthTask.php index b133795..54d6903 100644 --- a/application/city/main/tasks/daemon/building/class_CityDaemonBuildingGrowthTask.php +++ b/application/city/main/tasks/daemon/building/class_CityDaemonBuildingGrowthTask.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CityDaemonBuildingGrowthTask extends BaseTask implements Taskable, Visitable { +class CityDaemonBuildingGrowthTask extends BaseCityTask implements Taskable, Visitable { /** * Protected constructor * diff --git a/application/city/main/tasks/daemon/household/class_CityDaemonHouseholdGrowthTask.php b/application/city/main/tasks/daemon/household/class_CityDaemonHouseholdGrowthTask.php index ea041ed..179a927 100644 --- a/application/city/main/tasks/daemon/household/class_CityDaemonHouseholdGrowthTask.php +++ b/application/city/main/tasks/daemon/household/class_CityDaemonHouseholdGrowthTask.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CityDaemonHouseholdGrowthTask extends BaseTask implements Taskable, Visitable { +class CityDaemonHouseholdGrowthTask extends BaseCityTask implements Taskable, Visitable { /** * Protected constructor * diff --git a/application/city/main/tasks/daemon/city_map/.htaccess b/application/city/main/tasks/daemon/map_expander/.htaccess similarity index 100% rename from application/city/main/tasks/daemon/city_map/.htaccess rename to application/city/main/tasks/daemon/map_expander/.htaccess diff --git a/application/city/main/tasks/daemon/city_map/class_CityDaemonMapExpanderTask.php b/application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php similarity index 79% rename from application/city/main/tasks/daemon/city_map/class_CityDaemonMapExpanderTask.php rename to application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php index 6c0dad5..4152e92 100644 --- a/application/city/main/tasks/daemon/city_map/class_CityDaemonMapExpanderTask.php +++ b/application/city/main/tasks/daemon/map_expander/class_CityDaemonMapExpanderTask.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CityDaemonMapExpanderTask extends BaseTask implements Taskable, Visitable { +class CityDaemonMapExpanderTask extends BaseCityTask implements Taskable, Visitable { /** * Protected constructor * @@ -41,6 +41,12 @@ class CityDaemonMapExpanderTask extends BaseTask implements Taskable, Visitable // Get new instance $taskInstance = new CityDaemonMapExpanderTask(); + // Get city daemon instance + $cityInstance = CityDaemonFactory::createCityDaemonInstance(); + + // Set it here for "caching" it + $taskInstance->setCityInstance($cityInstance); + // Return the prepared instance return $taskInstance; } @@ -64,7 +70,14 @@ class CityDaemonMapExpanderTask extends BaseTask implements Taskable, Visitable * @todo 0% done */ public function executeTask () { - $this->partialStub('Unimplemented task.'); + // Get daemon instance + $cityInstance = $this->getCityInstance(); + + // Is there at least one map to expand? + if ($cityInstance->isMapPendingExpansion()) { + // Expand the map + $cityInstance->expandMaps(); + } // END - if } /** -- 2.39.5