]> git.mxchange.org Git - hub.git/commitdiff
Filter for node initialization added, more preparation for intercepting filter pattern
authorRoland Häder <roland@mxchange.org>
Sun, 19 Jul 2009 16:25:42 +0000 (16:25 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 19 Jul 2009 16:25:42 +0000 (16:25 +0000)
14 files changed:
.gitattributes
application/hub/class_ApplicationHelper.php
application/hub/config.php
application/hub/main/commands/console/class_ConsoleMainCommand.php
application/hub/main/filter/console/class_Console
application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php
application/hub/main/filter/node/.htaccess [new file with mode: 0644]
application/hub/main/filter/node/class_Node [new file with mode: 0644]
application/hub/main/filter/node/class_NodeInitializationFilter.php [new file with mode: 0644]
application/hub/main/nodes/boot/class_HubBootNode.php
application/hub/main/nodes/class_
application/hub/main/nodes/list/class_HubListNode.php
application/hub/main/nodes/master/class_HubMasterNode.php
application/hub/main/nodes/regular/class_HubRegularNode.php

index 7c7f796bfc71c8ca1c29ceffd52c1fe6bd2fefeb..35f40e25bf4830116209a51e81feff036d9e3859 100644 (file)
@@ -60,6 +60,9 @@ application/hub/main/filter/bootstrap/class_Bootstrap -text
 application/hub/main/filter/console/.htaccess -text
 application/hub/main/filter/console/class_Console -text
 application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php -text
+application/hub/main/filter/node/.htaccess -text
+application/hub/main/filter/node/class_Node -text
+application/hub/main/filter/node/class_NodeInitializationFilter.php -text
 application/hub/main/listener/.htaccess -text
 application/hub/main/listener/class_ -text
 application/hub/main/listener/class_BaseListener.php -text
index 96d955ace9315cd7489548917999b0968d215dce..0d75b689ebb2ca75a7a0d45d878994b9fe24d4af 100644 (file)
@@ -196,44 +196,15 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
                // Get a controller instance as well
                $this->controllerInstance = $resolverInstance->resolveController();
 
-               // Handle the request
-               $this->controllerInstance->handleRequest($requestInstance, $responseInstance);
-               // ----------------------------- Init phase ---------------------------
-
-               // The default node-mode is from our configuration
-               $nodeMode = $this->getConfigInstance()->readConfig('node_mode');
-               die("Until here!\n");
-
-               // Prepare a ConsoleRequest class to catch all parameters
-               $requestInstance = ObjectFactory::createObjectByName('ConsoleRequest');
-
-               // Is the node 'mode' parameter set?
-               if ($requestInstance->isRequestElementSet('mode')) {
-                       // Then use this which overrides the config entry temporarily
-                       $nodeMode = $requestInstance->getRequestElement('mode');
-               } else {
-                       // Set it for easier re-usage
-                       $requestInstance->setRequestElement('mode', $nodeMode);
-               }
-
-               // Now convert the node-mode in a class name
-               $className = 'Hub' . $this->convertToClassName($nodeMode) . 'Node';
-
-               // And try to instance it
-               try {
-                       // Get an instance
-                       $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
+               // Get the registry
+               $registryInstance = Registry::getRegistry();
 
-                       // Set the app instance
-                       $nodeInstance->setApplicationInstance($this);
+               // Set this application
+               $registryInstance->addInstance('app', $this);
 
-                       // Initialize all filters
-                       $nodeInstance->initializeFilters();
-               } catch (ClassNotFoundException $e) {
-                       // This exception means, the node mode is invalid.
-                       // @TODO Can we rewrite this to app_die() ?
-                       die('Node mode ' . $nodeMode . ' is invalid.' . "\n");
-               }
+               // Handle the request
+               $this->controllerInstance->handleRequest($requestInstance, $responseInstance);
+               die("STOP\n");
 
                // ----------------------- Output teaser lines ------------------------
                // Output some introducing lines to the console. This should be later
index f8e54313dbc5cb4184828a3eaed383367a9922cb..30830bb410d3e69f726f2e04373dfe964364e0b0 100644 (file)
@@ -93,6 +93,9 @@ $cfg->setConfigEntry('news_download_filter', "NewsDownloadFilter");
 // CFG: NEWS-PROCESS-FILTER
 $cfg->setConfigEntry('news_process_filter', "NewsProcessFilter");
 
+// CFG: NODE-INITIALIZATION-FILTER
+$cfg->setConfigEntry('node_initializer_filter', "NodeInitializationFilter");
+
 // CFG: CONSOLE-WELCOME-TEASER-FILTER
 $cfg->setConfigEntry('console_welcome_teaser_filter', "ConsoleWelcomeTeaserFilter");
 
index 4ce11a581310f2d44c0afacf971b2f4eaad7e438..be0cbd8f3a69d8bb3757bc4f471d631db57d7a32 100644 (file)
@@ -70,6 +70,7 @@ class ConsoleMainCommand extends BaseCommand implements Commandable {
         */
        public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
                // Add filters
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_initializer_filter'));
                $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('console_welcome_teaser_filter'));
        }
 }
index d6565af8a6a201062d0302a727d0bf7f3259330f..72f5657b2bb4846ec2507169fc43f4a82f2b0fd6 100644 (file)
@@ -54,8 +54,17 @@ class Console???Filter extends BaseFilter implements Filterable {
         * @todo        0% done
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+               // Get node instance
+               $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+               // Sanity-check on it
+               if (is_null($nodeInstance)) {
+                       // Throws a FilterChainException to stop further processing
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
+               } // END - if
+
                // Implement this!
-               $this->partialStub("Please implement this method.");
+               $this->partialStub('Please implement this method.');
        }
 }
 
