From: Roland Haeder Date: Sun, 28 Jun 2015 19:45:00 +0000 (+0200) Subject: Renamed some more files city -> city_daemon to avoid confusion as these classes X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7dbafe9738dfbc67b085ea983cc09c919a912fd6;p=city.git Renamed some more files city -> city_daemon to avoid confusion as these classes are only for the daemon and not for any frontends. Signed-off-by: Roland Haeder --- diff --git a/application/city/config.php b/application/city/config.php index 527502c..ab67804 100644 --- a/application/city/config.php +++ b/application/city/config.php @@ -52,6 +52,9 @@ $cfg->setConfigEntry('region_map_db_wrapper_class', 'RegionMapDatabaseWrapper'); // CFG: CITY-INIT-STATE-CLASS $cfg->setConfigEntry('city_init_state_class', 'CityInitState'); +// CFG: CITY-VIRGIN-STATE-CLASS +$cfg->setConfigEntry('city_virgin_state_class', 'CityVirginState'); + /****************************************************************************** * HTML client * ******************************************************************************/ @@ -510,6 +513,9 @@ $cfg->setConfigEntry('city_daemon_activation_task_handler_initializer_filter', ' // CFG: CITY-DAEMON-WELCOME-TEASER-FILTER $cfg->setConfigEntry('city_daemon_welcome_teaser_filter', 'CityDaemonWelcomeTeaserFilter'); +// CFG: CITY-DAEMON-BOOTSTRAP-INIT-DAEMON-FILTER +$cfg->setConfigEntry('city_daemon_bootstrap_init_daemon_filter', 'CityDaemonBootstrapInitDaemonFilter'); + // CFG: CITY-DAEMON-SHUTDOWN-TASK-HANDLER-FILTER $cfg->setConfigEntry('city_daemon_shutdown_task_handler_filter', 'CityDaemonShutdownTaskHandlerFilter'); diff --git a/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php b/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php index 9484065..7c45cf0 100644 --- a/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php +++ b/application/city/interfaces/database/frontend/city/class_CityInformationWrapper.php @@ -30,7 +30,7 @@ interface CityInformationWrapper extends DatabaseWrapper { * @param $requestInstance An instance of a Requestable class * @return void */ - function registerCityId (BaseCity $cityInstance, Requestable $requestInstance); + function registerCityId (BaseCityDaemon $cityInstance, Requestable $requestInstance); /** * Checks whether there is an entry for given city instance diff --git a/application/city/interfaces/helper/city/class_CityHelper.php b/application/city/interfaces/helper/city/class_CityHelper.php index 7f3e0e3..bf4a413 100644 --- a/application/city/interfaces/helper/city/class_CityHelper.php +++ b/application/city/interfaces/helper/city/class_CityHelper.php @@ -22,6 +22,13 @@ * along with this program. If not, see . */ interface CityHelper extends Helper, AddableCriteria { + /** + * Initializes the city daemon + * + * @return void + */ + function bootstrapInitCityDaemon (); + /** * Method to "bootstrap" the city. This step does also apply provided * command-line arguments stored in the request instance. You should now diff --git a/application/city/main/city/.htaccess b/application/city/main/city/.htaccess deleted file mode 100644 index 3a42882..0000000 --- a/application/city/main/city/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/city/main/city/class_ b/application/city/main/city/class_ deleted file mode 100644 index 19410ec..0000000 --- a/application/city/main/city/class_ +++ /dev/null @@ -1,98 +0,0 @@ - - * @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 Simulation???City extends BaseCity implements CityHelper, Registerable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this hub-node class - * - * @param $requestInstance An instance of a Requestable class - * @return $nodeInstance An instance of this hub-node class - */ - public final static function createCity???City (Requestable $requestInstance) { - // Get a new instance - $nodeInstance = new City???City(); - - // Set the request instance - $nodeInstance->setRequestInstance($requestInstance); - - // Return the instance - return $nodeInstance; - } - - /** - * Method to "bootstrap" the node. This step does also apply provided - * command-line arguments stored in the request instance. The regular node - * should communicate with the bootstrap-nodes at this point. - * - * @return void - * @todo Implement this method - */ - public function doBootstrapping () { - // Call generic (parent) bootstrapping method first - parent::doGenericBootstrapping(); - $this->partialStub('Please implement this method.'); - } - - /** - * Initializes hub-specific queues - * - * @return void - * @todo Implement this method - */ - public function initQueues () { - $this->partialStub('Please implement this method.'); - } - - /** - * Add some node-specific filters - * - * @return void - */ - public function addExtraCityFilters () { - // Add some filters here - } - - /** - * Adds extra tasks to the given handler for this node - * - * @param $handlerInstance An instance of a HandleableTask class - * @return void - * @todo 0% done - */ - public function addExtraTasks (HandleableTask $handlerInstance) { - $this->partialStub('Please add some tasks or empty this method.'); - } -} - -// [EOF] -?> diff --git a/application/city/main/city/class_BaseCity.php b/application/city/main/city/class_BaseCity.php deleted file mode 100644 index e6243f5..0000000 --- a/application/city/main/city/class_BaseCity.php +++ /dev/null @@ -1,241 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2015 City Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.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 BaseCity extends BaseCitySystem implements Updateable, AddableCriteria { - /** - * City types - */ - const CITY_TYPE_TESTING = 'testing'; - - /** - * Whether this City is active (default: FALSE) - */ - private $isActive = FALSE; - - /** - * Protected constructor - * - * @param $className Name of the class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - - // Get a wrapper instance - $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_info_db_wrapper_class'); - - // Set it here - $this->setWrapperInstance($wrapperInstance); - - // Get a crypto instance - $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class'); - - // Set it here - $this->setCryptoInstance($cryptoInstance); - - // Init state which sets the state to 'init' - $this->initState(); - } - - /** - * Initializes the City's state which sets it to 'init' - * - * @return void - */ - private function initState() { - // Get the state factory and create the initial state. - CityStateFactory::createCityStateInstanceByName('init', $this); - } - - /** - * Outputs the console teaser. This should only be executed on startup or - * full restarts. This method generates some space around the teaser. - * - * @return void - */ - public function outputConsoleTeaser () { - // Get the app instance (for shortening our code) - $app = $this->getApplicationInstance(); - - // Output all lines - self::createDebugInstance(__CLASS__)->debugOutput(' '); - self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' daemon starting'); - self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2015 City Developer Team'); - self::createDebugInstance(__CLASS__)->debugOutput(' '); - self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); - self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain'); - self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.'); - self::createDebugInstance(__CLASS__)->debugOutput(' '); - } - - /** - * Adds City data elements to a given dataset instance - * - * @param $criteriaInstance An instance of a storeable criteria - * @param $requestInstance An instance of a Requestable class - * @return void - */ - public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) { - // Make sure the request instance is set as it is not optional. - assert($requestInstance instanceof Requestable); - - // Add City number and type - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_ID , 1); - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_MODE, $requestInstance->getRequestElement('mode')); - - // Add the City id - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_ID, $this->getCityId()); - - // Add the session id if acquired - if ($this->getSessionId() != '') { - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId()); - } // END - if - - // Add the private key if acquired - if ($this->getPrivateKey() != '') { - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey())); - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash()); - } // END - if - - // Add own external and internal addresses as UNLs - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, CityTools::determineOwnInternalAddress()); - $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, CityTools::determineOwnExternalAddress()); - } - - /** - * Updates a given field with new value - * - * @param $fieldName Field to update - * @param $fieldValue New value to store - * @return void - * @throws DatabaseUpdateSupportException If this class does not support database updates - * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem - */ - public function updateDatabaseField ($fieldName, $fieldValue) { - // Unfinished - $this->partialStub('Unfinished!'); - return; - - // Get a critieria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Add search criteria - $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); - $searchInstance->setLimit(1); - - // Now get another criteria - $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class'); - - // Add criteria entry which we shall update - $updateInstance->addCriteria($fieldName, $fieldValue); - - // Add the search criteria for searching for the right entry - $updateInstance->setSearchInstance($searchInstance); - - // Set wrapper class name - $updateInstance->setWrapperConfigEntry('user_db_wrapper_class'); - - // Remember the update in database result - $this->getResultInstance()->add2UpdateQueue($updateInstance); - } - - /** - * Activates the City by doing some final preparation and setting - * $CityIsActive to TRUE. - * - * @param $requestInstance A Requestable class - * @param $responseInstance A Responseable class - * @return void - */ - public function activateCity (Requestable $requestInstance, Responseable $responseInstance) { - // Get the controller here - $controllerInstance = Registry::getRegistry()->getInstance('controller'); - - // Run all filters for the City activation - $controllerInstance->executeActivationFilters($requestInstance, $responseInstance); - - // Make sure the city's state is 'virigin' - assert($this->getStateInstance()->validateCityStateIsVirgin() === TRUE); - - // ----------------------- Last step from here ------------------------ - // Activate the City. This is ALWAYS the last step in this method - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CITY[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getStateInstance()->__toString()); - $this->getStateInstance()->citySimulationIsActivated(); - // ---------------------- Last step until here ------------------------ - } - - /** - * Getter for isActive attribute - * - * @return $isActive Whether the City is active - */ - public final function isCityActive () { - return $this->isActive; - } - - /** - * Enables (default) or disables isActive flag - * - * @param $isActive Whether the City is active - * @return void - */ - public final function enableIsActive ($isActive = TRUE) { - $this->isActive = (bool) $isActive; - } - - /** - * Updates/refreshes City data (e.g. status). - * - * @return void - * @todo Find more to do here - */ - public function updateCityData () { - // Set some dummy configuration entries, e.g. city_status - $this->getConfigInstance()->setConfigEntry('city_status', $this->getStateInstance()->getStateName()); - } - - /** - * Adds all required elements from given array into data set instance - * - * @param $dataSetInstance An instance of a StoreableCriteria class - * @param $CityData An array with valid City data - * @return void - */ - public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $cityData) { - // Add all data the array provides - foreach (CityInformationDatabaseWrapper::getAllElements() as $element) { - // Is the element there? - if (isset($cityData[$element])) { - // Add it - $dataSetInstance->addCriteria($element, $cityData[$element]); - } else { - // Output warning message - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CITY[' . __METHOD__ . ':' . __LINE__ . ']: addArrayToDataSet(): Element ' . $element . ' not found in CityData array.'); - } - } // END - foreac - } -} - -// [EOF] -?> diff --git a/application/city/main/city/testing/.htaccess b/application/city/main/city/testing/.htaccess deleted file mode 100644 index 3a42882..0000000 --- a/application/city/main/city/testing/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/city/main/city/testing/class_SimulationTestingCity.php b/application/city/main/city/testing/class_SimulationTestingCity.php deleted file mode 100644 index 798e3de..0000000 --- a/application/city/main/city/testing/class_SimulationTestingCity.php +++ /dev/null @@ -1,96 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2015 City Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.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 SimulationTestingCity extends BaseCity implements CityHelper, Registerable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this hub-node class - * - * @param $requestInstance An instance of a Requestable class - * @return $nodeInstance An instance of this hub-node class - */ - public static final function createSimulationTestingCity (Requestable $requestInstance) { - // Get a new instance - $nodeInstance = new SimulationTestingCity(); - - // Set the request instance - $nodeInstance->setRequestInstance($requestInstance); - - // Return the instance - return $nodeInstance; - } - - /** - * Method to "bootstrap" the node. This step does also apply provided - * command-line arguments stored in the request instance. The regular node - * should communicate with the bootstrap-nodes at this point. - * - * @return void - * @todo Implement this method - */ - public function doBootstrapping () { - $this->partialStub(); - } - - /** - * Add some node-specific filters - * - * @return void - */ - public function addExtraCityFilters () { - // Get the application instance from registry - $applicationInstance = Registry::getRegistry()->getInstance('app'); - - // Get the controller from the application - $controllerInstance = $applicationInstance->getControllerInstance(); - - // Foo task - // @TODO $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('city_foo_task_filter')); - - // @TODO Add some filters here - $this->partialStub('Add some filters here.'); - } - - /** - * Adds extra tasks to the given handler for this node - * - * @param $handlerInstance An instance of a HandleableTask class - * @return void - * @todo 0% done - */ - public function addExtraTasks (HandleableTask $handlerInstance) { - $this->partialStub('Please add some tasks or empty this method.'); - } -} - -// [EOF] -?> diff --git a/application/city/main/city_daemon/.htaccess b/application/city/main/city_daemon/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/city_daemon/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/city_daemon/class_ b/application/city/main/city_daemon/class_ new file mode 100644 index 0000000..94302a2 --- /dev/null +++ b/application/city/main/city_daemon/class_ @@ -0,0 +1,98 @@ + + * @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 Simulation???CityDaemon extends BaseCity implements CityHelper, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this hub-node class + * + * @param $requestInstance An instance of a Requestable class + * @return $nodeInstance An instance of this hub-node class + */ + public final static function createSimulation???CityDaemon (Requestable $requestInstance) { + // Get a new instance + $nodeInstance = new Simulation???CityDaemon(); + + // Set the request instance + $nodeInstance->setRequestInstance($requestInstance); + + // Return the instance + return $nodeInstance; + } + + /** + * Method to "bootstrap" the node. This step does also apply provided + * command-line arguments stored in the request instance. The regular node + * should communicate with the bootstrap-nodes at this point. + * + * @return void + * @todo Implement this method + */ + public function doBootstrapping () { + // Call generic (parent) bootstrapping method first + parent::doGenericBootstrapping(); + $this->partialStub('Please implement this method.'); + } + + /** + * Initializes hub-specific queues + * + * @return void + * @todo Implement this method + */ + public function initQueues () { + $this->partialStub('Please implement this method.'); + } + + /** + * Add some node-specific filters + * + * @return void + */ + public function addExtraCityFilters () { + // Add some filters here + } + + /** + * Adds extra tasks to the given handler for this node + * + * @param $handlerInstance An instance of a HandleableTask class + * @return void + * @todo 0% done + */ + public function addExtraTasks (HandleableTask $handlerInstance) { + $this->partialStub('Please add some tasks or empty this method.'); + } +} + +// [EOF] +?> diff --git a/application/city/main/city_daemon/class_BaseCityDaemon.php b/application/city/main/city_daemon/class_BaseCityDaemon.php new file mode 100644 index 0000000..661c613 --- /dev/null +++ b/application/city/main/city_daemon/class_BaseCityDaemon.php @@ -0,0 +1,256 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 BaseCityDaemon extends BaseCitySystem implements Updateable, AddableCriteria { + /** + * City types + */ + const CITY_TYPE_TESTING = 'testing'; + + /** + * Whether this City is active (default: FALSE) + */ + private $isActive = FALSE; + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Get a wrapper instance + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('city_info_db_wrapper_class'); + + // Set it here + $this->setWrapperInstance($wrapperInstance); + + // Get a crypto instance + $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class'); + + // Set it here + $this->setCryptoInstance($cryptoInstance); + + // Add own instance to registry + Registry::getRegistry()->addInstance('city', $this); + + // Init state which sets the state to 'init' + $this->initState(); + } + + /** + * Initializes the City's state which sets it to 'init' + * + * @return void + */ + private function initState() { + // Get the state factory and create the initial state. + CityStateFactory::createCityStateInstanceByName('init'); + } + + /** + * Outputs the console teaser. This should only be executed on startup or + * full restarts. This method generates some space around the teaser. + * + * @return void + */ + public function outputConsoleTeaser () { + // Get the app instance (for shortening our code) + $app = $this->getApplicationInstance(); + + // Output all lines + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' daemon starting'); + self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2015 City Developer Team'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); + self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain'); + self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + } + + /** + * Adds City data elements to a given dataset instance + * + * @param $criteriaInstance An instance of a storeable criteria + * @param $requestInstance An instance of a Requestable class + * @return void + */ + public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) { + // Make sure the request instance is set as it is not optional. + assert($requestInstance instanceof Requestable); + + // Add City number and type + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_ID , 1); + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_MODE, $requestInstance->getRequestElement('mode')); + + // Add the City id + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_CITY_ID, $this->getCityId()); + + // Add the session id if acquired + if ($this->getSessionId() != '') { + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId()); + } // END - if + + // Add the private key if acquired + if ($this->getPrivateKey() != '') { + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey())); + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash()); + } // END - if + + // Add own external and internal addresses as UNLs + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, CityTools::determineOwnInternalAddress()); + $criteriaInstance->addCriteria(CityInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, CityTools::determineOwnExternalAddress()); + } + + /** + * Updates a given field with new value + * + * @param $fieldName Field to update + * @param $fieldValue New value to store + * @return void + * @throws DatabaseUpdateSupportException If this class does not support database updates + * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem + */ + public function updateDatabaseField ($fieldName, $fieldValue) { + // Unfinished + $this->partialStub('Unfinished!'); + return; + + // Get a critieria instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Add search criteria + $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); + $searchInstance->setLimit(1); + + // Now get another criteria + $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class'); + + // Add criteria entry which we shall update + $updateInstance->addCriteria($fieldName, $fieldValue); + + // Add the search criteria for searching for the right entry + $updateInstance->setSearchInstance($searchInstance); + + // Set wrapper class name + $updateInstance->setWrapperConfigEntry('user_db_wrapper_class'); + + // Remember the update in database result + $this->getResultInstance()->add2UpdateQueue($updateInstance); + } + + /** + * Activates the City by doing some final preparation and setting + * $CityIsActive to TRUE. + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + public function activateCity (Requestable $requestInstance, Responseable $responseInstance) { + // Get the controller here + $controllerInstance = Registry::getRegistry()->getInstance('controller'); + + // Run all filters for the City activation + $controllerInstance->executeActivationFilters($requestInstance, $responseInstance); + + // Make sure the city's state is 'virigin' + $this->getStateInstance()->validateCityStateIsVirgin(); + + // ----------------------- Last step from here ------------------------ + // Activate the City. This is ALWAYS the last step in this method + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CITY[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getStateInstance()->__toString()); + $this->getStateInstance()->citySimulationIsActivated(); + // ---------------------- Last step until here ------------------------ + } + + /** + * Getter for isActive attribute + * + * @return $isActive Whether the City is active + */ + public final function isCityActive () { + return $this->isActive; + } + + /** + * Enables (default) or disables isActive flag + * + * @param $isActive Whether the City is active + * @return void + */ + public final function enableIsActive ($isActive = TRUE) { + $this->isActive = (bool) $isActive; + } + + /** + * Updates/refreshes City data (e.g. status). + * + * @return void + * @todo Find more to do here + */ + public function updateCityData () { + // Set some dummy configuration entries, e.g. city_status + $this->getConfigInstance()->setConfigEntry('city_status', $this->getStateInstance()->getStateName()); + } + + /** + * Adds all required elements from given array into data set instance + * + * @param $dataSetInstance An instance of a StoreableCriteria class + * @param $CityData An array with valid City data + * @return void + */ + public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $cityData) { + // Add all data the array provides + foreach (CityInformationDatabaseWrapper::getAllElements() as $element) { + // Is the element there? + if (isset($cityData[$element])) { + // Add it + $dataSetInstance->addCriteria($element, $cityData[$element]); + } else { + // Output warning message + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CITY[' . __METHOD__ . ':' . __LINE__ . ']: addArrayToDataSet(): Element ' . $element . ' not found in CityData array.'); + } + } // END - foreac + } + + /** + * Initializes the city daemon + * + * @return void + */ + public function bootstrapInitCityDaemon () { + $this->partialStub('Please add something here.'); + + // Daemon has been fully initialized, so change state to 'virgin' + $this->getStateInstance()->daemonHasInitialized(); + } +} + +// [EOF] +?> diff --git a/application/city/main/city_daemon/testing/.htaccess b/application/city/main/city_daemon/testing/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/city_daemon/testing/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/city_daemon/testing/class_SimulationTestingCityDaemon.php b/application/city/main/city_daemon/testing/class_SimulationTestingCityDaemon.php new file mode 100644 index 0000000..4931779 --- /dev/null +++ b/application/city/main/city_daemon/testing/class_SimulationTestingCityDaemon.php @@ -0,0 +1,95 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 SimulationTestingCityDaemon extends BaseCityDaemon implements CityHelper, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this hub-node class + * + * @param $requestInstance An instance of a Requestable class + * @return $nodeInstance An instance of this hub-node class + */ + public static final function createSimulationTestingCityDaemon (Requestable $requestInstance) { + // Get a new instance + $nodeInstance = new SimulationTestingCityDaemon(); + + // Set the request instance + $nodeInstance->setRequestInstance($requestInstance); + + // Return the instance + return $nodeInstance; + } + + /** + * Method to "bootstrap" the city simulation. This step does also apply + * provided command-line arguments stored in the request instance. + * + * @return void + * @todo Implement this method + */ + public function doBootstrapping () { + $this->partialStub(); + } + + /** + * Add some node-specific filters + * + * @return void + */ + public function addExtraCityFilters () { + // Get the application instance from registry + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + // Get the controller from the application + $controllerInstance = $applicationInstance->getControllerInstance(); + + // Foo task + // @TODO $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('city_foo_task_filter')); + + // @TODO Add some filters here + $this->partialStub('Add some filters here.'); + } + + /** + * Adds extra tasks to the given handler for this node + * + * @param $handlerInstance An instance of a HandleableTask class + * @return void + * @todo 0% done + */ + public function addExtraTasks (HandleableTask $handlerInstance) { + $this->partialStub('Please add some tasks or empty this method.'); + } +} + +// [EOF] +?> diff --git a/application/city/main/commands/console/class_CityConsoleDaemonCommand.php b/application/city/main/commands/console/class_CityConsoleDaemonCommand.php index 80c3691..a49d86d 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 = CityObjectFactory::createCityInstance(); + $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance(); // Add some city-specific filters, e.g. announcement $cityInstance->addExtraCityFilters(); @@ -120,7 +120,7 @@ class CityConsoleDaemonCommand extends BaseCommand implements Commandable { $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('city_daemon_welcome_teaser_filter')); // Add bootstrap filters - //$controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('city_daemon_bootstrap_generate_cityid_filter')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('city_daemon_bootstrap_init_daemon_filter')); // Add city activation filters $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('city_daemon_activation_task_handler_initializer_filter')); diff --git a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php index 9322280..6bebe8f 100644 --- a/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php +++ b/application/city/main/database/frontend/city/class_CityInformationDatabaseWrapper.php @@ -94,7 +94,7 @@ class CityInformationDatabaseWrapper extends BaseDatabaseWrapper implements City * @param $requestInstance An instance of a Requestable class * @return void */ - public function registerCityId (BaseCity $cityInstance, Requestable $requestInstance) { + public function registerCityId (BaseCityDaemon $cityInstance, Requestable $requestInstance) { // Get a dataset instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_CITY_INFORMATION)); diff --git a/application/city/main/factories/city/class_CityDaemonObjectFactory.php b/application/city/main/factories/city/class_CityDaemonObjectFactory.php new file mode 100644 index 0000000..0acfe5f --- /dev/null +++ b/application/city/main/factories/city/class_CityDaemonObjectFactory.php @@ -0,0 +1,89 @@ + + * @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 CityDaemonObjectFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton (registry-based) CityHelper instance + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return $cityInstance An instance of a CityHelper class + * @throws FactoryRequiredParameterException If not all parameters are set and no instance 'city' is set. + */ + public static final function createCityDaemonInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) { + // Get new factory instance + $factoryInstance = new CityDaemonObjectFactory(); + + // If there is no handler? + if (Registry::getRegistry()->instanceExists('city')) { + // Get handler from registry + $cityInstance = Registry::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'); + + // Is the city 'mode' parameter set? + if ($requestInstance->isRequestElementSet('mode')) { + // Then use this which overrides the config entry temporarily + $cityMode = $requestInstance->getRequestElement('mode'); + } else { + // Set it for easier re-usage + $requestInstance->setRequestElement('mode', $cityMode); + } + + // Now convert the city-mode in a class name + $className = 'Simulation' . $factoryInstance->convertToClassName($cityMode) . 'CityDaemon'; + + // Get the city instance + $cityInstance = ObjectFactory::createObjectByName($className, array($requestInstance)); + + // Get a registry + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + // Set the app instance + $cityInstance->setApplicationInstance($applicationInstance); + + // Add city-specific filters + $cityInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); + } else { + // Throw an exception here + throw new FactoryRequiredParameterException($factoryInstance, self::EXCEPTION_FACTORY_REQUIRE_PARAMETER); + } + + // Return the instance + return $cityInstance; + } +} + +// [EOF] +?> diff --git a/application/city/main/factories/city/class_CityObjectFactory.php b/application/city/main/factories/city/class_CityObjectFactory.php deleted file mode 100644 index a4be719..0000000 --- a/application/city/main/factories/city/class_CityObjectFactory.php +++ /dev/null @@ -1,92 +0,0 @@ - - * @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 CityObjectFactory extends ObjectFactory { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Returns a singleton (registry-based) CityHelper instance - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return $cityInstance An instance of a CityHelper class - * @throws FactoryRequiredParameterException If not all parameters are set and no instance 'city' is set. - */ - public static final function createCityInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) { - // Get new factory instance - $factoryInstance = new CityObjectFactory(); - - // If there is no handler? - if (Registry::getRegistry()->instanceExists('city')) { - // Get handler from registry - $cityInstance = Registry::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'); - - // Is the city 'mode' parameter set? - if ($requestInstance->isRequestElementSet('mode')) { - // Then use this which overrides the config entry temporarily - $cityMode = $requestInstance->getRequestElement('mode'); - } else { - // Set it for easier re-usage - $requestInstance->setRequestElement('mode', $cityMode); - } - - // Now convert the city-mode in a class name - $className = 'Simulation' . $factoryInstance->convertToClassName($cityMode) . 'City'; - - // Get the city instance - $cityInstance = ObjectFactory::createObjectByName($className, array($requestInstance)); - - // Get a registry - $applicationInstance = Registry::getRegistry()->getInstance('app'); - - // Set the app instance - $cityInstance->setApplicationInstance($applicationInstance); - - // Add city-specific filters - $cityInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); - - // Add it to the registry - Registry::getRegistry()->addInstance('city', $cityInstance); - } else { - // Throw an exception here - throw new FactoryRequiredParameterException($factoryInstance, self::EXCEPTION_FACTORY_REQUIRE_PARAMETER); - } - - // Return the instance - return $cityInstance; - } -} - -// [EOF] -?> diff --git a/application/city/main/factories/states/city/class_CityStateFactory.php b/application/city/main/factories/states/city/class_CityStateFactory.php index 8c8fffe..6a7794a 100644 --- a/application/city/main/factories/states/city/class_CityStateFactory.php +++ b/application/city/main/factories/states/city/class_CityStateFactory.php @@ -37,15 +37,17 @@ class CityStateFactory extends ObjectFactory { * given city instance. * * @param $stateName Name of the state - * @param $cityInstance A CityHelper class instance * @return $stateInstance A Stateable class instance */ - public static final function createCityStateInstanceByName ($stateName, CityHelper $cityInstance) { + public static final function createCityStateInstanceByName ($stateName) { // Then construct the class' configuraton entry $className = 'city_' . $stateName . '_state_class'; // Get a class from that configuration entry - $stateInstance = self::createObjectByConfiguredName($className, array($cityInstance)); + $stateInstance = self::createObjectByConfiguredName($className); + + // Get city instance + $cityInstance = Registry::getRegistry()->getInstance('city'); // 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/.htaccess b/application/city/main/filter/bootstrap/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/bootstrap/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/bootstrap/class_CityDaemonBootstrap b/application/city/main/filter/bootstrap/class_CityDaemonBootstrap new file mode 100644 index 0000000..9ac5ede --- /dev/null +++ b/application/city/main/filter/bootstrap/class_CityDaemonBootstrap @@ -0,0 +1,67 @@ + + * @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 CityDaemonBootstrap???Filter extends BaseCityFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createCityDaemonBootstrap???Filter () { + // Get a new instance + $filterInstance = new CityDaemonBootstrap???Filter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If $cityInstance is null (no NullPointerException here) + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get city instance + $cityInstance = Registry::getRegistry()->getInstance('city'); + + // Now do something + $this->partialStub('Please implement this step.'); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/bootstrap/init/.htaccess b/application/city/main/filter/bootstrap/init/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/bootstrap/init/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/bootstrap/init/class_CityDaemonBootstrapInitDaemonFilter.php b/application/city/main/filter/bootstrap/init/class_CityDaemonBootstrapInitDaemonFilter.php new file mode 100644 index 0000000..842f620 --- /dev/null +++ b/application/city/main/filter/bootstrap/init/class_CityDaemonBootstrapInitDaemonFilter.php @@ -0,0 +1,67 @@ + + * @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 CityDaemonBootstrapInitDaemonFilter extends BaseCityFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createCityDaemonBootstrapInitDaemonFilter () { + // Get a new instance + $filterInstance = new CityDaemonBootstrapInitDaemonFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If $cityInstance is null (no NullPointerException here) + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get city instance + $cityInstance = Registry::getRegistry()->getInstance('city'); + + // Now bootstrap the daemon + $cityInstance->bootstrapInitCityDaemon(); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php b/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php index 73a78a0..108b6c5 100644 --- a/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php +++ b/application/city/main/filter/city_daemon/class_CityDaemonInitializationFilter.php @@ -56,16 +56,15 @@ class CityDaemonInitializationFilter extends BaseCityFilter implements Filterabl // Try to instance it by using a factory try { // Get an instance - $cityInstance = CityObjectFactory::createCityInstance($requestInstance, $responseInstance); + $cityInstance = CityDaemonObjectFactory::createCityDaemonInstance($requestInstance, $responseInstance); } catch (ClassNotFoundException $e) { // This exception means, the city mode is invalid. // @TODO Can we rewrite this to app_exit() ? $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: city mode ' . $cityMode . ' is invalid.'); } - // Set the city instance in registry - Registry::getRegistry()->addInstance('city', $cityInstance); - //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-INIT-FILTER[' . __METHOD__ . ':' . __LINE__ . ']: City ' . $cityMode . ' has been added to registry.'); + // Debug message + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-INIT-FILTER[' . __METHOD__ . ':' . __LINE__ . ']: City daemon ' . $cityMode . ' has been added to registry.'); } } diff --git a/application/city/main/filter/city_daemon/class_CityDaemonWelcomeTeaserFilter.php b/application/city/main/filter/city_daemon/class_CityDaemonWelcomeTeaserFilter.php index 936980c..caf11ed 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 = CityObjectFactory::createCityInstance(); + $cityInstance = CityDaemonObjectFactory::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 624d2f2..9a0faed 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 = CityObjectFactory::createCityInstance(); + $cityInstance = CityDaemonObjectFactory::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 542aa27..bf6fff1 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 = CityObjectFactory::createCityInstance(); + $cityInstance = CityDaemonObjectFactory::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 1a1b745..b3956da 100644 --- a/application/city/main/states/city/active/class_CityActiveState.php +++ b/application/city/main/states/city/active/class_CityActiveState.php @@ -38,15 +38,14 @@ class CityActiveState extends BaseCityState implements Stateable { /** * Creates an instance of this class * - * @param $cityInstance An instance of a CityHelper class * @return $stateInstance An instance of a Stateable class */ - public static final function createCityActiveState (CityHelper $cityInstance) { + public static final function createCityActiveState () { // Get new instance $stateInstance = new CityActiveState(); // Get city instance and set 'active' flag - CityObjectFactory::createCityInstance()->enableIsActive(); + CityDaemonObjectFactory::createCityDaemonInstance()->enableIsActive(); // Return the prepared instance return $stateInstance; diff --git a/application/city/main/states/city/class_ b/application/city/main/states/city/class_ index 250c39d..a1f38ca 100644 --- a/application/city/main/states/city/class_ +++ b/application/city/main/states/city/class_ @@ -38,16 +38,12 @@ class City???State extends BaseCityState implements Stateable { /** * Creates an instance of this class * - * @param $cityInstance An instance of a CityHelper class * @return $stateInstance An instance of a Stateable class */ - public final static function createCity???State (CityHelper $cityInstance) { + public final static function createCity???State () { // Get new instance $stateInstance = new City???State(); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE: Has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); - // Return the prepared instance return $stateInstance; } diff --git a/application/city/main/states/city/init/class_CityInitState.php b/application/city/main/states/city/init/class_CityInitState.php index ea9d5b8..e5765b2 100644 --- a/application/city/main/states/city/init/class_CityInitState.php +++ b/application/city/main/states/city/init/class_CityInitState.php @@ -38,16 +38,36 @@ class CityInitState extends BaseCityState implements Stateable { /** * Creates an instance of this class * - * @param $cityInstance An instance of a CityHelper class * @return $stateInstance An instance of a Stateable class */ - public static final function createCityInitState (CityHelper $cityInstance) { + public static final function createCityInitState () { // Get new instance $stateInstance = new CityInitState(); // Return the prepared instance return $stateInstance; } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + */ + public function executeState (Executor $executorInstance) { + // Initialize the daemon + $executorInstance->initializeDaemon($this); + } + + /** + * The daemon has been fully initialized so change the state to 'virgin'. + * + * @return void + */ + public function daemonHasInitialized () { + // Change the state now to 'virgin' + CityStateFactory::createCityStateInstanceByName('virgin'); + } } // [EOF] diff --git a/application/city/main/states/city/virgin/class_CityVirginState.php b/application/city/main/states/city/virgin/class_CityVirginState.php index 9a43b87..a86b73f 100644 --- a/application/city/main/states/city/virgin/class_CityVirginState.php +++ b/application/city/main/states/city/virgin/class_CityVirginState.php @@ -38,10 +38,9 @@ class CityVirginState extends BaseCityState implements Stateable { /** * Creates an instance of this class * - * @param $cityInstance An instance of a CityHelper class * @return $stateInstance An instance of a Stateable class */ - public static final function createCityVirginState (CityHelper $cityInstance) { + public static final function createCityVirginState () { // Get new instance $stateInstance = new CityVirginState(); diff --git a/core b/core index c33ae28..1c6401b 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c33ae28f2865cdcfb330dbbc6e8159b1d17b9ce0 +Subproject commit 1c6401b0efc57aaf1735d05c260be92499cc6e32