// 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');
// 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);
// 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]
?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for "city-helper" classes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-node class for the '???' mode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A general City class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A city class for testing purposes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A ???
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A general ??? class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A general city (simulation) system class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A command for the 'main' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for cities
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for citys
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A Initialization filter for cities
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A PhpRequirements filter for cities
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A welcome-teaser filter for the console
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? filter for !!!
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for hub project
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for shutting down the city.
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A ShutdownCity filter for shutting down the city. This filter should be the
+ * last one in 'shutdown' chain so the hub is shutted down at the very end of
+ * its life... R.I.P. little hub...
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+<?php
+/**
+ * A TaskHandler filter for shutting down the city.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskHandlerInitializer filter for hubs
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A command resolver for console commands
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
+++ /dev/null
-<?php
-/**
- * A resolver for resolving controllers locally
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-class CityHtmlControllerResolver extends BaseControllerResolver implements ControllerResolver {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set prefix to 'Html'
- $this->setClassPrefix('Html');
- }
-
- /**
- * 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 createCityHtmlControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
- // Create the new instance
- $resolverInstance = new CityHtmlControllerResolver();
-
- // 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]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A resolver for resolving controllers locally
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A resolver for resolving controllers locally
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+class CityHtmlControllerResolver extends BaseControllerResolver implements ControllerResolver {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to 'Html'
+ $this->setClassPrefix('Html');
+ }
+
+ /**
+ * 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 createCityHtmlControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
+ // Create the new instance
+ $resolverInstance = new CityHtmlControllerResolver();
+
+ // 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]
+?>