index 1f889d0c0fd9d8240f36d059abb0529ff4e521f0..7f65b323c7712a36f8e6f8679c819effa6915539 100644 (file)
@@ -51,11 +51,20 @@ class ConsoleWelcomeTeaserFilter extends BaseFilter implements Filterable {
         * @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
+        * @throws      FilterChainException    If the nodeInstance was not set
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
-               // Implement this!
-               $this->partialStub("Please implement this method.");
+               // Get node instance
+               $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+               // Sanity-check on it
+               if (is_null($nodeInstance)) {
+                       // Throws a FilterChainException to stop further processing
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
+               } // END - if
+
+               // Now output the teaser
+               $nodeInstance->outputConsoleTeaser();
        }
 }
 
diff --git a/application/hub/main/filter/node/.htaccess b/application/hub/main/filter/node/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/filter/node/class_Node b/application/hub/main/filter/node/class_Node
new file mode 100644 (file)
index 0000000..355b084
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/**
+ * A ??? filter for nodes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Core 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 Node???Filter extends BaseFilter 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 createNode???Filter () {
+               // Get a new instance
+               $filterInstance = new Node???Filter();
+
+               // Return the instance
+               return $filterInstance;
+       }
+
+       /**
+        * Executes the filter with given request and response objects
+        *
+        * @param       $requestInstance        An instance of a class with an Requestable interface
+        * @param       $responseInstance       An instance of a class with an Responseable interface
+        * @return      void
+        * @todo        0% done
+        */
+       public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+               // Implement this!
+               $this->partialStub("Please implement this method.");
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/filter/node/class_NodeInitializationFilter.php b/application/hub/main/filter/node/class_NodeInitializationFilter.php
new file mode 100644 (file)
index 0000000..51078cf
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/**
+ * A Initialization filter for nodes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Core 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 NodeInitializationFilter extends BaseFilter 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 createNodeInitializationFilter () {
+               // Get a new instance
+               $filterInstance = new NodeInitializationFilter();
+
+               // 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) {
+               // The default node-mode is from our configuration
+               $nodeMode = $this->getConfigInstance()->readConfig('node_mode');
+
+               // Prepare a ConsoleRequest class to catch all parameters
+               $requestInstance = ObjectFactory::createObjectByName('ConsoleRequest');
+
+               // Is the node 'mode' parameter set?
+               if ($requestInstance->isRequestElementSet('mode')) {
+                       // Then use this which overrides the config entry temporarily
+                       $nodeMode = $requestInstance->getRequestElement('mode');
+               } else {
+                       // Set it for easier re-usage
+                       $requestInstance->setRequestElement('mode', $nodeMode);
+               }
+
+               // Now convert the node-mode in a class name
+               $className = 'Hub' . $this->convertToClassName($nodeMode) . 'Node';
+
+               // And try to instance it
+               try {
+                       // Get an instance
+                       $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
+
+                       // Get a registry
+                       $appInstance = Registry::getRegistry()->getInstance('app');
+
+                       // Set the app instance
+                       $nodeInstance->setApplicationInstance($appInstance);
+
+                       // Initialize all filters
+                       $nodeInstance->initializeFilters();
+               } catch (ClassNotFoundException $e) {
+                       // This exception means, the node mode is invalid.
+                       // @TODO Can we rewrite this to app_die() ?
+                       die('Node mode ' . $nodeMode . ' is invalid.' . "\n");
+               }
+
+               // Set the node instance in registry
+               Registry::getRegistry()->addInstance('node', $nodeInstance);
+       }
+}
+
+// [EOF]
+?>
index 8ffe3088612e5897b18f5e30c3d506c87ce53e87..3f2d9465c386a0b5631e2f79afbf5938301d82d8 100644 (file)
@@ -21,7 +21,7 @@
  * 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 HubBootNode extends BaseHubNode implements NodeHelper {
+class HubBootNode extends BaseHubNode implements NodeHelper, Registerable {
        /**
         * Protected constructor
         *
index 215ade831d97fb3ada617df6911cbabe6479ecb3..639d609d150dbdb86de829fff257508f5b49361f 100644 (file)
@@ -21,7 +21,7 @@
  * 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 {
+class Hub???Node extends BaseHubNode implements NodeHelper, Registerable {
        /**
         * Protected constructor
         *
index d14cb6b44e1b232896949c1866bb365e306dd4e7..3879b78ae3edfa0398757f34e08f1428252d9657 100644 (file)
@@ -21,7 +21,7 @@
  * 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 HubListNode extends BaseHubNode implements NodeHelper {
+class HubListNode extends BaseHubNode implements NodeHelper, Registerable {
        /**
         * Protected constructor
         *
index 7c04fc53643f691cc0d8ad246f57bab6ab671c4b..d67910beefdd1c2306222b3e9bfd9dd467f01aca 100644 (file)
@@ -21,7 +21,7 @@
  * 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 HubMasterNode extends BaseHubNode implements NodeHelper {
+class HubMasterNode extends BaseHubNode implements NodeHelper, Registerable {
        /**
         * Protected constructor
         *
index 0277516727df64d2169cf4535e9ee4a827573902..cb2ff250bca266342e439cdbc43b87c9aacd0b9d 100644 (file)
@@ -21,7 +21,7 @@
  * 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 HubRegularNode extends BaseHubNode implements NodeHelper {
+class HubRegularNode extends BaseHubNode implements NodeHelper, Registerable {
        /**
         * Protected constructor
         *