]> git.mxchange.org Git - city.git/commitdiff
Moved more methods to 'core' as they are now more generalized + fixed config entries...
authorRoland Haeder <roland@mxchange.org>
Tue, 24 Mar 2015 19:58:36 +0000 (20:58 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 24 Mar 2015 19:58:36 +0000 (20:58 +0100)
Signed-off-by: Roland Haeder <roland@mxchange.org>
application/city/config.php
application/city/main/city/class_BaseCity.php
application/city/main/city/testing/class_SimulationTestingCity.php
application/city/main/controller/.htaccess [new file with mode: 0644]
application/city/main/controller/console/.htaccess [new file with mode: 0644]
application/city/main/controller/console/class_CityConsoleDefaultNewsController.php [new file with mode: 0644]
application/city/main/resolver/command/console/class_CityConsoleCommandResolver.php
application/city/main/resolver/command/html/class_CityHtmlCommandResolver.php
application/city/main/resolver/controller/console/class_CityConsoleControllerResolver.php
application/city/main/resolver/controller/html/class_CityHtmlControllerResolver.php
core

index 0a5c1b63bee2ba7c55992bb65ba5c15ceadad9e2..8a6298e93e1d700f4b32f4eb71abdf6a40dba1f3 100644 (file)
@@ -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');
index fb83ddb1dae667406707b26209ab0cae93b207bc..e6baded446568b8a5d75b7324a255173ca2478e8 100644 (file)
@@ -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 ------------------------
        }
 
index 4b8d231d8657147968403fab29c8ae608e838a0b..798e3de6aaea9d90750f8253939af65098bf5eab 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..95e6462
--- /dev/null
@@ -0,0 +1,156 @@
+<?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]
+?>
index 00b71d04e132325ef8bcf330d63e4a3ec88d05c6..1eb5af26395e1b4b903ac35f893fe3f95acec70b 100644 (file)
@@ -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]
index 5dd265c7ef585e61b2fefed864c766e12d3d8535..af3d1221d9f7533ad8c0b80824013cec283d3012 100644 (file)
@@ -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]
index 0553ffd3afcf29b04f55c4b106f8787a1017d988..4735d52e8848b0a564f3885ba13241ce1872137a 100644 (file)
@@ -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
index 96df86bbe27de557bd6937922bbb9ff98de0db4b..d390856019ae4f9a5c14feba6f8596c620737edc 100644 (file)
@@ -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 a142fe5eeaaa17a434c80ea103088558157c43bb..df2fa5cf4b9cef7fa1b0064416cf579793f9038e 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit a142fe5eeaaa17a434c80ea103088558157c43bb
+Subproject commit df2fa5cf4b9cef7fa1b0064416cf579793f9038e