* HTML client *
******************************************************************************/
-// CFG: DEFAULT-HTML-COMMAND
-$cfg->setConfigEntry('default_html_command', 'home');
+// CFG: DEFAULT-CITY-HTML-COMMAND
+$cfg->setConfigEntry('default_city_html_command', 'home');
-// CFG: HTML-CMD-HOME-RESOLVER-CLASS
-$cfg->setConfigEntry('html_cmd_home_resolver_class', 'CityHtmlCommandResolver');
+// CFG: CITY-HTML-CMD-HOME-RESOLVER-CLASS
+$cfg->setConfigEntry('city_html_cmd_home_resolver_class', 'CityHtmlCommandResolver');
// CFG: NEWS-HOME-LIMIT
$cfg->setConfigEntry('news_home_limit', 10);
* Console client *
******************************************************************************/
-// CFG: DEFAULT-CONSOLE-COMMAND
-$cfg->setConfigEntry('default_console_command', 'main');
+// CFG: DEFAULT-CITY-CONSOLE-COMMAND
+$cfg->setConfigEntry('default_city_console_command', 'main');
-// CFG: CONSOLE-CMD-MAIN-RESOLVER-CLASS
-$cfg->setConfigEntry('console_cmd_main_resolver_class', 'CityConsoleCommandResolver');
+// CFG: CITY-CONSOLE-CMD-MAIN-RESOLVER-CLASS
+$cfg->setConfigEntry('city_console_cmd_main_resolver_class', 'CityConsoleCommandResolver');
// CFG: CITY-PHP-REQUIREMENTS-FILTER
$cfg->setConfigEntry('city_php_requirements_filter', 'CityPhpRequirementsFilter');
* @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');
// ----------------------- Last step from here ------------------------
// Activate the City. This is ALWAYS the last step in this method
- $this->getStateInstance()->CityIsActivated();
+ $this->getStateInstance()->activateCitySimulation();
// ---------------------- Last step until here ------------------------
}
// Get the controller from the application
$controllerInstance = $applicationInstance->getControllerInstance();
- // Self-announcement task
- $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_task_filter'));
+ // Foo task
+ // @TODO $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('city_foo_task_filter'));
// @TODO Add some filters here
$this->partialStub('Add some filters here.');
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * The default controller with news for e.g. home or news page
+ *
+ * @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 CityConsoleDefaultNewsController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init additional filter chains
+ foreach (array('bootstrap', 'activation','shutdown') as $filterChain) {
+ $this->initFilterChain($filterChain);
+ } // END - foreach
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ */
+ public static final function createCityConsoleDefaultNewsController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new CityConsoleDefaultNewsController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Add news filters to this controller
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter'));
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+
+ /**
+ * Add a bootstrap filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addBootstrapFilter (Filterable $filterInstance) {
+ $this->addFilter('bootstrap', $filterInstance);
+ }
+
+ /**
+ * Executes all bootstrap filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+ }
+
+ /**
+ * Add a city activation filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addActivationFilter (Filterable $filterInstance) {
+ $this->addFilter('activation', $filterInstance);
+ }
+
+ /**
+ * Executes all city activation filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('activation', $requestInstance, $responseInstance);
+ }
+
+ /**
+ * Add a shutdown filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addShutdownFilter (Filterable $filterInstance) {
+ $this->addFilter('shutdown', $filterInstance);
+ }
+
+ /**
+ * Executes all shutdown filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeShutdownFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('shutdown', $requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
parent::__construct(__CLASS__);
// Set prefix to "CityConsole"
- $this->setClassPrefix('CityConsole');
+ $this->setClassPrefix('city_console');
}
/**
// 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]
parent::__construct(__CLASS__);
// Set prefix to "CityHtml"
- $this->setClassPrefix('CityHtml');
+ $this->setClassPrefix('city_html');
}
/**
// 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]
// Call parent constructor
parent::__construct(__CLASS__);
- // Set prefix to 'Console'
- $this->setClassPrefix('Console');
+ // Set prefix to 'city_console'
+ $this->setClassPrefix('city_console');
}
/**
$controllerName = $this->getControllerName();
// Get the command
+ print 'controllerName=' . $controllerName . PHP_EOL;
$controllerInstance = $this->loadController($controllerName);
// And validate it
parent::__construct(__CLASS__);
// Set prefix to 'Html'
- $this->setClassPrefix('Html');
+ $this->setClassPrefix('city_html');
}
/**
-Subproject commit a142fe5eeaaa17a434c80ea103088558157c43bb
+Subproject commit df2fa5cf4b9cef7fa1b0064416cf579793f9038e