From: Roland Häder Date: Sun, 19 Jul 2009 16:25:42 +0000 (+0000) Subject: Filter for node initialization added, more preparation for intercepting filter pattern X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f182bd3aa0313bd5550531e5c848c9109f4a8e37;p=hub.git Filter for node initialization added, more preparation for intercepting filter pattern --- diff --git a/.gitattributes b/.gitattributes index 7c7f796bf..35f40e25b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 96d955ace..0d75b689e 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -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 diff --git a/application/hub/config.php b/application/hub/config.php index f8e54313d..30830bb41 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -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"); diff --git a/application/hub/main/commands/console/class_ConsoleMainCommand.php b/application/hub/main/commands/console/class_ConsoleMainCommand.php index 4ce11a581..be0cbd8f3 100644 --- a/application/hub/main/commands/console/class_ConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_ConsoleMainCommand.php @@ -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')); } } diff --git a/application/hub/main/filter/console/class_Console b/application/hub/main/filter/console/class_Console index d6565af8a..72f5657b2 100644 --- a/application/hub/main/filter/console/class_Console +++ b/application/hub/main/filter/console/class_Console @@ -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.'); } } diff --git a/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php b/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php index 1f889d0c0..7f65b323c 100644 --- a/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php +++ b/application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/filter/node/.htaccess @@ -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 index 000000000..355b084a5 --- /dev/null +++ b/application/hub/main/filter/node/class_Node @@ -0,0 +1,63 @@ + + * @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 . + */ +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 index 000000000..51078cfae --- /dev/null +++ b/application/hub/main/filter/node/class_NodeInitializationFilter.php @@ -0,0 +1,100 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index 8ffe30886..3f2d9465c 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class HubBootNode extends BaseHubNode implements NodeHelper { +class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { /** * Protected constructor * diff --git a/application/hub/main/nodes/class_ b/application/hub/main/nodes/class_ index 215ade831..639d609d1 100644 --- a/application/hub/main/nodes/class_ +++ b/application/hub/main/nodes/class_ @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class Hub???Node extends BaseHubNode implements NodeHelper { +class Hub???Node extends BaseHubNode implements NodeHelper, Registerable { /** * Protected constructor * diff --git a/application/hub/main/nodes/list/class_HubListNode.php b/application/hub/main/nodes/list/class_HubListNode.php index d14cb6b44..3879b78ae 100644 --- a/application/hub/main/nodes/list/class_HubListNode.php +++ b/application/hub/main/nodes/list/class_HubListNode.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class HubListNode extends BaseHubNode implements NodeHelper { +class HubListNode extends BaseHubNode implements NodeHelper, Registerable { /** * Protected constructor * diff --git a/application/hub/main/nodes/master/class_HubMasterNode.php b/application/hub/main/nodes/master/class_HubMasterNode.php index 7c04fc536..d67910bee 100644 --- a/application/hub/main/nodes/master/class_HubMasterNode.php +++ b/application/hub/main/nodes/master/class_HubMasterNode.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class HubMasterNode extends BaseHubNode implements NodeHelper { +class HubMasterNode extends BaseHubNode implements NodeHelper, Registerable { /** * Protected constructor * diff --git a/application/hub/main/nodes/regular/class_HubRegularNode.php b/application/hub/main/nodes/regular/class_HubRegularNode.php index 027751672..cb2ff250b 100644 --- a/application/hub/main/nodes/regular/class_HubRegularNode.php +++ b/application/hub/main/nodes/regular/class_HubRegularNode.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class HubRegularNode extends BaseHubNode implements NodeHelper { +class HubRegularNode extends BaseHubNode implements NodeHelper, Registerable { /** * Protected constructor *