From 059bbd293a661e74a3ce7ea0fb3bc84e44f07fa8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 28 Jul 2013 23:57:08 +0000 Subject: [PATCH] Imported more classes from 'hub' code --- .gitattributes | 33 +++ .gitignore | 1 + application/lfdb2/class_ApplicationHelper.php | 239 ++++++++++++++++++ application/lfdb2/config.php | 67 +++++ application/lfdb2/data.php | 43 ++++ application/lfdb2/debug.php | 28 ++ application/lfdb2/exceptions.php | 140 ++++++++++ application/lfdb2/init.php | 41 +++ application/lfdb2/loader.php | 38 +++ application/lfdb2/main/command/.htaccess | 1 + .../lfdb2/main/command/console/.htaccess | 1 + .../class_Lfdb2ConsoleServerCommand.php | 138 ++++++++++ application/lfdb2/main/controller/.htaccess | 1 + .../lfdb2/main/controller/console/.htaccess | 1 + ...lass_Lfdb2ConsoleDefaultNewsController.php | 156 ++++++++++++ application/lfdb2/main/filter/.htaccess | 1 + .../lfdb2/main/filter/bootstrap/.htaccess | 1 + .../main/filter/bootstrap/server/.htaccess | 1 + .../bootstrap/server/class_ServerBootstrap | 66 +++++ ...erverBootstrapExtraBootstrappingFilter.php | 66 +++++ .../main/filter/class_BaseLfdb2Filter.php | 114 +++++++++ .../main/filter/class_BaseServerFilter.php | 38 +++ .../lfdb2/main/filter/server/.htaccess | 1 + .../lfdb2/main/filter/server/class_Server | 63 +++++ .../class_ServerInitializationFilter.php | 101 ++++++++ .../class_ServerPhpRequirementsFilter.php | 78 ++++++ .../class_ServerWelcomeTeaserFilter.php | 67 +++++ application/lfdb2/main/resolver/.htaccess | 1 + .../lfdb2/main/resolver/command/.htaccess | 1 + .../main/resolver/command/console/.htaccess | 1 + .../class_Lfdb2ConsoleCommandResolver.php | 171 +++++++++++++ .../lfdb2/main/resolver/controller/.htaccess | 1 + .../resolver/controller/console/.htaccess | 1 + .../class_Lfdb2ConsoleControllerResolver.php | 104 ++++++++ application/lfdb2/starter.php | 57 +++++ 35 files changed, 1862 insertions(+) create mode 100644 .gitignore create mode 100644 application/lfdb2/class_ApplicationHelper.php create mode 100644 application/lfdb2/config.php create mode 100644 application/lfdb2/data.php create mode 100644 application/lfdb2/debug.php create mode 100644 application/lfdb2/exceptions.php create mode 100644 application/lfdb2/init.php create mode 100644 application/lfdb2/loader.php create mode 100644 application/lfdb2/main/command/.htaccess create mode 100644 application/lfdb2/main/command/console/.htaccess create mode 100644 application/lfdb2/main/command/console/class_Lfdb2ConsoleServerCommand.php create mode 100644 application/lfdb2/main/controller/.htaccess create mode 100644 application/lfdb2/main/controller/console/.htaccess create mode 100644 application/lfdb2/main/controller/console/class_Lfdb2ConsoleDefaultNewsController.php create mode 100644 application/lfdb2/main/filter/.htaccess create mode 100644 application/lfdb2/main/filter/bootstrap/.htaccess create mode 100644 application/lfdb2/main/filter/bootstrap/server/.htaccess create mode 100644 application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrap create mode 100644 application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrapExtraBootstrappingFilter.php create mode 100644 application/lfdb2/main/filter/class_BaseLfdb2Filter.php create mode 100644 application/lfdb2/main/filter/class_BaseServerFilter.php create mode 100644 application/lfdb2/main/filter/server/.htaccess create mode 100644 application/lfdb2/main/filter/server/class_Server create mode 100644 application/lfdb2/main/filter/server/class_ServerInitializationFilter.php create mode 100644 application/lfdb2/main/filter/server/class_ServerPhpRequirementsFilter.php create mode 100644 application/lfdb2/main/filter/server/class_ServerWelcomeTeaserFilter.php create mode 100644 application/lfdb2/main/resolver/.htaccess create mode 100644 application/lfdb2/main/resolver/command/.htaccess create mode 100644 application/lfdb2/main/resolver/command/console/.htaccess create mode 100644 application/lfdb2/main/resolver/command/console/class_Lfdb2ConsoleCommandResolver.php create mode 100644 application/lfdb2/main/resolver/controller/.htaccess create mode 100644 application/lfdb2/main/resolver/controller/console/.htaccess create mode 100644 application/lfdb2/main/resolver/controller/console/class_Lfdb2ConsoleControllerResolver.php create mode 100644 application/lfdb2/starter.php diff --git a/.gitattributes b/.gitattributes index ac236e4..eff759d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,10 +2,43 @@ /Doxyfile -text application/.htaccess -text application/lfdb2/.htaccess -text +application/lfdb2/class_ApplicationHelper.php -text application/lfdb2/config-local.php-dist -text +application/lfdb2/config.php -text +application/lfdb2/data.php -text +application/lfdb2/debug.php -text +application/lfdb2/exceptions.php -text application/lfdb2/exceptions/.htaccess -text +application/lfdb2/init.php -text application/lfdb2/interfaces/.htaccess -text +application/lfdb2/loader.php -text application/lfdb2/main/.htaccess -text +application/lfdb2/main/command/.htaccess -text +application/lfdb2/main/command/console/.htaccess -text +application/lfdb2/main/command/console/class_Lfdb2ConsoleServerCommand.php -text +application/lfdb2/main/controller/.htaccess -text +application/lfdb2/main/controller/console/.htaccess -text +application/lfdb2/main/controller/console/class_Lfdb2ConsoleDefaultNewsController.php -text +application/lfdb2/main/filter/.htaccess -text +application/lfdb2/main/filter/bootstrap/.htaccess -text +application/lfdb2/main/filter/bootstrap/server/.htaccess -text +application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrap -text +application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrapExtraBootstrappingFilter.php -text +application/lfdb2/main/filter/class_BaseLfdb2Filter.php -text +application/lfdb2/main/filter/class_BaseServerFilter.php -text +application/lfdb2/main/filter/server/.htaccess -text +application/lfdb2/main/filter/server/class_Server -text +application/lfdb2/main/filter/server/class_ServerInitializationFilter.php -text +application/lfdb2/main/filter/server/class_ServerPhpRequirementsFilter.php -text +application/lfdb2/main/filter/server/class_ServerWelcomeTeaserFilter.php -text +application/lfdb2/main/resolver/.htaccess -text +application/lfdb2/main/resolver/command/.htaccess -text +application/lfdb2/main/resolver/command/console/.htaccess -text +application/lfdb2/main/resolver/command/console/class_Lfdb2ConsoleCommandResolver.php -text +application/lfdb2/main/resolver/controller/.htaccess -text +application/lfdb2/main/resolver/controller/console/.htaccess -text +application/lfdb2/main/resolver/controller/console/class_Lfdb2ConsoleControllerResolver.php -text +application/lfdb2/starter.php -text application/lfdb2/templates/.htaccess -text /clear-cache.sh -text db/.htaccess -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cce3d39 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +application/lfdb2/config-local.php diff --git a/application/lfdb2/class_ApplicationHelper.php b/application/lfdb2/class_ApplicationHelper.php new file mode 100644 index 0000000..59aabe6 --- /dev/null +++ b/application/lfdb2/class_ApplicationHelper.php @@ -0,0 +1,239 @@ + + * @version 0.0 + * @copyright Copyright (c) 2013 LFDB2 Developer Team + * @license GNU GPL 3.0 or any newer version + * + * 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 ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable { + /** + * The version number of this application + */ + private $appVersion = ''; + + /** + * The human-readable name for this application + */ + private $appName = ''; + + /** + * The short uni*-like name for this application + */ + private $shortName = ''; + + /** + * An instance of this class + */ + private static $selfInstance = NULL; + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Getter for an instance of this class + * + * @return $selfInstance An instance of this class + */ + public static final function getSelfInstance () { + // Is the instance there? + if (is_null(self::$selfInstance)) { + self::$selfInstance = new ApplicationHelper(); + } // END - if + + // Return the instance + return self::$selfInstance; + } + + /** + * Getter for the version number + * + * @return $appVersion The application's version number + */ + public final function getAppVersion () { + return $this->appVersion; + } + /** + * Setter for the version number + * + * @param $appVersion The application's version number + * @return void + */ + public final function setAppVersion ($appVersion) { + // Cast and set it + $this->appVersion = (string) $appVersion; + } + + /** + * Getter for human-readable name + * + * @return $appName The application's human-readable name + */ + public final function getAppName () { + return $this->appName; + } + + /** + * Setter for human-readable name + * + * @param $appName The application's human-readable name + * @return void + */ + public final function setAppName ($appName) { + // Cast and set it + $this->appName = (string) $appName;; + } + + /** + * Getter for short uni*-like name + * + * @return $shortName The application's short uni*-like name + */ + public final function getAppShortName () { + return $this->shortName; + } + + /** + * Setter for short uni*-like name + * + * @param $shortName The application's short uni*-like name + * @return void + */ + public final function setAppShortName ($shortName) { + // Cast and set it + $this->shortName = (string) $shortName; + } + + /** + * Launches the LFDB2 system + * + * @return void + */ + public final function entryPoint () { + // Set this application in registry + Registry::getRegistry()->addInstance('app', $this); + + // Is no external IP set? + if ($this->getConfigInstance()->getConfigEntry('external_ip') == '') { + // Determine external IP + $this->getConfigInstance()->setConfigEntry('external_ip', ConsoleTools::determineExternalIp()); + } // END - if + + // Default response is console + $response = $this->getResponseTypeFromSystem(); + $responseType = $this->getResponseTypeFromSystem(); + + // Create a new request object + $requestInstance = ObjectFactory::createObjectByName($this->convertToClassName($response) . 'Request'); + + // Remember request instance here + $this->setRequestInstance($requestInstance); + + // Do we have another response? + if ($requestInstance->isRequestElementSet('request')) { + // Then use it + $response = strtolower($requestInstance->getRequestElement('request')); + $responseType = $response; + } // END - if + + // ... and a new response object + $responseClass = sprintf('%sResponse', $this->convertToClassName($response)); + $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this)); + + // Remember response instance here + $this->setResponseInstance($responseInstance); + + // Get the parameter from the request + $commandName = $requestInstance->getRequestElement('command'); + + // If it is null then get default command + if (is_null($commandName)) { + // Get default command + $commandName = $responseInstance->getDefaultCommand(); + + // Set it in request + $requestInstance->setRequestElement('command', $commandName); + } // END - if + + // Get a controller resolver + $resolverClass = $this->convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver'); + $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this)); + + // Get a controller instance as well + $this->setControllerInstance($resolverInstance->resolveController()); + + // Launch the LFDB2 main routine here + $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance); + + // -------------------------- Shutdown phase -------------------------- + // Shutting down the LFDB2 + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.'); + $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); + } + + /** + * Handle the indexed array of fatal messages and puts them out in an + * acceptable fasion + * + * @param $messageList An array of fatal messages + * @return void + */ + public function handleFatalMessages (array $messageList) { + // Walk through all messages + foreach ($messageList as $message) { + exit(__METHOD__ . ':MSG:' . $message); + } // END - foreach + } + + /** + * Builds the master template's name + * + * @return $masterTemplateName Name of the master template + */ + public function buildMasterTemplateName () { + return 'node_main'; + } +} + +// [EOF] +?> diff --git a/application/lfdb2/config.php b/application/lfdb2/config.php new file mode 100644 index 0000000..af94b70 --- /dev/null +++ b/application/lfdb2/config.php @@ -0,0 +1,67 @@ + + * @version 0.0 + * @copyright Copyright (c) 2013 LFDB2 Developer Team + * @license GNU GPL 3.0 or any newer version + * + * 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 . + */ + +// Some hub-specific configuration like port hostname where we will listen, etc. +$cfg = FrameworkConfiguration::getSelfInstance(); + +// CFG: INTERNAL-IP +$cfg->setConfigEntry('internal_ip', ConsoleTools::acquireSelfIPAddress()); + +// CFG: EXTERNAL-IP +$cfg->setConfigEntry('external_ip', ''); + +// CFG: DEFAULT-CONSOLE-COMMAND +$cfg->setConfigEntry('default_console_command', 'server'); + +// CFG: DEFAULT-LFDB2CONSOLE-COMMAND +$cfg->setConfigEntry('default_lfdb2console_command', 'server'); + +// CFG: LFDB2CONSOLE-CMD-SERVER-RESOLVER-CLASS +$cfg->setConfigEntry('lfdb2console_cmd_server_resolver_class', 'Lfdb2ConsoleCommandResolver'); + +// CFG: NEWS-DOWNLOAD-FILTER +$cfg->setConfigEntry('news_download_filter', 'NewsDownloadFilter'); + +// CFG: NEWS-PROCESS-FILTER +$cfg->setConfigEntry('news_process_filter', 'NewsProcessFilter'); + +// CFG: SERVER-PHP-REQUIREMENTS-FILTER +$cfg->setConfigEntry('node_php_requirements_filter', 'NodePhpRequirementsFilter'); + +// CFG: SERVER-INITIALIZER-FILTER +$cfg->setConfigEntry('server_initializer_filter', 'ServerInitializationFilter'); + +// CFG: SERVER-ACTIVATION-TASK-HANDLER-INITIALIZER-FILTER +$cfg->setConfigEntry('server_activation_task_handler_initializer_filter', 'ServerTaskHandlerInitializerFilter'); + +// CFG: SERVER-PHP-REQUIREMENTS-FILTER +$cfg->setConfigEntry('server_php_requirements_filter', 'ServerPhpRequirementsFilter'); + +// CFG: SERVER-WELCOME-TEASER-FILTER +$cfg->setConfigEntry('server_welcome_teaser_filter', 'ServerWelcomeTeaserFilter'); + +// CFG: SERVER-BOOTSTRAP-EXTRA-BOOTSTRAPPING-FILTER +$cfg->setConfigEntry('server_bootstrap_extra_bootstrapping_filter', 'ServerBootstrapExtraBootstrappingFilter'); + +// [EOF] +?> diff --git a/application/lfdb2/data.php b/application/lfdb2/data.php new file mode 100644 index 0000000..dd17b19 --- /dev/null +++ b/application/lfdb2/data.php @@ -0,0 +1,43 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub 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 . + */ + +// Get config instance +$cfg = FrameworkConfiguration::getSelfInstance(); + +// Get an instance of the helper +$app = call_user_func_array( + array($cfg->getConfigEntry('app_helper_class'), 'getSelfInstance'), + array() +); + +// Set application name and version +$app->setAppName('Local File Database NG'); +$app->setAppVersion('0.0.0'); +$app->setAppShortName('lfdb2'); + +// [EOF] +?> diff --git a/application/lfdb2/debug.php b/application/lfdb2/debug.php new file mode 100644 index 0000000..2ffd5f5 --- /dev/null +++ b/application/lfdb2/debug.php @@ -0,0 +1,28 @@ + + * @version 0.0 + * @copyright Copyright (c) 2013 LFDB2 Developer Team + * @license GNU GPL 3.0 or any newer version + * + * 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 . + */ + +// Set error reporting +error_reporting(E_ALL | E_STRICT); + +// [EOF] +?> diff --git a/application/lfdb2/exceptions.php b/application/lfdb2/exceptions.php new file mode 100644 index 0000000..57e7c72 --- /dev/null +++ b/application/lfdb2/exceptions.php @@ -0,0 +1,140 @@ + + * @version 0.0 + * @copyright Copyright (c) 2013 LFDB2 Developer Team + * @license GNU GPL 3.0 or any newer version + * + * 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 . + */ + +// The node's own exception handler +function hub_exception_handler ($exceptionInstance) { + // Is it an object and a valid instance? + if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) { + // Init variable + $backTrace = ''; + + // Get all call levels from backtrace + foreach ($exceptionInstance->getTrace() as $idx => $traceArray) { + // Init argument string + $argsString = ''; + + // Convert arguments type into human-readable + foreach ($traceArray['args'] as $arg) { + $argsString .= ', ' . gettype($arg); + } // END - foreach + $argsString = substr($argsString, 2); + + // Set missing file/line + if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown'; + if (!isset($traceArray['line'])) $traceArray['line'] = '0'; + if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject'; + if (!isset($traceArray['type'])) $traceArray['type'] = '->'; + + $backTrace .= sprintf("---------- Pos %d: ---------- +Method : %s%s%s(%s) +----- Caller: ----- +File : %s +Line : %d\n", + ($idx + 1), + $traceArray['class'], + $traceArray['type'], + $traceArray['function'], + $argsString, + basename($traceArray['file']), + $traceArray['line'] + ); + } // END - foreach + + // Construct the message + $message = sprintf("-------------------------------------------------------------------------------- +Uncaught Exception : %s +-------------------------------------------------------------------------------- +Message : %s +Code : %s +File : %s +Line : %d +-------------------------------------------------------------------------------- +Backtrace: +-------------------------------------------------------------------------------- +%s +--------------------------------------------------------------------------------\n", + trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))), + trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))), + $exceptionInstance->getHexCode(), + $exceptionInstance->getFile(), + $exceptionInstance->getLine(), + trim($backTrace) + ); + + // Output the message + print($message); + } else { + // Invalid exception instance detected! Do *only* throw exceptions that + // extends our own exception 'FrameworkException' to get such nice + // outputs like above. + print('exceptionInstance[]=' . gettype($exceptionInstance) . ' is invalid! Please inform the core developer team.'); + } +} + +// Error handler +function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) { + // Construct the message + $message = sprintf('File: %s, Line: %s, Code: %s, Message: %s', + basename($errfile), + $errline, + $errno, + $errstr + ); + + // Throw an exception here + throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR); +} // END - function + +// Assertion handler +function __assertHandler ($file, $line, $code) { + // Empty code? + if ($code === '') { + $code = 'Unknown'; + } // END - if + + // Create message + $message = sprintf('File: %s, Line: %s, Code: %s', + basename($file), + $line, + $code + ); + + // Throw an exception here + throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED); +} // END - function + +// Set error handler +//set_error_handler('__errorHandler'); + +// Set the new handler +set_exception_handler('hub_exception_handler'); + +// Init assert handling +assert_options(ASSERT_ACTIVE , TRUE); +assert_options(ASSERT_WARNING , FALSE); +assert_options(ASSERT_BAIL , TRUE); +assert_options(ASSERT_QUIET_EVAL, FALSE); +assert_options(ASSERT_CALLBACK , '__assertHandler'); + +// [EOF] +?> diff --git a/application/lfdb2/init.php b/application/lfdb2/init.php new file mode 100644 index 0000000..ad80370 --- /dev/null +++ b/application/lfdb2/init.php @@ -0,0 +1,41 @@ + + * @version 0.0 + * @copyright Copyright (c) 2013 LFDB2 Developer Team + * @license GNU GPL 3.0 or any newer version + * + * 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 . + */ + +// Get config instance +$cfg = FrameworkConfiguration::getSelfInstance(); + +// Initialize output system +require($cfg->getConfigEntry('base_path') . 'inc/output.php'); + +// This application needs a database connection then we have to simply include +// the inc/database.php script +require($cfg->getConfigEntry('base_path') . 'inc/database.php'); + +// Get's our IP address +ConsoleTools::acquireSelfIPAddress(); + +// [EOF] +?> diff --git a/application/lfdb2/loader.php b/application/lfdb2/loader.php new file mode 100644 index 0000000..e7c8506 --- /dev/null +++ b/application/lfdb2/loader.php @@ -0,0 +1,38 @@ + + * @version 0.0 + * @copyright Copyright (c) 2013 LFDB2 Developer Team + * @license GNU GPL 3.0 or any newer version + * + * 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 . + */ + +// Get config instance +$cfg = FrameworkConfiguration::getSelfInstance(); + +// Load all classes for the application +foreach ($lowerClasses as $class) { + // Try to load the application classes + ClassLoader::getSelfInstance()->scanClassPath(sprintf('%s/%s/%s', $cfg->getConfigEntry('application_path'), $cfg->getConfigEntry('app_name'), $class)); +} // END - foreach + +// Clean up the global namespace +unset($lowerClasses); +unset($class); + +// [EOF] +?> diff --git a/application/lfdb2/main/command/.htaccess b/application/lfdb2/main/command/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/command/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/command/console/.htaccess b/application/lfdb2/main/command/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/command/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/command/console/class_Lfdb2ConsoleServerCommand.php b/application/lfdb2/main/command/console/class_Lfdb2ConsoleServerCommand.php new file mode 100644 index 0000000..c2c58b6 --- /dev/null +++ b/application/lfdb2/main/command/console/class_Lfdb2ConsoleServerCommand.php @@ -0,0 +1,138 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub 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 Lfdb2ConsoleServerCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public static final function createLfdb2ConsoleServerCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new Lfdb2ConsoleServerCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given command 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 Try to create a Lfdb2ActivationTask or so + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a registry and the application instance from it + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + /* + * ----------------------- Bootstrapping phase ------------------------ + * Try to bootstrap the server and pass the request instance to it for + * extra arguments which mostly override config entries or enable special + * features within the hub (none is ready at this development stage) + */ + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); + + // Get server instance + $serverInstance = Registry::getRegistry()->getInstance('server'); + + // Add some server-specific filters, e.g. announcement + $serverInstance->addExtraServerFilters(); + + /* + * -------------------------- Server activation -------------------------- + * Activates the server by doing some final preparation steps and setting + * the attribute $hubIsActive to TRUE. + */ + $serverInstance->activateServer($requestInstance, $responseInstance); + + // Get task handler instance + $handlerInstance = Registry::getRegistry()->getInstance('task_handler'); + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---'); + + /* + * ----------------------------- Main loop ---------------------------- + * This is the main server loop. Queried calls should come back here very fast + * so the whole application runs on nice speed. This while-loop goes + * until the hub is no longer active or all tasks are killed. + */ + while (($serverInstance->isServerActive()) && ($handlerInstance->hasTasksLeft())) { + // Handle all tasks here + $handlerInstance->handleTasks(); + } // END - while + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---'); + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + * @todo Should we add some more filters? + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Add pre filters + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('server_php_requirements_filter')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('server_initializer_filter')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('server_welcome_teaser_filter')); + + // Add bootstrap filters + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('server_bootstrap_extra_bootstrapping_filter')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('server_bootstrap_listener_pool_filter')); + + // Add server activation filters + $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('server_activation_task_handler_initializer_filter')); + + // Add shutdown filters + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('server_shutdown_task_handler_filter')); + + // This is the last generic shutdown filter + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('server_shutdown_server_filter')); + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/controller/.htaccess b/application/lfdb2/main/controller/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/controller/console/.htaccess b/application/lfdb2/main/controller/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/controller/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/controller/console/class_Lfdb2ConsoleDefaultNewsController.php b/application/lfdb2/main/controller/console/class_Lfdb2ConsoleDefaultNewsController.php new file mode 100644 index 0000000..f730e23 --- /dev/null +++ b/application/lfdb2/main/controller/console/class_Lfdb2ConsoleDefaultNewsController.php @@ -0,0 +1,156 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 Lfdb2ConsoleDefaultNewsController 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 createLfdb2ConsoleDefaultNewsController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new Lfdb2ConsoleDefaultNewsController(); + + // 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 hub activation filter + * + * @param $filterInstance A Filterable class + * @return void + */ + public function addActivationFilter (Filterable $filterInstance) { + $this->addFilter('activation', $filterInstance); + } + + /** + * Executes all hub 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/lfdb2/main/filter/.htaccess b/application/lfdb2/main/filter/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/filter/bootstrap/.htaccess b/application/lfdb2/main/filter/bootstrap/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/filter/bootstrap/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/filter/bootstrap/server/.htaccess b/application/lfdb2/main/filter/bootstrap/server/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/filter/bootstrap/server/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrap b/application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrap new file mode 100644 index 0000000..114e922 --- /dev/null +++ b/application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrap @@ -0,0 +1,66 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Server 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 ServerBootstrap???Filter extends BaseServerFilter 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 createServerBootstrap???Filter () { + // Get a new instance + $filterInstance = new ServerBootstrap???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) { + // Get server instance + $serverInstance = Registry::getRegistry()->getInstance('server'); + + // Now do something + $this->partialStub('Please implement this step.'); + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrapExtraBootstrappingFilter.php b/application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrapExtraBootstrappingFilter.php new file mode 100644 index 0000000..8602702 --- /dev/null +++ b/application/lfdb2/main/filter/bootstrap/server/class_ServerBootstrapExtraBootstrappingFilter.php @@ -0,0 +1,66 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub 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 ServerBootstrapExtraBootstrappingFilter extends BaseServerFilter 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 static final function createServerBootstrapExtraBootstrappingFilter () { + // Get a new instance + $filterInstance = new ServerBootstrapExtraBootstrappingFilter(); + + // 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 + * @throws FilterChainException If $serverInstance is null (no NullPointerException here) + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get server instance + $serverInstance = Registry::getRegistry()->getInstance('server'); + + // Do some extra bootstrapping steps + $serverInstance->doBootstrapping(); + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/filter/class_BaseLfdb2Filter.php b/application/lfdb2/main/filter/class_BaseLfdb2Filter.php new file mode 100644 index 0000000..fec94ae --- /dev/null +++ b/application/lfdb2/main/filter/class_BaseLfdb2Filter.php @@ -0,0 +1,114 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 BaseLfdb2Filter extends BaseFilter { + /** + * Array with all data XML nodes (which hold the actual data) and their values + */ + protected $dataXmlNodes = array(); + + /** + * Protected constructor + * + * @param $className Real name of class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Processes the given raw message content. The method renderXmlContent + * may throw (not the method itself) several exceptions: + * + * InvalidXmlNodeException - If an invalid XML node has been found (e.g. + * wrong/out-dated template used) + * XmlNodeMismatchException - Again might be caused by invalid XML node + * usage + * XmlParserException - If the XML message is damaged or not + * well-formed + * + * @param $messageType Type of message + * @param $messageContent Raw message content + * @param $packageInstance An instance of a Receivable class + * @return void + * @todo Exceptions from renderXmlContent() are currently unhandled + */ + protected function genericProcessMessage ($messageType, $messageContent, Receivable $packageInstance) { + $this->partialStub('Please fix this imported code.'); + die(); + + // Get a template instance from the factory + $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_' . $messageType . '_template_class'); + + // And render the XML content (aka message) + $templateInstance->renderXmlContent($messageContent); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Handling ' . strlen($messageContent) . ' bytes: ' . $messageContent); + + /* + * The template system now stores all required data as 'general' + * variables, so simply get them. If there is an invalid XML node + * inside the message, the above method call will cause exceptions. + */ + foreach ($this->dataXmlNodes as $key => $dummy) { + // Call it + $value = $templateInstance->readXmlData($key); + + /* + * If value is NULL, a variable hasn't been found. This could mean + * that *this* node is running an out-dated software or the other + * peer is using an out-dated $messageType.xml template. + */ + if (is_null($value)) { + // Output a warning + self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Found not fully supported variable ' . $key . ' - skipping.'); + + // Skip this part, don't write NULLs to the array + continue; + } // END - if + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: key=' . $key . ',value=' . $value); + + // Set it now + $this->dataXmlNodes[$key] = $value; + } // END - foreach + + // Construct an array for pushing it on next stack + $messageArray = array( + // Message data itself + NetworkPackage::MESSAGE_ARRAY_DATA => $this->dataXmlNodes, + // Message type (which is $messageType) + NetworkPackage::MESSAGE_ARRAY_TYPE => $messageType + ); + + // Push the processed message back on stack + $packageInstance->getStackerInstance()->pushNamed(NetworkPackage::STACKER_NAME_PROCESSED_MESSAGE, $messageArray); + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/filter/class_BaseServerFilter.php b/application/lfdb2/main/filter/class_BaseServerFilter.php new file mode 100644 index 0000000..6bd8101 --- /dev/null +++ b/application/lfdb2/main/filter/class_BaseServerFilter.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 BaseServerFilter extends BaseLfdb2Filter { + /** + * Protected constructor + * + * @param $className Real name of class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/filter/server/.htaccess b/application/lfdb2/main/filter/server/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/filter/server/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/filter/server/class_Server b/application/lfdb2/main/filter/server/class_Server new file mode 100644 index 0000000..33cc50a --- /dev/null +++ b/application/lfdb2/main/filter/server/class_Server @@ -0,0 +1,63 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 Server???Filter extends BaseServerFilter 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 createServer???Filter () { + // Get a new instance + $filterInstance = new Server???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/lfdb2/main/filter/server/class_ServerInitializationFilter.php b/application/lfdb2/main/filter/server/class_ServerInitializationFilter.php new file mode 100644 index 0000000..c63fef9 --- /dev/null +++ b/application/lfdb2/main/filter/server/class_ServerInitializationFilter.php @@ -0,0 +1,101 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 ServerInitializationFilter extends BaseServerFilter 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 static final function createServerInitializationFilter () { + // Get a new instance + $filterInstance = new ServerInitializationFilter(); + + // 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + $this->partialStub('Unported.'); + die(); + + // The default node-mode is from our configuration + $nodeMode = $this->getConfigInstance()->getConfigEntry('node_default_mode'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[INIT:] Got default node mode ' . $nodeMode . ' from configuration.'); + + // 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 = 'Lfdb2' . $this->convertToClassName($nodeMode) . 'Server'; + + // And try to instance it + try { + // Get an instance + $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance)); + + // Get a registry + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + // Set the app instance + $nodeInstance->setApplicationInstance($applicationInstance); + + // Add node-specific filters + $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); + } catch (ClassNotFoundException $e) { + // This exception means, the node mode is invalid. + // @TODO Can we rewrite this to app_exit() ? + $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: node mode ' . $nodeMode . ' is invalid.'); + } + + // Set the node instance in registry + Registry::getRegistry()->addInstance('node', $nodeInstance); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[INIT:] Server ' . $nodeMode . ' has been added to registry.'); + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/filter/server/class_ServerPhpRequirementsFilter.php b/application/lfdb2/main/filter/server/class_ServerPhpRequirementsFilter.php new file mode 100644 index 0000000..d62555b --- /dev/null +++ b/application/lfdb2/main/filter/server/class_ServerPhpRequirementsFilter.php @@ -0,0 +1,78 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 ServerPhpRequirementsFilter extends BaseServerFilter 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 static final function createServerPhpRequirementsFilter () { + // Get a new instance + $filterInstance = new ServerPhpRequirementsFilter(); + + // 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 + * @throws FilterChainException If a required PHP function is not available + * @todo Add more test and try to add an extra message to the thrown exception + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // By default, the requirement check is passed and zero checks are failed + $checkPassed = TRUE; + $checksFailed = 0; + + // Socket support is essential... + if (!function_exists('socket_create')) { + // Test failed + $checkPassed = FALSE; + $checksFailed++; + } // END -if + + // Are all tests passed? + if ($checkPassed === FALSE) { + // Throw an exception + throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); + } // END - if + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/filter/server/class_ServerWelcomeTeaserFilter.php b/application/lfdb2/main/filter/server/class_ServerWelcomeTeaserFilter.php new file mode 100644 index 0000000..ee033c4 --- /dev/null +++ b/application/lfdb2/main/filter/server/class_ServerWelcomeTeaserFilter.php @@ -0,0 +1,67 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub 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 ServerWelcomeTeaserFilter extends BaseServerFilter 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 static final function createServerWelcomeTeaserFilter () { + // Get a new instance + $filterInstance = new ServerWelcomeTeaserFilter(); + + // 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 + * @throws FilterChainException If $nodeInstance is null (no NullPointerException here) + * @todo Handle over the $responseInstance to outputConsoleTeaser() + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get server instance + $serverInstance = Registry::getRegistry()->getInstance('server'); + + // Now output the teaser + $serverInstance->outputConsoleTeaser(); + } +} + +// [EOF] +?> diff --git a/application/lfdb2/main/resolver/.htaccess b/application/lfdb2/main/resolver/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/resolver/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/resolver/command/.htaccess b/application/lfdb2/main/resolver/command/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/resolver/command/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/resolver/command/console/.htaccess b/application/lfdb2/main/resolver/command/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/resolver/command/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/resolver/command/console/class_Lfdb2ConsoleCommandResolver.php b/application/lfdb2/main/resolver/command/console/class_Lfdb2ConsoleCommandResolver.php new file mode 100644 index 0000000..fca9287 --- /dev/null +++ b/application/lfdb2/main/resolver/command/console/class_Lfdb2ConsoleCommandResolver.php @@ -0,0 +1,171 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 Lfdb2ConsoleCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "Lfdb2Console" + $this->setClassPrefix('Lfdb2Console'); + } + + /** + * Creates an instance of a Lfdb2Console command resolver with a given default command + * + * @param $commandName The default command we shall execute + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared command resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidCommandException Thrown if default command is invalid + */ + public static final function createLfdb2ConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new Lfdb2ConsoleCommandResolver(); + + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isCommandValid($commandName) === FALSE) { + // Invalid command found + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + + // 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_console_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_console_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 = 'Lfdb2Console' . $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/lfdb2/main/resolver/controller/.htaccess b/application/lfdb2/main/resolver/controller/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/resolver/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/resolver/controller/console/.htaccess b/application/lfdb2/main/resolver/controller/console/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/lfdb2/main/resolver/controller/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/lfdb2/main/resolver/controller/console/class_Lfdb2ConsoleControllerResolver.php b/application/lfdb2/main/resolver/controller/console/class_Lfdb2ConsoleControllerResolver.php new file mode 100644 index 0000000..5240d1e --- /dev/null +++ b/application/lfdb2/main/resolver/controller/console/class_Lfdb2ConsoleControllerResolver.php @@ -0,0 +1,104 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2013 LFDB2 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 Lfdb2ConsoleControllerResolver extends BaseControllerResolver implements ControllerResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "Lfdb2Console" + $this->setClassPrefix('Lfdb2Console'); + } + + /** + * Creates an instance of a resolver class with a given command + * + * @param $controllerName The controller we shall resolve + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared controller resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidControllerException Thrown if default controller is invalid + */ + public static final function createLfdb2ConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new Lfdb2ConsoleControllerResolver(); + + // Is the variable $controllerName set and the command is valid? + if (empty($controllerName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) { + // Invalid command found + throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + + // Set command name + $resolverInstance->setControllerName($controllerName); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Resolves the default controller of the given command + * + * @return $controllerInstance A controller instance for the default + * command + * @throws InvalidControllerInstanceException Thrown if $controllerInstance + * is invalid + */ + public function resolveController () { + // Init variables + $controllerName = ''; + $controllerInstance = NULL; + + // Get the command name + $controllerName = $this->getControllerName(); + + // Get the command + $controllerInstance = $this->loadController($controllerName); + + // And validate it + if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { + // This command has an invalid instance! + throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } // END - if + + // Set last controller + $this->setResolvedInstance($controllerInstance); + + // Return the maybe resolved instance + return $controllerInstance; + } +} + +// [EOF] +?> diff --git a/application/lfdb2/starter.php b/application/lfdb2/starter.php new file mode 100644 index 0000000..8266d31 --- /dev/null +++ b/application/lfdb2/starter.php @@ -0,0 +1,57 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub 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 . + */ + +// Is there an application helper instance? We need the method main() for +// maining the application +$app = call_user_func_array( + array( + FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class'), 'getSelfInstance' + ), array() +); + +// Some sanity checks +if ((empty($app)) || (is_null($app))) { + // Something went wrong! + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the helper class %s is not loaded.", + $application, + FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class') + )); +} elseif (!is_object($app)) { + // No object! + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because 'app' is not an object.", + $application + )); +} elseif (!method_exists($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method'))) { + // Method not found! + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the method %s is missing.", + $application, + FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method') + )); +} + +// Call user function +call_user_func_array(array($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')), array()); + +// [EOF] +?> -- 2.39.5