From 0ca22a753be1ebb6a069b2ce20e29440cf2c4081 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 24 Mar 2015 17:58:19 +0100 Subject: [PATCH] Added first console-related stuff: - This game can then be launched similar to 'hub' project: php index.php app=city This will launch the game with the currently default simulation city type 'testing' which is for testing purposes (new features are added there first). For now this is the only simulation city type you can choose. More about the architecture will be added later. Signed-off-by: Roland Haeder --- application/city/config.php | 53 +++- application/city/interfaces/helper/.htaccess | 1 + .../city/interfaces/helper/city/.htaccess | 1 + .../helper/city/class_CityHelper.php | 76 ++++++ application/city/main/city/.htaccess | 1 + application/city/main/city/class_ | 98 +++++++ application/city/main/city/class_BaseCity.php | 244 ++++++++++++++++++ application/city/main/city/testing/.htaccess | 1 + .../testing/class_SimulationTestingCity.php | 96 +++++++ application/city/main/class_ | 50 ++++ application/city/main/class_Base | 38 +++ .../city/main/class_BaseCitySystem.php | 139 ++++++++++ .../city/main/commands/console/.htaccess | 1 + .../console/class_CityConsoleMainCommand.php | 137 ++++++++++ application/city/main/factories/.htaccess | 1 + .../city/main/factories/city/.htaccess | 1 + .../city/class_CityObjectFactory.php | 92 +++++++ application/city/main/filter/.htaccess | 1 + application/city/main/filter/city/.htaccess | 1 + application/city/main/filter/city/class_City | 63 +++++ .../city/class_CityInitializationFilter.php | 73 ++++++ .../city/class_CityPhpRequirementsFilter.php | 71 +++++ .../city/class_CityWelcomeTeaserFilter.php | 67 +++++ application/city/main/filter/class_ | 67 +++++ .../city/main/filter/class_BaseCityFilter.php | 111 ++++++++ .../city/main/filter/shutdown/.htaccess | 1 + .../city/main/filter/shutdown/city/.htaccess | 1 + .../filter/shutdown/city/class_CityShutdown | 67 +++++ .../city/class_CityShutdownCityFilter.php | 68 +++++ .../class_CityShutdownTaskHandlerFilter.php | 67 +++++ application/city/main/filter/task/.htaccess | 1 + .../city/main/filter/task/city/.htaccess | 1 + ...class_CityTaskHandlerInitializerFilter.php | 83 ++++++ .../main/resolver/command/console/.htaccess | 1 + .../class_CityConsoleCommandResolver.php | 171 ++++++++++++ .../resolver/controller/console/.htaccess | 1 + .../class_CityConsoleControllerResolver.php | 104 ++++++++ .../main/resolver/controller/html/.htaccess | 1 + .../class_CityHtmlControllerResolver.php | 0 39 files changed, 2047 insertions(+), 4 deletions(-) create mode 100644 application/city/interfaces/helper/.htaccess create mode 100644 application/city/interfaces/helper/city/.htaccess create mode 100644 application/city/interfaces/helper/city/class_CityHelper.php create mode 100644 application/city/main/city/.htaccess create mode 100644 application/city/main/city/class_ create mode 100644 application/city/main/city/class_BaseCity.php create mode 100644 application/city/main/city/testing/.htaccess create mode 100644 application/city/main/city/testing/class_SimulationTestingCity.php create mode 100644 application/city/main/class_ create mode 100644 application/city/main/class_Base create mode 100644 application/city/main/class_BaseCitySystem.php create mode 100644 application/city/main/commands/console/.htaccess create mode 100644 application/city/main/commands/console/class_CityConsoleMainCommand.php create mode 100644 application/city/main/factories/.htaccess create mode 100644 application/city/main/factories/city/.htaccess create mode 100644 application/city/main/factories/city/class_CityObjectFactory.php create mode 100644 application/city/main/filter/.htaccess create mode 100644 application/city/main/filter/city/.htaccess create mode 100644 application/city/main/filter/city/class_City create mode 100644 application/city/main/filter/city/class_CityInitializationFilter.php create mode 100644 application/city/main/filter/city/class_CityPhpRequirementsFilter.php create mode 100644 application/city/main/filter/city/class_CityWelcomeTeaserFilter.php create mode 100644 application/city/main/filter/class_ create mode 100644 application/city/main/filter/class_BaseCityFilter.php create mode 100644 application/city/main/filter/shutdown/.htaccess create mode 100644 application/city/main/filter/shutdown/city/.htaccess create mode 100644 application/city/main/filter/shutdown/city/class_CityShutdown create mode 100644 application/city/main/filter/shutdown/city/class_CityShutdownCityFilter.php create mode 100644 application/city/main/filter/shutdown/city/class_CityShutdownTaskHandlerFilter.php create mode 100644 application/city/main/filter/task/.htaccess create mode 100644 application/city/main/filter/task/city/.htaccess create mode 100644 application/city/main/filter/task/city/class_CityTaskHandlerInitializerFilter.php create mode 100644 application/city/main/resolver/command/console/.htaccess create mode 100644 application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php create mode 100644 application/city/main/resolver/controller/console/.htaccess create mode 100644 application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php create mode 100644 application/city/main/resolver/controller/html/.htaccess rename application/city/main/resolver/controller/{ => html}/class_CityHtmlControllerResolver.php (100%) diff --git a/application/city/config.php b/application/city/config.php index a221c83..293d044 100644 --- a/application/city/config.php +++ b/application/city/config.php @@ -24,11 +24,12 @@ // Some hub-specific configuration like port hostname where we will listen, etc. $cfg = FrameworkConfiguration::getSelfInstance(); -// CFG: DEFAULT-HTML-COMMAND -$cfg->setConfigEntry('default_html_command', 'home'); +/****************************************************************************** + * General * + ******************************************************************************/ -// CFG: HTML-CMD-HOME-RESOLVER-CLASS -$cfg->setConfigEntry('html_cmd_home_resolver_class', 'CityHtmlCommandResolver'); +// CFG: CITY-DEFAULT-MODE (more is coming) +$cfg->setConfigEntry('city_default_mode', 'testing'); // CFG: NEWS-DOWNLOAD-FILTER $cfg->setConfigEntry('news_download_filter', 'NewsDownloadFilter'); @@ -39,6 +40,19 @@ $cfg->setConfigEntry('news_process_filter', 'NewsProcessFilter'); // CFG: NEWS-READER-CLASS $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader'); +// CFG: CITY-INFO-DB-WRAPPER-CLASS +$cfg->setConfigEntry('city_info_db_wrapper_class', 'CityInformationDatabaseWrapper'); + +/****************************************************************************** + * HTML client * + ******************************************************************************/ + +// CFG: DEFAULT-HTML-COMMAND +$cfg->setConfigEntry('default_html_command', 'home'); + +// CFG: HTML-CMD-HOME-RESOLVER-CLASS +$cfg->setConfigEntry('html_cmd_home_resolver_class', 'CityHtmlCommandResolver'); + // CFG: NEWS-HOME-LIMIT $cfg->setConfigEntry('news_home_limit', 10); @@ -51,5 +65,36 @@ $cfg->setConfigEntry('menu_template_class', 'MenuTemplateEngine'); // CFG: MENU-TEMPLATE-EXTENSION $cfg->setConfigEntry('menu_template_extension', '.xml'); +/****************************************************************************** + * Console client * + ******************************************************************************/ + +// CFG: DEFAULT-CONSOLE-COMMAND +$cfg->setConfigEntry('default_console_command', 'main'); + +// CFG: CONSOLE-CMD-MAIN-RESOLVER-CLASS +$cfg->setConfigEntry('console_cmd_main_resolver_class', 'CityConsoleCommandResolver'); + +// CFG: CITY-PHP-REQUIREMENTS-FILTER +$cfg->setConfigEntry('city_php_requirements_filter', 'CityPhpRequirementsFilter'); + +// CFG: CITY-INITIALIZER-FILTER +$cfg->setConfigEntry('city_initializer_filter', 'CityInitializationFilter'); + +// CFG: CITY-ACTIVATION-TASK-HANDLER-INITIALIZER-FILTER +$cfg->setConfigEntry('city_activation_task_handler_initializer_filter', 'CityTaskHandlerInitializerFilter'); + +// CFG: CITY-WELCOME-TEASER-FILTER +$cfg->setConfigEntry('city_welcome_teaser_filter', 'CityWelcomeTeaserFilter'); + +// CFG: CITY-SHUTDOWN-TASK-HANDLER-FILTER +$cfg->setConfigEntry('city_shutdown_task_handler_filter', 'CityShutdownTaskHandlerFilter'); + +// CFG: CITY-SHUTDOWN-CITY-FILTER +$cfg->setConfigEntry('city_shutdown_city_filter', 'CityShutdownCityFilter'); + +// CFG: NEWS-MAIN-LIMIT +$cfg->setConfigEntry('news_main_limit', 5); + // [EOF] ?> diff --git a/application/city/interfaces/helper/.htaccess b/application/city/interfaces/helper/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/helper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/helper/city/.htaccess b/application/city/interfaces/helper/city/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/interfaces/helper/city/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/interfaces/helper/city/class_CityHelper.php b/application/city/interfaces/helper/city/class_CityHelper.php new file mode 100644 index 0000000..7f3e0e3 --- /dev/null +++ b/application/city/interfaces/helper/city/class_CityHelper.php @@ -0,0 +1,76 @@ + + * @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 . + */ +interface CityHelper extends Helper, AddableCriteria { + /** + * Method to "bootstrap" the city. This step does also apply provided + * command-line arguments stored in the request instance. You should now + * get it from calling $this->getRequestInstance(). + * + * @return void + */ + function doBootstrapping (); + + /** + * Outputs the console teaser. This should only be executed on startup or + * full restarts. This method generates some space around the teaser. + * + * @return void + */ + function outputConsoleTeaser (); + + /** + * Add some city-specific filters + * + * @return void + */ + function addExtraCityFilters (); + + /** + * Activates the hub by doing some final preparation and setting + * $hubIsActive to TRUE. + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + function activateCity (Requestable $requestInstance, Responseable $responseInstance); + + /** + * Updates/refreshes city data (e.g. state). + * + * @return void + */ + function updateCityData (); + + /** + * Adds extra tasks to the given handler for this city + * + * @param $handlerInstance An instance of a HandleableTask class + * @return void + */ + function addExtraTasks (HandleableTask $handlerInstance); +} + +// [EOF] +?> diff --git a/application/city/main/city/.htaccess b/application/city/main/city/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/city/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/city/class_ b/application/city/main/city/class_ new file mode 100644 index 0000000..915a3e8 --- /dev/null +++ b/application/city/main/city/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 Hub???Node extends BaseHubNode implements NodeHelper, 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 createHub???Node (Requestable $requestInstance) { + // Get a new instance + $nodeInstance = new Hub???Node(); + + // 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 addExtraHubFilters () { + // 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 new file mode 100644 index 0000000..fb83ddb --- /dev/null +++ b/application/city/main/city/class_BaseCity.php @@ -0,0 +1,244 @@ + + * @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') . ' mode active'); + self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 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_NR , 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) { + // Checks whether a listener is still active and shuts it down if one + // is still listening. + if (($this->determineIfListenerIsActive()) && ($this->isCityActive())) { + // Shutdown them down before they can hurt anything + $this->shutdownListenerPool(); + } // END - if + + // Get the controller here + $controllerInstance = Registry::getRegistry()->getInstance('controller'); + + // Run all filters for the City activation + $controllerInstance->executeActivationFilters($requestInstance, $responseInstance); + + // ----------------------- Last step from here ------------------------ + // Activate the City. This is ALWAYS the last step in this method + $this->getStateInstance()->CityIsActivated(); + // ---------------------- 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 (CityDistributedHashTableDatabaseWrapper::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 new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/city/testing/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/city/testing/class_SimulationTestingCity.php b/application/city/main/city/testing/class_SimulationTestingCity.php new file mode 100644 index 0000000..4b8d231 --- /dev/null +++ b/application/city/main/city/testing/class_SimulationTestingCity.php @@ -0,0 +1,96 @@ + + * @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(); + + // Self-announcement task + $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_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/class_ b/application/city/main/class_ new file mode 100644 index 0000000..2dea4bd --- /dev/null +++ b/application/city/main/class_ @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub 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 ??? extends BaseFrameworkSystem implements === { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $!!!Instance An instance of a === class + */ + public final static function create??? () { + // Get new instance + $!!!Instance = new ???(); + + // Return the prepared instance + return $!!!Instance; + } +} + +// [EOF] +?> diff --git a/application/city/main/class_Base b/application/city/main/class_Base new file mode 100644 index 0000000..da87388 --- /dev/null +++ b/application/city/main/class_Base @@ -0,0 +1,38 @@ + + * @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 Base??? extends BaseCitySystem { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/city/main/class_BaseCitySystem.php b/application/city/main/class_BaseCitySystem.php new file mode 100644 index 0000000..52e5b4c --- /dev/null +++ b/application/city/main/class_BaseCitySystem.php @@ -0,0 +1,139 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 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 BaseCitySystem extends BaseFrameworkSystem { + // Exception codes + const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x900; + const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x901; + + // Message status codes + const MESSAGE_STATUS_CODE_OKAY = 'OKAY'; + + /** + * An instance of a city + */ + private $cityInstance = NULL; + + /** + * An instance of a communicator + */ + private $stateInstance = NULL; + + /** + * An instance of a communicator + */ + private $communicatorInstance = 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; + } + + /** + * Getter for communicator instance + * + * @return $communicatorInstance An instance of a Communicator class + */ + public final function getCommunicatorInstance () { + return $this->communicatorInstance; + } + + /** + * Setter for communicator instance + * + * @param $communicatorInstance An instance of a Communicator class + * @return void + */ + protected final function setCommunicatorInstance (Communicator $communicatorInstance) { + $this->communicatorInstance = $communicatorInstance; + } + + /** + * Setter for state instance + * + * @param $stateInstance A Stateable instance + * @return void + */ + public final function setStateInstance (Stateable $stateInstance) { + $this->stateInstance = $stateInstance; + } + + /** + * Getter for state instance + * + * @return $stateInstance A Stateable instance + */ + public final function getStateInstance () { + return $this->stateInstance; + } + + /** + * "Getter" for a printable state name + * + * @return $stateName Name of the city's state in a printable format + */ + public final function getPrintableState () { + // Default is 'null' + $stateName = 'null'; + + // Get the state instance + $stateInstance = $this->getStateInstance(); + + // Is it an instance of Stateable? + if ($stateInstance instanceof Stateable) { + // Then use that state name + $stateName = $stateInstance->getStateName(); + } // END - if + + // Return result + return $stateName; + } +} + +// [EOF] +?> diff --git a/application/city/main/commands/console/.htaccess b/application/city/main/commands/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/commands/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/commands/console/class_CityConsoleMainCommand.php b/application/city/main/commands/console/class_CityConsoleMainCommand.php new file mode 100644 index 0000000..ea595f7 --- /dev/null +++ b/application/city/main/commands/console/class_CityConsoleMainCommand.php @@ -0,0 +1,137 @@ + + * @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 CityConsoleMainCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public static final function createCityConsoleMainCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new CityConsoleMainCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given command 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 + * @todo ~10% done? + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a registry and the application instance from it + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + /* + * ----------------------- Bootstrapping phase ------------------------ + * Try to bootstrap the city and pass the request instance to it for + * extra arguments which mostly override config entries or enable special + * features within the hub (none is ready at this development stage) + */ + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); + + // Get city instance + $cityInstance = CityObjectFactory::createCityInstance(); + + // Add some city-specific filters, e.g. announcement + $cityInstance->addExtraCityFilters(); + + /* + * -------------------------- City activation -------------------------- + * Activates the city by doing some final preparation steps and setting + * the attribute $hubIsActive to TRUE. + */ + $cityInstance->activateCity($requestInstance, $responseInstance); + + // Get task handler instance + $handlerInstance = Registry::getRegistry()->getInstance('task_handler'); + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---'); + + /* + * ----------------------------- Main loop ---------------------------- + * This is the main loop. Queried calls should come back here very fast + * so the whole application runs on nice speed. This while-loop goes + * until the hub is no longer active or all tasks are killed. + */ + while (($cityInstance->isCityActive()) && ($handlerInstance->hasTasksLeft())) { + // Handle all tasks here + $handlerInstance->handleTasks(); + } // END - while + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---'); + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + * @todo 0% done + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Add pre filters + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('city_php_requirements_filter')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('city_initializer_filter')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('city_welcome_teaser_filter')); + + // Add bootstrap filters + //$controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('city_bootstrap_generate_cityid_filter')); + + // Add city activation filters + $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('city_activation_task_handler_initializer_filter')); + + // Add shutdown filters + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('city_shutdown_task_handler_filter')); + + // This is the last generic shutdown filter + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('city_shutdown_city_filter')); + } +} + +// [EOF] +?> diff --git a/application/city/main/factories/.htaccess b/application/city/main/factories/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/factories/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/factories/city/.htaccess b/application/city/main/factories/city/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/factories/city/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/factories/city/class_CityObjectFactory.php b/application/city/main/factories/city/class_CityObjectFactory.php new file mode 100644 index 0000000..a4be719 --- /dev/null +++ b/application/city/main/factories/city/class_CityObjectFactory.php @@ -0,0 +1,92 @@ + + * @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/filter/.htaccess b/application/city/main/filter/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/city/.htaccess b/application/city/main/filter/city/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/city/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/city/class_City b/application/city/main/filter/city/class_City new file mode 100644 index 0000000..75aa344 --- /dev/null +++ b/application/city/main/filter/city/class_City @@ -0,0 +1,63 @@ + + * @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 City???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 createCity???Filter () { + // Get a new instance + $filterInstance = new City???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 + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub('Please implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/city/class_CityInitializationFilter.php b/application/city/main/filter/city/class_CityInitializationFilter.php new file mode 100644 index 0000000..2cb21e3 --- /dev/null +++ b/application/city/main/filter/city/class_CityInitializationFilter.php @@ -0,0 +1,73 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 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 CityInitializationFilter 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 static final function createCityInitializationFilter () { + // Get a new instance + $filterInstance = new CityInitializationFilter(); + + // 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Try to instance it by using a factory + try { + // Get an instance + $cityInstance = CityObjectFactory::createCityInstance($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.'); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/city/class_CityPhpRequirementsFilter.php b/application/city/main/filter/city/class_CityPhpRequirementsFilter.php new file mode 100644 index 0000000..307de6f --- /dev/null +++ b/application/city/main/filter/city/class_CityPhpRequirementsFilter.php @@ -0,0 +1,71 @@ + + * @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 CityPhpRequirementsFilter 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 static final function createCityPhpRequirementsFilter () { + // Get a new instance + $filterInstance = new CityPhpRequirementsFilter(); + + // 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 a required PHP function is not available + * @todo Add more test and try to add an extra message to the thrown exception + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // By default, the requirement check is passed and zero checks are failed + $checkPassed = TRUE; + $checksFailed = 0; + + // Are all tests passed? + if ($checkPassed === FALSE) { + // Throw an exception + throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); + } // END - if + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/city/class_CityWelcomeTeaserFilter.php b/application/city/main/filter/city/class_CityWelcomeTeaserFilter.php new file mode 100644 index 0000000..8fc2917 --- /dev/null +++ b/application/city/main/filter/city/class_CityWelcomeTeaserFilter.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.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 CityWelcomeTeaserFilter 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 static final function createCityWelcomeTeaserFilter () { + // Get a new instance + $filterInstance = new CityWelcomeTeaserFilter(); + + // 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 Handle over the $responseInstance to outputConsoleTeaser() + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get city instance + $cityInstance = CityObjectFactory::createCityInstance(); + + // Now output the teaser + $cityInstance->outputConsoleTeaser(); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/class_ b/application/city/main/filter/class_ new file mode 100644 index 0000000..68dd7c7 --- /dev/null +++ b/application/city/main/filter/class_ @@ -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 City!!!???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 createCity!!!???Filter () { + // Get a new instance + $filterInstance = new City!!!???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/class_BaseCityFilter.php b/application/city/main/filter/class_BaseCityFilter.php new file mode 100644 index 0000000..e9017c9 --- /dev/null +++ b/application/city/main/filter/class_BaseCityFilter.php @@ -0,0 +1,111 @@ + + * @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 BaseCityFilter extends BaseFilter { + /** + * Array with all data XML nodes (which hold the actual data) and their values + */ + protected $dataXmlNodes = array(); + + /** + * Protected constructor + * + * @param $className Real name of class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Processes the given raw message content. The method renderXmlContent + * may throw (not the method itself) several exceptions: + * + * InvalidXmlNodeException - If an invalid XML node has been found (e.g. + * wrong/out-dated template used) + * XmlNodeMismatchException - Again might be caused by invalid XML node + * usage + * XmlParserException - If the XML message is damaged or not + * well-formed + * + * @param $messageType Type of message + * @param $messageContent Raw message content + * @param $packageInstance An instance of a Receivable class + * @return void + * @todo Exceptions from renderXmlContent() are currently unhandled + */ + protected function genericProcessMessage ($messageType, $messageContent, Receivable $packageInstance) { + // Get a template instance from the factory + $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('city_' . $messageType . '_template_class'); + + // And render the XML content (aka message) + $templateInstance->renderXmlContent($messageContent); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Handling ' . strlen($messageContent) . ' bytes: ' . $messageContent); + + /* + * The template system now stores all required data as 'general' + * variables, so simply get them. If there is an invalid XML node + * inside the message, the above method call will cause exceptions. + */ + foreach ($this->dataXmlNodes as $key => $dummy) { + // Call it + $value = $templateInstance->readXmlData($key); + + /* + * If value is NULL, a variable hasn't been found. This could mean + * that *this* node is running an out-dated software or the other + * peer is using an out-dated $messageType.xml template. + */ + if (is_null($value)) { + // Output a warning + self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Found not fully supported variable ' . $key . ' - skipping.'); + + // Skip this part, don't write NULLs to the array + continue; + } // END - if + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: key=' . $key . ',value=' . $value); + + // Set it now + $this->dataXmlNodes[$key] = $value; + } // END - foreach + + // Construct an array for pushing it on next stack + $messageArray = array( + // Message data itself + NetworkPackage::MESSAGE_ARRAY_DATA => $this->dataXmlNodes, + // Message type (which is $messageType) + NetworkPackage::MESSAGE_ARRAY_TYPE => $messageType + ); + + // Push the processed message back on stack + $packageInstance->getStackInstance()->pushNamed(NetworkPackage::STACKER_NAME_PROCESSED_MESSAGE, $messageArray); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/shutdown/.htaccess b/application/city/main/filter/shutdown/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/shutdown/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/shutdown/city/.htaccess b/application/city/main/filter/shutdown/city/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/shutdown/city/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/shutdown/city/class_CityShutdown b/application/city/main/filter/shutdown/city/class_CityShutdown new file mode 100644 index 0000000..60201db --- /dev/null +++ b/application/city/main/filter/shutdown/city/class_CityShutdown @@ -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 CityShutdown???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 createCityShutdown???Filter () { + // Get a new instance + $filterInstance = new CityShutdown???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/shutdown/city/class_CityShutdownCityFilter.php b/application/city/main/filter/shutdown/city/class_CityShutdownCityFilter.php new file mode 100644 index 0000000..0b48c5a --- /dev/null +++ b/application/city/main/filter/shutdown/city/class_CityShutdownCityFilter.php @@ -0,0 +1,68 @@ + + * @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 CityShutdownCityFilter 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 static final function createCityShutdownCityFilter () { + // Get a new instance + $filterInstance = new CityShutdownCityFilter(); + + // 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 please) + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get city instance + $cityInstance = CityObjectFactory::createCityInstance(); + + // Shutdown the city. This should be the last line + $cityInstance->doShutdown(); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/shutdown/city/class_CityShutdownTaskHandlerFilter.php b/application/city/main/filter/shutdown/city/class_CityShutdownTaskHandlerFilter.php new file mode 100644 index 0000000..18dfe61 --- /dev/null +++ b/application/city/main/filter/shutdown/city/class_CityShutdownTaskHandlerFilter.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.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 CityShutdownTaskHandlerFilter 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 static final function createCityShutdownTaskHandlerFilter () { + // Get a new instance + $filterInstance = new CityShutdownTaskHandlerFilter(); + + // 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 task handler instance + $handlerInstance = Registry::getRegistry()->getInstance('task_handler'); + + // Shutdown the task manager and all its registered tasks + $handlerInstance->doShutdown(); + } +} + +// [EOF] +?> diff --git a/application/city/main/filter/task/.htaccess b/application/city/main/filter/task/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/task/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/task/city/.htaccess b/application/city/main/filter/task/city/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/filter/task/city/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/filter/task/city/class_CityTaskHandlerInitializerFilter.php b/application/city/main/filter/task/city/class_CityTaskHandlerInitializerFilter.php new file mode 100644 index 0000000..384421a --- /dev/null +++ b/application/city/main/filter/task/city/class_CityTaskHandlerInitializerFilter.php @@ -0,0 +1,83 @@ + + * @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 CityTaskHandlerInitializerFilter 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 static final function createCityTaskHandlerInitializerFilter () { + // Get a new instance + $filterInstance = new CityTaskHandlerInitializerFilter(); + + // 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 the filter chain needs to be interrupted + * @todo Add more tasks + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get city instance + $cityInstance = CityObjectFactory::createCityInstance(); + + // Get a new task handler instance + $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class'); + + // Put the task handler in registry + Registry::getRegistry()->addInstance('task_handler', $handlerInstance); + + // Prepare a package-tags initialization task for the listeners + //$taskInstance = ObjectFactory::createObjectByConfiguredName('city_package_tags_init_task_class'); + + // Register it + //$handlerInstance->registerTask('package_tags_init', $taskInstance); + + /* + * Allow extra city-depending tasks, e.g. the bootstrapper city needs + * booting its DHT. DHTs are decentralized and are working on + * peer-to-peer basis. + */ + $cityInstance->addExtraTasks($handlerInstance); + } +} + +// [EOF] +?> diff --git a/application/city/main/resolver/command/console/.htaccess b/application/city/main/resolver/command/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/resolver/command/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php b/application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php new file mode 100644 index 0000000..00b71d0 --- /dev/null +++ b/application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php @@ -0,0 +1,171 @@ + + * @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 CityConsoleCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "CityConsole" + $this->setClassPrefix('CityConsole'); + } + + /** + * Creates an instance of a CityConsole command resolver with a given default command + * + * @param $commandName The default command we shall execute + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared command resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidCommandException Thrown if default command is invalid + */ + public static final function createCityConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new CityConsoleCommandResolver(); + + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isCommandValid($commandName) === FALSE) { + // Invalid command found + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Returns an command instance for a given request class or null if + * it was not found + * + * @param $requestInstance An instance of a request class + * @return $commandInstance An instance of the resolved command + * @throws InvalidCommandException Thrown if $commandName is + * invalid + * @throws InvalidCommandInstanceException Thrown if $commandInstance + * is an invalid instance + */ + public function resolveCommandByRequest (Requestable $requestInstance) { + // Init variables + $commandName = ''; + $commandInstance = NULL; + + // This goes fine so let's resolve the command + $commandName = $requestInstance->getRequestElement('command'); + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_html_command'); + + // Check if command is valid + if ($this->isCommandValid($commandName) === FALSE) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } // END - if + + // Get the command + $commandInstance = $this->loadCommand($commandName); + + // And validate it + if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { + // This command has an invalid instance! + throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } // END - if + + // Set last command + $this->setResolvedInstance($commandInstance); + + // Return the resolved command instance + return $commandInstance; + } + + /** + * Resolves the command by its direct name and returns an instance of its class + * + * @param $commandName The direct command name we shall resolve + * @return $commandInstance An instance of the command class + * @throws InvalidCommandException Thrown if $commandName is invalid + */ + public function resolveCommand ($commandName) { + // Initiate the instance variable + $commandInstance = NULL; + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_html_command'); + + // Check if command is valid + if ($this->isCommandValid($commandName) === FALSE) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Get the command + $commandInstance = $this->loadCommand($commandName); + + // Return the instance + return $commandInstance; + } + + /** + * "Loads" a given command and instances it if not yet cached + * + * @param $commandName A command name we shall look for + * @return $commandInstance A loaded command instance + * @throws InvalidCommandException Thrown if even the default + * command class is missing (bad!) + */ + private function loadCommand ($commandName) { + // Init command instance + $commandInstance = NULL; + + // Create class name + $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command'; + + // Create command class name + $this->setClassName($className); + + // Is this class loaded? + if (!class_exists($this->getClassName())) { + // Class not found, so throw an exception + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } // END - if + + // Initiate the command + $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); + + // Return the result + return $commandInstance; + } +} + +// [EOF] +?> diff --git a/application/city/main/resolver/controller/console/.htaccess b/application/city/main/resolver/controller/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/resolver/controller/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php b/application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php new file mode 100644 index 0000000..0553ffd --- /dev/null +++ b/application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php @@ -0,0 +1,104 @@ + + * @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 CityConsoleControllerResolver extends BaseControllerResolver implements ControllerResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to 'Console' + $this->setClassPrefix('Console'); + } + + /** + * Creates an instance of a resolver class with a given command + * + * @param $controllerName The controller we shall resolve + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared controller resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidControllerException Thrown if default controller is invalid + */ + public static final function createCityConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new CityConsoleControllerResolver(); + + // Is the variable $controllerName set and the command is valid? + if (empty($controllerName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) { + // Invalid command found + throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + + // Set command name + $resolverInstance->setControllerName($controllerName); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Resolves the default controller of the given command + * + * @return $controllerInstance A controller instance for the default + * command + * @throws InvalidControllerInstanceException Thrown if $controllerInstance + * is invalid + */ + public function resolveController () { + // Init variables + $controllerName = ''; + $controllerInstance = NULL; + + // Get the command name + $controllerName = $this->getControllerName(); + + // Get the command + $controllerInstance = $this->loadController($controllerName); + + // And validate it + if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { + // This command has an invalid instance! + throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } // END - if + + // Set last controller + $this->setResolvedInstance($controllerInstance); + + // Return the maybe resolved instance + return $controllerInstance; + } +} + +// [EOF] +?> diff --git a/application/city/main/resolver/controller/html/.htaccess b/application/city/main/resolver/controller/html/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/resolver/controller/html/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/resolver/controller/class_CityHtmlControllerResolver.php b/application/city/main/resolver/controller/html/class_CityHtmlControllerResolver.php similarity index 100% rename from application/city/main/resolver/controller/class_CityHtmlControllerResolver.php rename to application/city/main/resolver/controller/html/class_CityHtmlControllerResolver.php -- 2.39.5