From 40a6659c97f177fe6e5580a4e7bdee9a1bc1f0e4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 24 Mar 2015 20:58:36 +0100 Subject: [PATCH] Moved more methods to 'core' as they are now more generalized + fixed config entries +++. Signed-off-by: Roland Haeder --- application/city/config.php | 16 +- application/city/main/city/class_BaseCity.php | 9 +- .../testing/class_SimulationTestingCity.php | 4 +- application/city/main/controller/.htaccess | 1 + .../city/main/controller/console/.htaccess | 1 + ...class_CityConsoleDefaultNewsController.php | 156 ++++++++++++++++++ .../class_CityConsoleCommandResolver.php | 104 +----------- .../html/class_CityHtmlCommandResolver.php | 104 +----------- .../class_CityConsoleControllerResolver.php | 5 +- .../html/class_CityHtmlControllerResolver.php | 2 +- core | 2 +- 11 files changed, 176 insertions(+), 228 deletions(-) create mode 100644 application/city/main/controller/.htaccess create mode 100644 application/city/main/controller/console/.htaccess create mode 100644 application/city/main/controller/console/class_CityConsoleDefaultNewsController.php diff --git a/application/city/config.php b/application/city/config.php index 0a5c1b6..8a6298e 100644 --- a/application/city/config.php +++ b/application/city/config.php @@ -50,11 +50,11 @@ $cfg->setConfigEntry('city_init_state_class', 'CityInitState'); * 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); @@ -72,11 +72,11 @@ $cfg->setConfigEntry('menu_template_extension', '.xml'); * 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'); diff --git a/application/city/main/city/class_BaseCity.php b/application/city/main/city/class_BaseCity.php index fb83ddb..e6baded 100644 --- a/application/city/main/city/class_BaseCity.php +++ b/application/city/main/city/class_BaseCity.php @@ -169,13 +169,6 @@ class BaseCity extends BaseCitySystem implements Updateable, AddableCriteria { * @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'); @@ -184,7 +177,7 @@ class BaseCity extends BaseCitySystem implements Updateable, AddableCriteria { // ----------------------- 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 ------------------------ } diff --git a/application/city/main/city/testing/class_SimulationTestingCity.php b/application/city/main/city/testing/class_SimulationTestingCity.php index 4b8d231..798e3de 100644 --- a/application/city/main/city/testing/class_SimulationTestingCity.php +++ b/application/city/main/city/testing/class_SimulationTestingCity.php @@ -73,8 +73,8 @@ class SimulationTestingCity extends BaseCity implements CityHelper, Registerable // 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.'); diff --git a/application/city/main/controller/.htaccess b/application/city/main/controller/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/controller/console/.htaccess b/application/city/main/controller/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/city/main/controller/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/city/main/controller/console/class_CityConsoleDefaultNewsController.php b/application/city/main/controller/console/class_CityConsoleDefaultNewsController.php new file mode 100644 index 0000000..95e6462 --- /dev/null +++ b/application/city/main/controller/console/class_CityConsoleDefaultNewsController.php @@ -0,0 +1,156 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2015 City Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class 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] +?> diff --git a/application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php b/application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php index 00b71d0..1eb5af2 100644 --- a/application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php +++ b/application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php @@ -32,7 +32,7 @@ class CityConsoleCommandResolver extends BaseCommandResolver implements CommandR parent::__construct(__CLASS__); // Set prefix to "CityConsole" - $this->setClassPrefix('CityConsole'); + $this->setClassPrefix('city_console'); } /** @@ -63,108 +63,6 @@ class CityConsoleCommandResolver extends BaseCommandResolver implements CommandR // Return the prepared instance return $resolverInstance; } - - /** - * Returns an command instance for a given request class or null if - * it was not found - * - * @param $requestInstance An instance of a request class - * @return $commandInstance An instance of the resolved command - * @throws InvalidCommandException Thrown if $commandName is - * invalid - * @throws InvalidCommandInstanceException Thrown if $commandInstance - * is an invalid instance - */ - public function resolveCommandByRequest (Requestable $requestInstance) { - // Init variables - $commandName = ''; - $commandInstance = NULL; - - // This goes fine so let's resolve the command - $commandName = $requestInstance->getRequestElement('command'); - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_html_command'); - - // Check if command is valid - if ($this->isCommandValid($commandName) === FALSE) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if - - // Get the command - $commandInstance = $this->loadCommand($commandName); - - // And validate it - if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { - // This command has an invalid instance! - throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if - - // Set last command - $this->setResolvedInstance($commandInstance); - - // Return the resolved command instance - return $commandInstance; - } - - /** - * Resolves the command by its direct name and returns an instance of its class - * - * @param $commandName The direct command name we shall resolve - * @return $commandInstance An instance of the command class - * @throws InvalidCommandException Thrown if $commandName is invalid - */ - public function resolveCommand ($commandName) { - // Initiate the instance variable - $commandInstance = NULL; - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_html_command'); - - // Check if command is valid - if ($this->isCommandValid($commandName) === FALSE) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Get the command - $commandInstance = $this->loadCommand($commandName); - - // Return the instance - return $commandInstance; - } - - /** - * "Loads" a given command and instances it if not yet cached - * - * @param $commandName A command name we shall look for - * @return $commandInstance A loaded command instance - * @throws InvalidCommandException Thrown if even the default - * command class is missing (bad!) - */ - private function loadCommand ($commandName) { - // Init command instance - $commandInstance = NULL; - - // Create class name - $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command'; - - // Create command class name - $this->setClassName($className); - - // Is this class loaded? - if (!class_exists($this->getClassName())) { - // Class not found, so throw an exception - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if - - // Initiate the command - $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); - - // Return the result - return $commandInstance; - } } // [EOF] diff --git a/application/city/main/resolver/command/html/class_CityHtmlCommandResolver.php b/application/city/main/resolver/command/html/class_CityHtmlCommandResolver.php index 5dd265c..af3d122 100644 --- a/application/city/main/resolver/command/html/class_CityHtmlCommandResolver.php +++ b/application/city/main/resolver/command/html/class_CityHtmlCommandResolver.php @@ -32,7 +32,7 @@ class CityHtmlCommandResolver extends BaseCommandResolver implements CommandReso parent::__construct(__CLASS__); // Set prefix to "CityHtml" - $this->setClassPrefix('CityHtml'); + $this->setClassPrefix('city_html'); } /** @@ -63,108 +63,6 @@ class CityHtmlCommandResolver extends BaseCommandResolver implements CommandReso // Return the prepared instance return $resolverInstance; } - - /** - * Returns an command instance for a given request class or null if - * it was not found - * - * @param $requestInstance An instance of a request class - * @return $commandInstance An instance of the resolved command - * @throws InvalidCommandException Thrown if $commandName is - * invalid - * @throws InvalidCommandInstanceException Thrown if $commandInstance - * is an invalid instance - */ - public function resolveCommandByRequest (Requestable $requestInstance) { - // Init variables - $commandName = ''; - $commandInstance = NULL; - - // This goes fine so let's resolve the command - $commandName = $requestInstance->getRequestElement('command'); - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_html_command'); - - // Check if command is valid - if ($this->isCommandValid($commandName) === FALSE) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if - - // Get the command - $commandInstance = $this->loadCommand($commandName); - - // And validate it - if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { - // This command has an invalid instance! - throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if - - // Set last command - $this->setResolvedInstance($commandInstance); - - // Return the resolved command instance - return $commandInstance; - } - - /** - * Resolves the command by its direct name and returns an instance of its class - * - * @param $commandName The direct command name we shall resolve - * @return $commandInstance An instance of the command class - * @throws InvalidCommandException Thrown if $commandName is invalid - */ - public function resolveCommand ($commandName) { - // Initiate the instance variable - $commandInstance = NULL; - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_html_command'); - - // Check if command is valid - if ($this->isCommandValid($commandName) === FALSE) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Get the command - $commandInstance = $this->loadCommand($commandName); - - // Return the instance - return $commandInstance; - } - - /** - * "Loads" a given command and instances it if not yet cached - * - * @param $commandName A command name we shall look for - * @return $commandInstance A loaded command instance - * @throws InvalidCommandException Thrown if even the default - * command class is missing (bad!) - */ - private function loadCommand ($commandName) { - // Init command instance - $commandInstance = NULL; - - // Create class name - $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command'; - - // Create command class name - $this->setClassName($className); - - // Is this class loaded? - if (!class_exists($this->getClassName())) { - // Class not found, so throw an exception - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if - - // Initiate the command - $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); - - // Return the result - return $commandInstance; - } } // [EOF] diff --git a/application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php b/application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php index 0553ffd..4735d52 100644 --- a/application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php +++ b/application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php @@ -31,8 +31,8 @@ class CityConsoleControllerResolver extends BaseControllerResolver implements Co // Call parent constructor parent::__construct(__CLASS__); - // Set prefix to 'Console' - $this->setClassPrefix('Console'); + // Set prefix to 'city_console' + $this->setClassPrefix('city_console'); } /** @@ -84,6 +84,7 @@ class CityConsoleControllerResolver extends BaseControllerResolver implements Co $controllerName = $this->getControllerName(); // Get the command + print 'controllerName=' . $controllerName . PHP_EOL; $controllerInstance = $this->loadController($controllerName); // And validate it diff --git a/application/city/main/resolver/controller/html/class_CityHtmlControllerResolver.php b/application/city/main/resolver/controller/html/class_CityHtmlControllerResolver.php index 96df86b..d390856 100644 --- a/application/city/main/resolver/controller/html/class_CityHtmlControllerResolver.php +++ b/application/city/main/resolver/controller/html/class_CityHtmlControllerResolver.php @@ -32,7 +32,7 @@ class CityHtmlControllerResolver extends BaseControllerResolver implements Contr parent::__construct(__CLASS__); // Set prefix to 'Html' - $this->setClassPrefix('Html'); + $this->setClassPrefix('city_html'); } /** diff --git a/core b/core index a142fe5..df2fa5c 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a142fe5eeaaa17a434c80ea103088558157c43bb +Subproject commit df2fa5cf4b9cef7fa1b0064416cf579793f9038e -- 2.39.5