From 12a993738a1d1bea29a886e06478beb145c275e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 31 May 2008 11:29:30 +0000 Subject: [PATCH] Code merge from latest ship-simu code --- .gitattributes | 40 +- application/hub/class_ApplicationHelper.php | 14 + .../local => exceptions/helper}/.htaccess | 0 .../helper/class_FormClosedException.php | 47 ++ .../helper/class_FormGroupClosedException.php | 46 ++ .../helper/class_FormOpenedException.php | 47 ++ .../helper/class_InvalidFormNameException.php | 45 ++ .../io/class_DirPointerNotOpenedException.php | 4 +- .../class_FilePointerNotOpenedException.php | 12 +- ...s_InvalidTemplateVariableNameException.php | 23 +- inc/classes/exceptions/user/.htaccess | 1 + .../user/class_UsernameMissingException.php | 46 ++ .../class_ManageableApplication.php | 9 + .../interfaces/commands/class_Commandable.php | 2 +- inc/classes/interfaces/filter/.htaccess | 1 + .../interfaces/filter/class_Filterable.php | 36 ++ .../interfaces/request/class_Requestable.php | 8 + .../resolver/class_ControllerResolver.php | 2 +- .../response/class_Responseable.php | 9 + inc/classes/interfaces/user/.htaccess | 1 + .../interfaces/user/class_ManageableUser.php | 28 + .../main/class_BaseFrameworkSystem.php | 142 ++++- inc/classes/main/commands/class_ | 73 +++ .../commands/web/class_WebDoFormCommand.php | 77 +++ .../commands/web/class_WebHomeCommand.php | 8 +- .../commands/web/class_WebRegisterCommand.php | 121 ++++ .../main/compressor/class_Bzip2Compressor.php | 2 +- .../main/compressor/class_GzipCompressor.php | 2 +- .../main/compressor/class_NullCompressor.php | 2 +- .../main/console/class_ConsoleTools.php | 2 +- .../main/controller/class_BaseController.php | 89 ++- .../class_LocalDefaultNewsController.php | 111 ---- .../default/class_WebDefaultController.php | 25 +- .../class_WebDefaultNewsController.php | 27 +- inc/classes/main/controller/form/.htaccess | 1 + .../class_WebDoFormController.php} | 60 +- .../classes/class_LocalFileDatabase.php | 14 +- .../main/debug/class_DebugConsoleOutput.php | 2 +- .../main/debug/class_DebugErrorLogOutput.php | 2 +- .../main/debug/class_DebugWebOutput.php | 2 +- .../main/extended/class_ObjectLimits.php | 2 +- .../extended/class_SerializationContainer.php | 2 +- .../factories/objects/class_ObjectFactory.php | 2 +- ...wsFactory.php => class_WebNewsFactory.php} | 10 +- inc/classes/main/filter/.htaccess | 1 + inc/classes/main/filter/class_ | 72 +++ .../filter/class_AbstractFilterDecorator.php | 87 +++ inc/classes/main/filter/class_FilterChain.php | 93 +++ inc/classes/main/filter/validator/.htaccess | 1 + .../class_UserNameValidatorFilter.php | 131 ++++ inc/classes/main/helper/.htaccess | 1 + inc/classes/main/helper/class_ | 53 ++ inc/classes/main/helper/class_BaseHelper.php | 90 +++ inc/classes/main/helper/web/.htaccess | 1 + .../main/helper/web/class_WebFormHelper.php | 589 ++++++++++++++++++ ...ileIOStream.php => class_FileIoStream.php} | 10 +- .../io/class_FrameworkDirectoryPointer.php | 2 +- .../io/class_FrameworkFileInputPointer.php | 2 +- .../io/class_FrameworkFileOutputPointer.php | 2 +- .../main/language/class_LanguageSystem.php | 59 +- .../main/output/class_ConsoleOutput.php | 4 +- inc/classes/main/output/class_WebOutput.php | 2 +- .../main/request/class_HttpRequest.php | 37 +- .../main/resolver/class_BaseResolver.php | 34 +- .../local/class_LocalCommandResolver.php | 184 ------ .../local/class_LocalControllerResolver.php | 189 ------ .../resolver/web/class_WebCommandResolver.php | 61 +- .../web/class_WebControllerResolver.php | 34 +- .../main/response/class_HttpResponse.php | 62 +- .../main/template/class_TemplateEngine.php | 158 +++-- inc/classes/main/user/.htaccess | 1 + inc/classes/main/user/class_User.php | 103 +++ .../compressor/class_CompressorChannel.php | 2 +- ...eIOHandler.php => class_FileIoHandler.php} | 10 +- inc/config.php | 84 +-- inc/config/config-hubmaster.php | 40 +- inc/database.php | 6 +- inc/database/lib-local.php | 18 +- inc/file_io.php | 8 +- inc/includes.php | 10 +- inc/language.php | 2 +- inc/loader/class_ClassLoader.php | 10 +- inc/output.php | 2 +- inc/selector.php | 22 +- index.php | 32 +- 85 files changed, 2644 insertions(+), 864 deletions(-) rename inc/classes/{main/resolver/local => exceptions/helper}/.htaccess (100%) create mode 100644 inc/classes/exceptions/helper/class_FormClosedException.php create mode 100644 inc/classes/exceptions/helper/class_FormGroupClosedException.php create mode 100644 inc/classes/exceptions/helper/class_FormOpenedException.php create mode 100644 inc/classes/exceptions/helper/class_InvalidFormNameException.php create mode 100644 inc/classes/exceptions/user/.htaccess create mode 100644 inc/classes/exceptions/user/class_UsernameMissingException.php create mode 100644 inc/classes/interfaces/filter/.htaccess create mode 100644 inc/classes/interfaces/filter/class_Filterable.php create mode 100644 inc/classes/interfaces/user/.htaccess create mode 100644 inc/classes/interfaces/user/class_ManageableUser.php create mode 100644 inc/classes/main/commands/class_ create mode 100644 inc/classes/main/commands/web/class_WebDoFormCommand.php create mode 100644 inc/classes/main/commands/web/class_WebRegisterCommand.php delete mode 100644 inc/classes/main/controller/default/class_LocalDefaultNewsController.php create mode 100644 inc/classes/main/controller/form/.htaccess rename inc/classes/main/controller/{default/class_LocalDefaultController.php => form/class_WebDoFormController.php} (57%) rename inc/classes/main/factories/web/{class_NewsFactory.php => class_WebNewsFactory.php} (91%) create mode 100644 inc/classes/main/filter/.htaccess create mode 100644 inc/classes/main/filter/class_ create mode 100644 inc/classes/main/filter/class_AbstractFilterDecorator.php create mode 100644 inc/classes/main/filter/class_FilterChain.php create mode 100644 inc/classes/main/filter/validator/.htaccess create mode 100644 inc/classes/main/filter/validator/class_UserNameValidatorFilter.php create mode 100644 inc/classes/main/helper/.htaccess create mode 100644 inc/classes/main/helper/class_ create mode 100644 inc/classes/main/helper/class_BaseHelper.php create mode 100644 inc/classes/main/helper/web/.htaccess create mode 100644 inc/classes/main/helper/web/class_WebFormHelper.php rename inc/classes/main/io/{class_FileIOStream.php => class_FileIoStream.php} (96%) delete mode 100644 inc/classes/main/resolver/local/class_LocalCommandResolver.php delete mode 100644 inc/classes/main/resolver/local/class_LocalControllerResolver.php create mode 100644 inc/classes/main/user/.htaccess create mode 100644 inc/classes/main/user/class_User.php rename inc/classes/middleware/io/{class_FileIOHandler.php => class_FileIoHandler.php} (94%) diff --git a/.gitattributes b/.gitattributes index 073ef92f5..8455a4b44 100644 --- a/.gitattributes +++ b/.gitattributes @@ -71,6 +71,11 @@ inc/classes/exceptions/database/local_file/class_SavePathIsEmptyException.php -t inc/classes/exceptions/database/local_file/class_SavePathIsNoDirectoryException.php -text inc/classes/exceptions/database/local_file/class_SavePathReadProtectedException.php -text inc/classes/exceptions/database/local_file/class_SavePathWriteProtectedException.php -text +inc/classes/exceptions/helper/.htaccess -text +inc/classes/exceptions/helper/class_FormClosedException.php -text +inc/classes/exceptions/helper/class_FormGroupClosedException.php -text +inc/classes/exceptions/helper/class_FormOpenedException.php -text +inc/classes/exceptions/helper/class_InvalidFormNameException.php -text inc/classes/exceptions/io/.htaccess -text inc/classes/exceptions/io/class_DirPointerNotOpenedException.php -text inc/classes/exceptions/io/class_FilePointerNotOpenedException.php -text @@ -120,6 +125,8 @@ inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php - inc/classes/exceptions/template/class_UnexpectedTemplateTypeException.php -text inc/classes/exceptions/template/class_UnsupportedTemplateEngineException.php -text inc/classes/exceptions/template/class_ViewHelperNotFoundException.php -text +inc/classes/exceptions/user/.htaccess -text +inc/classes/exceptions/user/class_UsernameMissingException.php -text inc/classes/interfaces/.htaccess -text inc/classes/interfaces/application/.htaccess -text inc/classes/interfaces/application/class_ManageableApplication.php -text @@ -141,6 +148,8 @@ inc/classes/interfaces/debug/.htaccess -text inc/classes/interfaces/debug/class_Debugger.php -text inc/classes/interfaces/extended/.htaccess -text inc/classes/interfaces/extended/class_LimitableObject.php -text +inc/classes/interfaces/filter/.htaccess -text +inc/classes/interfaces/filter/class_Filterable.php -text inc/classes/interfaces/io/.htaccess -text inc/classes/interfaces/io/class_Streamable.php -text inc/classes/interfaces/io/file/.htaccess -text @@ -160,16 +169,21 @@ inc/classes/interfaces/response/class_Responseable.php -text inc/classes/interfaces/template/.htaccess -text inc/classes/interfaces/template/class_CompileableTemplate.php -text inc/classes/interfaces/template/view/class_ViewHelper.php -text +inc/classes/interfaces/user/.htaccess -text +inc/classes/interfaces/user/class_ManageableUser.php -text inc/classes/main/.htaccess -text inc/classes/main/class_ -text inc/classes/main/class_BaseFrameworkSystem.php -text inc/classes/main/class_FrameworkArrayObject.php -text inc/classes/main/commands/.htaccess -text +inc/classes/main/commands/class_ -text inc/classes/main/commands/class_BaseCommand.php -text inc/classes/main/commands/local/.htaccess -text inc/classes/main/commands/local/class_LocalHomeCommand.php -text inc/classes/main/commands/web/.htaccess -text +inc/classes/main/commands/web/class_WebDoFormCommand.php -text inc/classes/main/commands/web/class_WebHomeCommand.php -text +inc/classes/main/commands/web/class_WebRegisterCommand.php -text inc/classes/main/compressor/.htaccess -text inc/classes/main/compressor/class_Bzip2Compressor.php -text inc/classes/main/compressor/class_GzipCompressor.php -text @@ -180,10 +194,10 @@ inc/classes/main/controller/.htaccess -text inc/classes/main/controller/class_ -text inc/classes/main/controller/class_BaseController.php -text inc/classes/main/controller/default/.htaccess -text -inc/classes/main/controller/default/class_LocalDefaultController.php -text -inc/classes/main/controller/default/class_LocalDefaultNewsController.php -text inc/classes/main/controller/default/class_WebDefaultController.php -text inc/classes/main/controller/default/class_WebDefaultNewsController.php -text +inc/classes/main/controller/form/.htaccess -text +inc/classes/main/controller/form/class_WebDoFormController.php -text inc/classes/main/controller/registration/.htaccess -text inc/classes/main/controller/registration/class_DefaultRegistrationController.php -text inc/classes/main/database/.htaccess -text @@ -202,9 +216,20 @@ inc/classes/main/factories/class_BaseFactory.php -text inc/classes/main/factories/objects/.htaccess -text inc/classes/main/factories/objects/class_ObjectFactory.php -text inc/classes/main/factories/web/.htaccess -text -inc/classes/main/factories/web/class_NewsFactory.php -text +inc/classes/main/factories/web/class_WebNewsFactory.php -text +inc/classes/main/filter/.htaccess -text +inc/classes/main/filter/class_ -text +inc/classes/main/filter/class_AbstractFilterDecorator.php -text +inc/classes/main/filter/class_FilterChain.php -text +inc/classes/main/filter/validator/.htaccess -text +inc/classes/main/filter/validator/class_UserNameValidatorFilter.php -text +inc/classes/main/helper/.htaccess -text +inc/classes/main/helper/class_ -text +inc/classes/main/helper/class_BaseHelper.php -text +inc/classes/main/helper/web/.htaccess -text +inc/classes/main/helper/web/class_WebFormHelper.php -text inc/classes/main/io/.htaccess -text -inc/classes/main/io/class_FileIOStream.php -text +inc/classes/main/io/class_FileIoStream.php -text inc/classes/main/io/class_FrameworkDirectoryPointer.php -text inc/classes/main/io/class_FrameworkFileInputPointer.php -text inc/classes/main/io/class_FrameworkFileOutputPointer.php -text @@ -217,9 +242,6 @@ inc/classes/main/request/.htaccess -text inc/classes/main/request/class_HttpRequest.php -text inc/classes/main/resolver/.htaccess -text inc/classes/main/resolver/class_BaseResolver.php -text -inc/classes/main/resolver/local/.htaccess -text -inc/classes/main/resolver/local/class_LocalCommandResolver.php -text -inc/classes/main/resolver/local/class_LocalControllerResolver.php -text inc/classes/main/resolver/web/.htaccess -text inc/classes/main/resolver/web/class_WebCommandResolver.php -text inc/classes/main/resolver/web/class_WebControllerResolver.php -text @@ -227,6 +249,8 @@ inc/classes/main/response/.htaccess -text inc/classes/main/response/class_HttpResponse.php -text inc/classes/main/template/.htaccess -text inc/classes/main/template/class_TemplateEngine.php -text +inc/classes/main/user/.htaccess -text +inc/classes/main/user/class_User.php -text inc/classes/middleware/.htaccess -text inc/classes/middleware/class_BaseMiddleware.php -text inc/classes/middleware/compressor/.htaccess -text @@ -236,7 +260,7 @@ inc/classes/middleware/database/class_DatabaseConnection.php -text inc/classes/middleware/debug/.htaccess -text inc/classes/middleware/debug/class_DebugMiddleware.php -text inc/classes/middleware/io/.htaccess -text -inc/classes/middleware/io/class_FileIOHandler.php -text +inc/classes/middleware/io/class_FileIoHandler.php -text inc/config.php -text inc/config/.htaccess -text inc/config/class_FrameworkConfiguration.php -text diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 94ea19675..466ff6d83 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -185,6 +185,20 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica public final function getMasterTemplate () { return "hub_main"; } + + /** + * 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) { + die("MSG:".$message); + } + } } // [EOF] diff --git a/inc/classes/main/resolver/local/.htaccess b/inc/classes/exceptions/helper/.htaccess similarity index 100% rename from inc/classes/main/resolver/local/.htaccess rename to inc/classes/exceptions/helper/.htaccess diff --git a/inc/classes/exceptions/helper/class_FormClosedException.php b/inc/classes/exceptions/helper/class_FormClosedException.php new file mode 100644 index 000000000..93909118e --- /dev/null +++ b/inc/classes/exceptions/helper/class_FormClosedException.php @@ -0,0 +1,47 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 FormClosedException extends FrameworkException { + /** + * The constructor + * + * @param $classArray Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $classArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Could not add form element %s because form is closed.", + $classArray[0]->__toString(), + $this->getLine(), + $classArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/helper/class_FormGroupClosedException.php b/inc/classes/exceptions/helper/class_FormGroupClosedException.php new file mode 100644 index 000000000..608228de9 --- /dev/null +++ b/inc/classes/exceptions/helper/class_FormGroupClosedException.php @@ -0,0 +1,46 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 FormGroupClosedException extends FrameworkException { + /** + * The constructor + * + * @param $classArray Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $classArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Could not add sub group %s because no form group has been opened before.", + $classArray[0]->__toString(), + $this->getLine(), + $classArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/helper/class_FormOpenedException.php b/inc/classes/exceptions/helper/class_FormOpenedException.php new file mode 100644 index 000000000..e964c7c33 --- /dev/null +++ b/inc/classes/exceptions/helper/class_FormOpenedException.php @@ -0,0 +1,47 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 FormOpenedException extends FrameworkException { + /** + * The constructor + * + * @param $class Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (BaseFrameworkSystem $class, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Form is not yet closed. Close it with method %s::addFormTag() and add no parameters.", + $class->__toString(), + $this->getLine(), + $class->__toString() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/helper/class_InvalidFormNameException.php b/inc/classes/exceptions/helper/class_InvalidFormNameException.php new file mode 100644 index 000000000..85b51371c --- /dev/null +++ b/inc/classes/exceptions/helper/class_InvalidFormNameException.php @@ -0,0 +1,45 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 InvalidFormNameException extends FrameworkException { + /** + * The constructor + * + * @param $class Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (BaseFrameworkSystem $class, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Form name not set.", + $class->__toString(), + $this->getLine() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/io/class_DirPointerNotOpenedException.php b/inc/classes/exceptions/io/class_DirPointerNotOpenedException.php index 060b01709..3292d4bbc 100644 --- a/inc/classes/exceptions/io/class_DirPointerNotOpenedException.php +++ b/inc/classes/exceptions/io/class_DirPointerNotOpenedException.php @@ -25,8 +25,8 @@ class DirPointerNotOpenedException extends FrameworkException { /** * The constructor * - * @param $message Message from the exception - * @param $code Code number for the exception + * @param $path Message from the exception + * @param $code Code number for the exception * @return void */ public function __construct ($path, $code) { diff --git a/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php b/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php index 9c7a8a891..27fe8d1d4 100644 --- a/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php +++ b/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php @@ -3,10 +3,10 @@ * An exception thrown when a file pointer is not opened * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @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 @@ -19,19 +19,19 @@ * 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 . + * along with this program. If not, see . */ class FilePointerNotOpenedException extends FrameworkException { /** * The constructor * - * @param $message Message from the exception + * @param $fqfn Full-qualified file name of (maybe) missing file * @param $code Code number for the exception * @return void */ - public function __construct ($path, $code) { + public function __construct ($fqfn, $code) { // Add a message around the missing class - $message = sprintf("Für die Datei %s konnte kein Pointer initialisiert werden. Möglicherweise ist die Datei nicht lesbar oder fehlt!", $path); + $message = sprintf("Not able to initialize a pointer for the file %s. Maybe the file is missing.", $fqfn); // Call parent constructor parent::__construct($message, $code); diff --git a/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php b/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php index 8a3151cc0..01fd09fa4 100644 --- a/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php +++ b/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php @@ -3,10 +3,11 @@ * An exception thrown when a template variable name is invalid * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @link http://www.ship-simu.org + * @deprecated * * 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 @@ -19,24 +20,24 @@ * 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 . + * along with this program. If not, see . */ class InvalidTemplateVariableNameException extends FrameworkException { /** * The constructor * - * @param $class An array holding our informations - * @param $code Code number for the exception + * @param $classArray An array holding our informations + * @param $code Code number for the exception * @return void */ - public function __construct (BaseFrameworkSystem $class, $code) { + public function __construct (array $classArray, $code) { // Add a message around the missing class - $message = sprintf("[%s:%d] Die im Template %s gefundene Variable %s ist nicht gültig! Gültige Variablennamen sind nur %s.", - $class[0]->__toString(), + $message = sprintf("[%s:%d] The template %s contains an invalid variable called %s. Valid variable names are only %s.", + $classArray[0]->__toString(), $this->getLine(), - basename($class[1]), - $class[2], - $class[3]->readConfig("tpl_valid_var") + basename($classArray[1]), + $classArray[2], + $classArray[3]->readConfig('tpl_valid_var') ); // Call parent constructor diff --git a/inc/classes/exceptions/user/.htaccess b/inc/classes/exceptions/user/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/exceptions/user/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/user/class_UsernameMissingException.php b/inc/classes/exceptions/user/class_UsernameMissingException.php new file mode 100644 index 000000000..8016cf376 --- /dev/null +++ b/inc/classes/exceptions/user/class_UsernameMissingException.php @@ -0,0 +1,46 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 UsernameMissingException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray The non-optional message for the exception + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code = 0) { + // Create the message + $message = sprintf("[%s:%d] Username %s was not found.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Make sure everything is assigned properly + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/application/class_ManageableApplication.php b/inc/classes/interfaces/application/class_ManageableApplication.php index 5bb3dac1b..d1d7267aa 100644 --- a/inc/classes/interfaces/application/class_ManageableApplication.php +++ b/inc/classes/interfaces/application/class_ManageableApplication.php @@ -84,6 +84,15 @@ interface ManageableApplication extends FrameworkInterface { * @return void */ function entryPoint (); + + /** + * Handle the indexed array of fatal messages and puts them out in an + * acceptable fasion + * + * @param $messageList An array of fatal messages + * @return void + */ + function handleFatalMessages (array $messageList); } // [EOF] diff --git a/inc/classes/interfaces/commands/class_Commandable.php b/inc/classes/interfaces/commands/class_Commandable.php index 4b3eaba9f..8b3392df8 100644 --- a/inc/classes/interfaces/commands/class_Commandable.php +++ b/inc/classes/interfaces/commands/class_Commandable.php @@ -23,7 +23,7 @@ */ interface Commandable extends FrameworkInterface { /** - * Executes the given command with given request and response objects + * Executes the 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 diff --git a/inc/classes/interfaces/filter/.htaccess b/inc/classes/interfaces/filter/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/interfaces/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/filter/class_Filterable.php b/inc/classes/interfaces/filter/class_Filterable.php new file mode 100644 index 000000000..bc4bb3075 --- /dev/null +++ b/inc/classes/interfaces/filter/class_Filterable.php @@ -0,0 +1,36 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 . + */ +interface Filterable extends FrameworkInterface { + /** + * 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 + */ + function execute (Requestable $requestInstance, Responseable $responseInstance); +} + +// +?> diff --git a/inc/classes/interfaces/request/class_Requestable.php b/inc/classes/interfaces/request/class_Requestable.php index 08dd5b170..a7b39bf58 100644 --- a/inc/classes/interfaces/request/class_Requestable.php +++ b/inc/classes/interfaces/request/class_Requestable.php @@ -62,6 +62,14 @@ interface Requestable extends FrameworkInterface { * @return $headerValue Value of the header or 'null' if not found */ function getHeader ($headerName); + + /** + * Sets wether the request was valid (default: true) + * + * @param $isValid Wether the request is valid + * @return void + */ + function requestIsValid ($isValid = true); } // diff --git a/inc/classes/interfaces/resolver/class_ControllerResolver.php b/inc/classes/interfaces/resolver/class_ControllerResolver.php index e953ceee2..76ec16a24 100644 --- a/inc/classes/interfaces/resolver/class_ControllerResolver.php +++ b/inc/classes/interfaces/resolver/class_ControllerResolver.php @@ -27,7 +27,7 @@ interface ControllerResolver extends FrameworkInterface { * * @return $controllerInstance A controller instance for the default command */ - function resolveDefaultController (); + function resolveCommandController (); } // diff --git a/inc/classes/interfaces/response/class_Responseable.php b/inc/classes/interfaces/response/class_Responseable.php index 7416b948c..ae9f4ae91 100644 --- a/inc/classes/interfaces/response/class_Responseable.php +++ b/inc/classes/interfaces/response/class_Responseable.php @@ -57,6 +57,15 @@ interface Responseable extends FrameworkInterface { * already sent */ function flushBuffer($force=false); + + /** + * Adds a fatal message id to the response. The added messages can then be + * processed and outputed to the world + * + * @param $messageId The message id we shall add + * @return void + */ + function addFatalMessage ($messageId); } // diff --git a/inc/classes/interfaces/user/.htaccess b/inc/classes/interfaces/user/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/interfaces/user/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/user/class_ManageableUser.php b/inc/classes/interfaces/user/class_ManageableUser.php new file mode 100644 index 000000000..eef4ef82c --- /dev/null +++ b/inc/classes/interfaces/user/class_ManageableUser.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 . + */ +interface ManageableUser extends FrameworkInterface { +} + +// +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index f341fc9d3..1ccb1c2c7 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -219,8 +219,50 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ public final function __call ($methodName, $args) { // Implode all given arguments - $argsString = implode("|", $args); - if (empty($argsString)) $argsString = "NULL"; + $argsString = ""; + if (empty($args)) { + // No arguments + $argsString = "NULL"; + } elseif (is_array($args)) { + // Some arguments are there + foreach ($args as $arg) { + // Check the type + if (is_bool($arg)) { + // Boolean! + if ($arg) $argsString .= "true(bool)"; else $argsString .= "false(bool)"; + } elseif (is_int($arg)) { + // Integer + $argsString .= $arg."(int)"; + } elseif (is_float($arg)) { + // Floating point + $argsString .= $arg."(float)"; + } elseif ($arg instanceof BaseFramework) { + // Own object instance + $argsString .= $arg->__toString()."(Object)"; + } elseif (is_object($arg)) { + // External object + $argsString .= "unknown object(!)"; + } elseif (is_array($arg)) { + // Array + $argsString .= "Array(array)"; + } elseif (is_string($arg)) { + // String + $argsString .= "\"".$arg."\"(string)"; + } else { + // Unknown type (please report!) + $argsString .= $arg."(unknown!)"; + } + + // Add comma + $argsString .= ", "; + } + + // Remove last comma + if (substr($argsString, -2, 1) === ",") $argsString = substr($argsString, 0, -2); + } else { + // Invalid arguments! + $argsString = sprintf("!INVALID:%s!", $args); + } $this->getDebugInstance()->output(sprintf("[%s::%s] Stub! Args: %s", $this->__toString(), @@ -246,16 +288,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Initialize debug instance if (is_null($this->getDebugInstance())) { // Set the debug output system if it is not debug class ;) - $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig("debug_engine"))); + $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_engine'))); } // Initialize web instance if (is_null($this->getWebOutputInstance())) { // Generate the eval() command $eval = sprintf("\$this->setWebOutputInstance(%s::create%s(\"%s\"));", - $this->getConfigInstance()->readConfig("web_engine"), - $this->getConfigInstance()->readConfig("web_engine"), - $this->getConfigInstance()->readConfig("web_content_type") + $this->getConfigInstance()->readConfig('web_engine'), + $this->getConfigInstance()->readConfig('web_engine'), + $this->getConfigInstance()->readConfig('web_content_type') ); // Debug message @@ -273,7 +315,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Set the compressor channel $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s", PATH, - $this->getConfigInstance()->readConfig("compressor_base_path") + $this->getConfigInstance()->readConfig('compressor_base_path') ))); } @@ -732,7 +774,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * * @return $fileIOInstance An instance to the file I/O sub-system */ - protected final function getFileIOInstance () { + protected final function getFileIoInstance () { return $this->fileIOInstance; } @@ -742,7 +784,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @param $fileIOInstance An instance to the file I/O sub-system * @return void */ - public final function setFileIOInstance (FileIOHandler $fileIOInstance) { + public final function setFileIoInstance (FileIoHandler $fileIOInstance) { $this->fileIOInstance = $fileIOInstance; } @@ -797,16 +839,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Generate FQFN for all application templates $fqfn = sprintf("%s%s/%s/%s", PATH, - $this->getConfigInstance()->readConfig("application_path"), + $this->getConfigInstance()->readConfig('application_path'), strtolower($appInstance->getAppShortName()), - $this->getConfigInstance()->readConfig("tpl_base_path") + $this->getConfigInstance()->readConfig('tpl_base_path') ); // Are both instances set? if ($appInstance->getLanguageInstance() === null) { // Invalid language instance throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER); - } elseif ($appInstance->getFileIOInstance() === null) { + } elseif ($appInstance->getFileIoInstance() === null) { // Invalid language instance throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER); } @@ -816,10 +858,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $eval = sprintf("\$tplEngine = %s::create%s( \"%s\", \$appInstance->getLanguageInstance(), - \$appInstance->getFileIOInstance() + \$appInstance->getFileIoInstance() );", - $this->getConfigInstance()->readConfig("tpl_engine"), - $this->getConfigInstance()->readConfig("tpl_engine"), + $this->getConfigInstance()->readConfig('tpl_engine'), + $this->getConfigInstance()->readConfig('tpl_engine'), $fqfn ); @@ -854,10 +896,76 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ public final function debugInstance () { // Generate the output - $content = "
".trim(print_r($this, true))."
"; + $content = sprintf("
%s
", + trim(print_r($this, true)) + ); // Output it - ApplicationEntryPoint::app_die("Debug output:".$content); + ApplicationEntryPoint::app_die(sprintf("%s debug output:%s", $this->__toString(), $content)); + } + + /** + * Output a partial stub message for the caller method + * + * @param $message An optional message to display + * @return void + */ + protected function partialStub ($message = "") { + // Get the backtrace + $backtrace = debug_backtrace(); + + // Generate the class::method string + $methodName = "UnknownClass::unknownMethod"; + if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) { + $methodName = $backtrace[1]['class']."::".$backtrace[1]['function']; + } + + // Construct the full message + $stubMessage = sprintf("[%s:] Partial stub!", + $methodName + ); + + // Is the extra message given? + if (!empty($message)) { + // Then add it as well + $stubMessage .= sprintf(" Message: %s", $message); + } + + // Debug instance is there? + if (!is_null($this->getDebugInstance())) { + // Output stub message + $this->getDebugInstance()->output($stubMessage); + } else { + // Trigger an error + trigger_error($stubMessage."
\n"); + } + } + + /** + * Converts e.g. a command from URL to a valid class by keeping out bad characters + * + * @param $str The string, what ever it is needs to be converted + * @return $className Generated class name + */ + public function convertToClassName ($str) { + $className = ""; + foreach (explode("_", $str) as $strPart) { + $className .= ucfirst(strtolower($strPart)); + } + return $className; + } + + /** + * Outputs a debug backtrace and stops further script execution + * + * @return void + */ + public function debugBacktrace () { + // Sorry, there is no other way getting this nice backtrace + print "
\n";
+		debug_print_backtrace();
+		print "
"; + exit; } } diff --git a/inc/classes/main/commands/class_ b/inc/classes/main/commands/class_ new file mode 100644 index 000000000..cbb5b60fe --- /dev/null +++ b/inc/classes/main/commands/class_ @@ -0,0 +1,73 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 ???Command extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription(""); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public final static function create???Command (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new ???Command(); + + // 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + } +} + +// [EOF] +?> diff --git a/inc/classes/main/commands/web/class_WebDoFormCommand.php b/inc/classes/main/commands/web/class_WebDoFormCommand.php new file mode 100644 index 000000000..e4c230097 --- /dev/null +++ b/inc/classes/main/commands/web/class_WebDoFormCommand.php @@ -0,0 +1,77 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 WebDoFormCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription("Command for handling forms on a centralized place"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public final static function createWebDoFormCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new WebDoFormCommand(); + + // 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Should never be executed... + echo "This should never be executed!
";
+		debug_print_backtrace();
+		die("
Good bye..."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/commands/web/class_WebHomeCommand.php b/inc/classes/main/commands/web/class_WebHomeCommand.php index 9629b9742..0b7e9c41a 100644 --- a/inc/classes/main/commands/web/class_WebHomeCommand.php +++ b/inc/classes/main/commands/web/class_WebHomeCommand.php @@ -32,7 +32,7 @@ class WebHomeCommand extends BaseCommand implements Commandable { parent::__construct(__CLASS__); // Set special description - $this->setObjectDescription("Home-Command"); + $this->setObjectDescription("Command for the "home" page"); // Create unique ID number $this->createUniqueID(); @@ -90,7 +90,7 @@ class WebHomeCommand extends BaseCommand implements Commandable { $templateInstance->assignTemplateWithVariable("footer", "footer"); // Load the home template - $templateInstance->loadWebTemplate("home"); + $templateInstance->loadCodeTemplate("home"); // Assign the home template with the master template as a content ... ;) $templateInstance->assignTemplateWithVariable("home", "content"); @@ -99,9 +99,9 @@ class WebHomeCommand extends BaseCommand implements Commandable { $templateInstance->loadCodeTemplate($masterTemplate); // Set title - $title = ucfirst($requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter"))); + $title = ucfirst($requestInstance->getRequestElement($this->getConfigInstance()->readConfig('command_parameter'))); if (empty($title)) $title = "Home"; - $templateInstance->assignVariable("title", $title); + $templateInstance->assignVariable('title', $title); // ... and all variables. This should be merged together in a pattern // to make things easier. A cache mechanism should be added between diff --git a/inc/classes/main/commands/web/class_WebRegisterCommand.php b/inc/classes/main/commands/web/class_WebRegisterCommand.php new file mode 100644 index 000000000..af1d7488b --- /dev/null +++ b/inc/classes/main/commands/web/class_WebRegisterCommand.php @@ -0,0 +1,121 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 WebRegisterCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription("Command for the registration form"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public final static function createWebRegisterCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new WebRegisterCommand(); + + // 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get the application instance + $appInstance = $this->getResolverInstance()->getApplicationInstance(); + + // Prepare a template instance + $templateInstance = $this->prepareTemplateEngine($appInstance); + + // Assign all the application's data with template variables + $templateInstance->assignApplicationData($appInstance); + + // Load the master template + $masterTemplate = $appInstance->getMasterTemplate(); + + // Load header template + $templateInstance->loadCodeTemplate("header"); + + // Compile and assign it with a variable + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("header", "header"); + + // Load footer template + $templateInstance->loadCodeTemplate("footer"); + + // Compile and assign it with a variable + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("footer", "footer"); + + // Load the register template + $templateInstance->loadCodeTemplate("register"); + + // Assign the register template with the master template as a content ... ;) + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("register", "content"); + + // Load the master template + $templateInstance->loadCodeTemplate($masterTemplate); + + // Set title + $title = ucfirst($requestInstance->getRequestElement($this->getConfigInstance()->readConfig('command_parameter'))); + if (empty($title)) $title = "Register"; + $templateInstance->assignVariable('title', $title); + + // ... and all variables. This should be merged together in a pattern + // to make things easier. A cache mechanism should be added between + // these two calls to cache compiled templates. + $templateInstance->compileVariables(); + + // Get the content back from the template engine and put it in the response class + $templateInstance->transferToResponse($responseInstance); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/compressor/class_Bzip2Compressor.php b/inc/classes/main/compressor/class_Bzip2Compressor.php index 88322b60c..24566b91d 100644 --- a/inc/classes/main/compressor/class_Bzip2Compressor.php +++ b/inc/classes/main/compressor/class_Bzip2Compressor.php @@ -32,7 +32,7 @@ class Bzip2Compressor extends BaseFrameworkSystem implements Compressor { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("BZIP2-Kompressor"); + $this->setObjectDescription("BZIP2 compressor"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/compressor/class_GzipCompressor.php b/inc/classes/main/compressor/class_GzipCompressor.php index 4e95f801f..08b1a6ded 100644 --- a/inc/classes/main/compressor/class_GzipCompressor.php +++ b/inc/classes/main/compressor/class_GzipCompressor.php @@ -32,7 +32,7 @@ class GzipCompressor extends BaseFrameworkSystem implements Compressor { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("GZIP-Kompressor"); + $this->setObjectDescription("GZIP compressor"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/compressor/class_NullCompressor.php b/inc/classes/main/compressor/class_NullCompressor.php index a8a570c58..157dc1a9e 100644 --- a/inc/classes/main/compressor/class_NullCompressor.php +++ b/inc/classes/main/compressor/class_NullCompressor.php @@ -32,7 +32,7 @@ class NullCompressor extends BaseFrameworkSystem implements Compressor { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Null-Kompressor"); + $this->setObjectDescription("Null compressor"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/console/class_ConsoleTools.php b/inc/classes/main/console/class_ConsoleTools.php index 78dc94c90..054c8c7db 100644 --- a/inc/classes/main/console/class_ConsoleTools.php +++ b/inc/classes/main/console/class_ConsoleTools.php @@ -32,7 +32,7 @@ class ConsoleTools extends BaseFrameworkSystem { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Console-Tools"); + $this->setObjectDescription("General console tools"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index f7aea5c30..a2bf81158 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -1,6 +1,8 @@ * @version 0.0.0 @@ -22,6 +24,21 @@ * along with this program. If not, see . */ class BaseController extends BaseFrameworkSystem { + /** + * Instance of a CommandResolver class + */ + private $resolverInstance = null; + + /** + * Pre filter chain instance + */ + private $preFilterChain = null; + + /** + * Post filter chain instance + */ + private $postFilterChain = null; + /** * Protected constructor * @@ -33,6 +50,76 @@ class BaseController extends BaseFrameworkSystem { // Clean up a little $this->removeNumberFormaters(); + $this->removeSystemArray(); + + // Initialize both filter chains + $this->preFilterChain = FilterChain::createFilterChain(); + $this->postFilterChain = FilterChain::createFilterChain(); + } + + /** + * Getter for a command resolver instance + * + * @return $resolverInstance An instance of a command resolver class + */ + public final function getResolverInstance () { + return $this->resolverInstance; + } + + /** + * Setter for a command resolver instance + * + * @param $resolverInstance An instance of a command resolver class + * @return void + */ + public final function setResolverInstance (CommandResolver $resolverInstance) { + $this->resolverInstance = $resolverInstance; + } + + /** + * Adds a filter to the pre filter chain + * + * @param $filterInstance An instance of a filter + * @return void + */ + public function addPreFilter (Filterable $filterInstance) { + // Add the pre filter + $this->preFilterChain->addFilter($filterInstance); + } + + /** + * Adds a filter to the post filter chain + * + * @param $filterInstance An instance of a filter + * @return void + */ + public function addPostFilter (Filterable $filterInstance) { + // Add the post filter + $this->postFilterChain->addFilter($filterInstance); + } + + /** + * Executes all pre filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) { + // Execute all pre filters + $this->preFilterChain->processFilters($requestInstance, $responseInstance); + } + + /** + * Executes all post filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) { + // Execute all post filters + $this->postFilterChain->processFilters($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/default/class_LocalDefaultNewsController.php b/inc/classes/main/controller/default/class_LocalDefaultNewsController.php deleted file mode 100644 index 90d3ec7ba..000000000 --- a/inc/classes/main/controller/default/class_LocalDefaultNewsController.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software - * @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 LocalDefaultNewsController extends BaseController implements Controller { - /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - - /** - * Private constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set part description - $this->setObjectDescription("Standart-Controller mit News-Auflistung"); - - // Create unique ID number - $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); - } - - /** - * Creates an instance of this class - * - * @param $resolverInstance An instance of a command resolver class - * @return $controllerInstance A prepared instance of this class - */ - public final static function createLocalDefaultNewsController (CommandResolver $resolverInstance) { - // Create the instance - $controllerInstance = new LocalDefaultNewsController(); - - // Set the command resolver - $controllerInstance->setResolverInstance($resolverInstance); - - // Return the prepared instance - return $controllerInstance; - } - - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - - /** - * 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 - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); - - // Get the news page variable from the request instance - $newsPage = $requestInstance->getRequestElement("news_page"); - - // Load the news here - $this->loadNews($newsPage); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushResponse(); - } - - /** - * Loads news from the connected database for later usage - * - * @param $newsPage Page of listed news we want to read - * @return void - */ - private function loadNews ($newsPage) { - } -} - -// [EOF] -?> diff --git a/inc/classes/main/controller/default/class_WebDefaultController.php b/inc/classes/main/controller/default/class_WebDefaultController.php index 983089194..9d60e6178 100644 --- a/inc/classes/main/controller/default/class_WebDefaultController.php +++ b/inc/classes/main/controller/default/class_WebDefaultController.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class WebWebDefaultController extends BaseController implements Controller { - /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - /** * Protected constructor * @@ -37,13 +32,10 @@ class WebWebDefaultController extends BaseController implements Controller { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Standart-Controller für alle übrigen Anfragen"); + $this->setObjectDescription("Default controller for all other requests"); // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** @@ -63,16 +55,6 @@ class WebWebDefaultController extends BaseController implements Controller { return $controllerInstance; } - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - /** * Handles the given request and response * @@ -82,7 +64,10 @@ class WebWebDefaultController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + + // This request was valid! :-D + $requestInstance->requestIsValid(); // Execute the command $commandInstance->execute($requestInstance, $responseInstance); diff --git a/inc/classes/main/controller/default/class_WebDefaultNewsController.php b/inc/classes/main/controller/default/class_WebDefaultNewsController.php index ea690a9ec..b8bbc0554 100644 --- a/inc/classes/main/controller/default/class_WebDefaultNewsController.php +++ b/inc/classes/main/controller/default/class_WebDefaultNewsController.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class WebDefaultNewsController extends BaseController implements Controller { - /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - /** * Protected constructor * @@ -37,13 +32,10 @@ class WebDefaultNewsController extends BaseController implements Controller { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Standart-Controller mit News-Auflistung"); + $this->setObjectDescription("Default controller with news"); // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** @@ -63,16 +55,6 @@ class WebDefaultNewsController extends BaseController implements Controller { return $controllerInstance; } - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - /** * Handles the given request and response * @@ -82,11 +64,14 @@ class WebDefaultNewsController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); // Load the news here $this->loadNewsByRequest($requestInstance); + // This request was valid! :-D + $requestInstance->requestIsValid(); + // Execute the command $commandInstance->execute($requestInstance, $responseInstance); @@ -102,7 +87,7 @@ class WebDefaultNewsController extends BaseController implements Controller { */ private function loadNewsByRequest (Requestable $requestInstance) { // Generate a new news object but not carring about which concrete we have - $newsInstance = NewsFactory::createFactoryByRequest($requestInstance)->createNewsObject(); + $newsInstance = WebNewsFactory::createFactoryByRequest($requestInstance)->createNewsObject(); } } diff --git a/inc/classes/main/controller/form/.htaccess b/inc/classes/main/controller/form/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/controller/form/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/controller/default/class_LocalDefaultController.php b/inc/classes/main/controller/form/class_WebDoFormController.php similarity index 57% rename from inc/classes/main/controller/default/class_LocalDefaultController.php rename to inc/classes/main/controller/form/class_WebDoFormController.php index a79243a7d..9ffcf78b5 100644 --- a/inc/classes/main/controller/default/class_LocalDefaultController.php +++ b/inc/classes/main/controller/form/class_WebDoFormController.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,12 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class LocalLocalDefaultController extends BaseController implements Controller { - /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - +class WebDoFormController extends BaseController implements Controller { /** * Private constructor * @@ -37,42 +32,32 @@ class LocalLocalDefaultController extends BaseController implements Controller { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Standart-Controller für alle übrigen Anfragen"); + $this->setObjectDescription("Controller for handling forms"); // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** * Creates an instance of this class * - * @param $resolverInstance An instance of a command resolver class + * @param $resolverInstance An instance of a resolver class * @return $controllerInstance A prepared instance of this class */ - public final static function createLocalDefaultController (CommandResolver $resolverInstance) { + public final static function createWebDoFormController (CommandResolver $resolverInstance) { // Create the instance - $controllerInstance = new LocalDefaultController(); + $controllerInstance = new WebDoFormController(); - // Set the command resolver + // Set resolver instance $controllerInstance->setResolverInstance($resolverInstance); + // We need the controller instance in the resolver class so set it here + $resolverInstance->setControllerInstance($controllerInstance); + // Return the prepared instance return $controllerInstance; } - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - /** * Handles the given request and response * @@ -81,14 +66,27 @@ class LocalLocalDefaultController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); + // Get the "form action" + $formAction = $requestInstance->getRequestElement('form'); + + // Get command instance from resolver + $commandInstance = $this->getResolverInstance()->resolveCommand($formAction); + + // Execute *very* generic pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // Is the request still valid? Post filters shall only be executed of + // the request is valid + if ($requestInstance->isRequestValid()) { + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); + // Execute *very* generic ppost filters + $this->executePostFilters($requestInstance, $responseInstance); + } - // Flush the response out - $responseInstance->flushResponse(); + // Flush the buffer out + $responseInstance->flushBuffer(); } } diff --git a/inc/classes/main/database/classes/class_LocalFileDatabase.php b/inc/classes/main/database/classes/class_LocalFileDatabase.php index 84babfeaf..dbe55ac36 100644 --- a/inc/classes/main/database/classes/class_LocalFileDatabase.php +++ b/inc/classes/main/database/classes/class_LocalFileDatabase.php @@ -55,7 +55,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Dateidatenbankschicht"); + $this->setObjectDescription("Class for local file databases"); // Create unique ID $this->createUniqueID(); @@ -70,7 +70,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * * @param $savePath The local file path string * @param $ioInstance The input/output handler. This - * should be FileIOHandler + * should be FileIoHandler * @return $dbInstance An instance of LocalFileDatabase * @throws SavePathIsEmptyException If the given save path is an * empty string @@ -81,7 +81,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @throws SavePathWriteProtectedException If the save path is write- * protected */ - public final static function createLocalFileDatabase ($savePath, FileIOHandler $ioInstance) { + public final static function createLocalFileDatabase ($savePath, FileIoHandler $ioInstance) { // Get an instance $dbInstance = new LocalFileDatabase(); @@ -101,7 +101,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Set save path and IO instance $dbInstance->setSavePath($savePath); - $dbInstance->setFileIOInstance($ioInstance); + $dbInstance->setFileIoInstance($ioInstance); // Return database instance return $dbInstance; @@ -163,7 +163,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Save the file to disc we don't care here if the path is there, // this must be done in later methods. - $this->getFileIOInstance()->saveFile($fqfn, array($this->getCompressorChannel()->getCompressorExtension(), $serialized)); + $this->getFileIoInstance()->saveFile($fqfn, array($this->getCompressorChannel()->getCompressorExtension(), $serialized)); } /** @@ -263,7 +263,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $this->setLastFile($fqfn); // Get instance for file handler - $inputHandler = $this->getFileIOInstance(); + $inputHandler = $this->getFileIoInstance(); // Try to read from it. This makes it sure that the file is // readable and a valid database file @@ -356,7 +356,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend */ public final function getObjectFromCachedData ($uniqueID) { // Get instance for file handler - $inputHandler = $this->getFileIOInstance(); + $inputHandler = $this->getFileIoInstance(); // Get last file's name and contents $fqfn = $this->repairFQFN($this->getLastFile(), $uniqueID); diff --git a/inc/classes/main/debug/class_DebugConsoleOutput.php b/inc/classes/main/debug/class_DebugConsoleOutput.php index dfcfd36b4..e9be4a591 100644 --- a/inc/classes/main/debug/class_DebugConsoleOutput.php +++ b/inc/classes/main/debug/class_DebugConsoleOutput.php @@ -32,7 +32,7 @@ class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, Output parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Debug-Ausgabe auf Konsole"); + $this->setObjectDescription("Debug output for the console"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/debug/class_DebugErrorLogOutput.php b/inc/classes/main/debug/class_DebugErrorLogOutput.php index 26b099d41..1a1723fd6 100644 --- a/inc/classes/main/debug/class_DebugErrorLogOutput.php +++ b/inc/classes/main/debug/class_DebugErrorLogOutput.php @@ -32,7 +32,7 @@ class DebugErrorLogOutput extends BaseFrameworkSystem implements Debugger, Outpu parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Debug-Ausgabe in error_log()"); + $this->setObjectDescription("Debug output to error_log()"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/debug/class_DebugWebOutput.php b/inc/classes/main/debug/class_DebugWebOutput.php index 17faa1977..0c763e010 100644 --- a/inc/classes/main/debug/class_DebugWebOutput.php +++ b/inc/classes/main/debug/class_DebugWebOutput.php @@ -32,7 +32,7 @@ class DebugWebOutput extends BaseFrameworkSystem implements Debugger, OutputStre parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Debug-Ausgabe auf Konsole"); + $this->setObjectDescription("Debug output for webpages"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/extended/class_ObjectLimits.php b/inc/classes/main/extended/class_ObjectLimits.php index 75925c648..3c23f805a 100644 --- a/inc/classes/main/extended/class_ObjectLimits.php +++ b/inc/classes/main/extended/class_ObjectLimits.php @@ -39,7 +39,7 @@ class ObjectLimits extends BaseFrameworkSystem { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Limitierungsobjekt"); + $this->setObjectDescription("Class for "limiting" other classes. See description for details."); // Create unique ID number $this->createUniqueID(); diff --git a/inc/classes/main/extended/class_SerializationContainer.php b/inc/classes/main/extended/class_SerializationContainer.php index a0980e3d6..7924d4c92 100644 --- a/inc/classes/main/extended/class_SerializationContainer.php +++ b/inc/classes/main/extended/class_SerializationContainer.php @@ -44,7 +44,7 @@ class SerializationContainer extends FrameworkArrayObject { * @return $containerInstance An instance of SerializationContainer * @throws GetterNotFoundException If a getter was not found */ - public final static function createSerializationContainer (ObjectLimits $limitInstance, $object) { + public final static function createSerializationContainer (ObjectLimits $limitInstance, FrameworkInterface $object) { // Get an instance $containerInstance = new SerializationContainer(); diff --git a/inc/classes/main/factories/objects/class_ObjectFactory.php b/inc/classes/main/factories/objects/class_ObjectFactory.php index fd983cac7..5dda5fb90 100644 --- a/inc/classes/main/factories/objects/class_ObjectFactory.php +++ b/inc/classes/main/factories/objects/class_ObjectFactory.php @@ -33,7 +33,7 @@ class ObjectFactory extends BaseFactory { parent::__construct(__CLASS__); // Set object description - $this->setObjectDescription("Objekte-Fabrik"); + $this->setObjectDescription("Simple generic object factory"); } /** diff --git a/inc/classes/main/factories/web/class_NewsFactory.php b/inc/classes/main/factories/web/class_WebNewsFactory.php similarity index 91% rename from inc/classes/main/factories/web/class_NewsFactory.php rename to inc/classes/main/factories/web/class_WebNewsFactory.php index 3da66f9f7..5a604a779 100644 --- a/inc/classes/main/factories/web/class_NewsFactory.php +++ b/inc/classes/main/factories/web/class_WebNewsFactory.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 NewsFactory extends BaseFactory { +class WebNewsFactory extends BaseFactory { /** * Instance of a request class */ @@ -37,7 +37,7 @@ class NewsFactory extends BaseFactory { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("News-Fabrik für Webseiten"); + $this->setObjectDescription("Factory for webpages with news"); } /** @@ -45,14 +45,14 @@ class NewsFactory extends BaseFactory { * request * * @param $requestInstance An instance of a request class - * @return $factoryInstance An instance of a NewsFactory class + * @return $factoryInstance An instance of a WebNewsFactory class */ public final static function createFactoryByRequest (Requestable $requestInstance) { // Generate the new instance - $factoryInstance = new NewsFactory(); + $factoryInstance = new WebNewsFactory(); // Get the element name from configuration - $element = FrameworkConfiguration::getInstance()->readConfig("app_selector_get"); + $element = FrameworkConfiguration::getInstance()->readConfig('app_selector_get'); // Analyze the request, first get the Uni* application name (short one from URL) $appName = $requestInstance->getRequestElement($element); diff --git a/inc/classes/main/filter/.htaccess b/inc/classes/main/filter/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/class_ b/inc/classes/main/filter/class_ new file mode 100644 index 000000000..b79b83d21 --- /dev/null +++ b/inc/classes/main/filter/class_ @@ -0,0 +1,72 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 ???Filter extends BaseFrameworkSystem implements Filterable { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A concrete filter"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function create???Filter () { + // Get a new instance + $filterInstance = new ???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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub("Please implement this method."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/class_AbstractFilterDecorator.php b/inc/classes/main/filter/class_AbstractFilterDecorator.php new file mode 100644 index 000000000..a9a1d4a66 --- /dev/null +++ b/inc/classes/main/filter/class_AbstractFilterDecorator.php @@ -0,0 +1,87 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 . + */ +abstract class AbstractFilterDecorator extends BaseFrameworkSystem implements Filterable { + /** + * The decorated filter instance + */ + private $filterInstance = null; + + /** + * Private constructor + * + * @param $className Name of the real class' name + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Setter for the decorated filter instance + * + * @param $filterInstance An instance of a filter + * @return void + */ + protected final function setFilterInstance (Filterable $filterInstance) { + $this->filterInstance = $filterInstance; + } + + /** + * Getter for the decorated filter instance + * + * @return $filterInstance An instance of a filter + */ + protected final function getFilterInstance () { + return $this->filterInstance; + } + + /** + * Execute the inner filter + * + * @param<->$requestInstance<-->An instance of a request class + * @param<->$responseInstance<->An instance of a response class + * @return void + */ + public final function execute (Requestable $requestInstance, Responseable $responseInstance) { + $this->getFilterInstance()->execute($requestInstance, $responseInstance); + } + + + /** + * Do the execution of the filter + * + * @param<->$requestInstance<-->An instance of a request class + * @param<->$responseInstance<->An instance of a response class + * @return void + */ + abstract public function doExecute (Requestable $requestInstance, Responseable $responseInstance); +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/class_FilterChain.php b/inc/classes/main/filter/class_FilterChain.php new file mode 100644 index 000000000..cf2ff3b3c --- /dev/null +++ b/inc/classes/main/filter/class_FilterChain.php @@ -0,0 +1,93 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 FilterChain extends BaseFrameworkSystem { + /** + * All filters together + */ + private $filters = array(); + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter chain class"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @return $chainInstance An instance of this class + */ + public final static function createFilterChain () { + // Get a new instance + $chainInstance = new FilterChain(); + + // Return the prepared instance + return $chainInstance; + } + + /** + * Add a new filter + * + * @param $filerInstance An instance of a filter class + * @return void + */ + public final function addFilter (Filterable $filterInstance) { + $this->filters[] = $filterInstance; + } + + /** + * Process all added filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function processFilters (Requestable $requestInstance, Responseable $responseInstance) { + // Run all filters + //* DEBUG */ echo "COUNT=".count($this->filters)."
\n"; + foreach ($this->filters as $filterInstance) { + // Execute this filter + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.
\n"; + $filterInstance->execute($requestInstance, $responseInstance); + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.
\n"; + } + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/validator/.htaccess b/inc/classes/main/filter/validator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/filter/validator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php new file mode 100644 index 000000000..1c7c54afc --- /dev/null +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -0,0 +1,131 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for username validation"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createUserNameValidatorFilter () { + // Get a new instance + $filterInstance = new UserNameValidatorFilter(); + + // 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) { + // Get username from request + $userName = $requestInstance->getRequestElement('username'); + + // Is the username set? + if (is_null($userName)) { + // Not found in form so stop the filtering process + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_unset'); + + // Abort here + return false; + } elseif (empty($userName)) { + // Empty field! + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_empty'); + + // Abort here + return false; + } elseif ($this->ifUserNameIsTaken($userName)) { + // Username is already taken + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_taken'); + + // Abort here + return false; + } + } + + /** + * Check wether the username as already been taken + * + * @param $userName Username to check for existence + * @return $alreadyTaken Wether the username has been taken + */ + private function ifUserNameIsTaken ($userName) { + // Default is already taken + $alreadyTaken = true; + + // Try to create a user instance + try { + // If this instance is created then the username *does* exist + $userInstance = User::createUserByUsername($userName); + } catch (UsernameMissingException $e) { + // Okay, this user is missing! + $alreadyTaken = false; + } catch (FrameworkException $e) { + // Something bad happend + ApplicationEntryPoint::app_die(sprintf("Exception: %s", $e->__toString())); + } + + // Return the result + return $alreadyTaken; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/.htaccess b/inc/classes/main/helper/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/helper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/helper/class_ b/inc/classes/main/helper/class_ new file mode 100644 index 000000000..8a1892b8a --- /dev/null +++ b/inc/classes/main/helper/class_ @@ -0,0 +1,53 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 extends BaseHelper { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription(""); + } + + /** + * Creates the helper class + * + * @return $helperInstance A preparedf instance of this class + */ + public final static function createHelper () { + // Get new instance + $helperInstance = new Helper(); + + // Return the prepared instance + return $helperInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/class_BaseHelper.php b/inc/classes/main/helper/class_BaseHelper.php new file mode 100644 index 000000000..02a99e3aa --- /dev/null +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -0,0 +1,90 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 BaseHelper extends BaseFrameworkSystem { + /** + * Template engine instance + */ + private $templateInstance = null; + + /** + * Rendered content created by the helper class + */ + private $content = ""; + + /** + * Private constructor + * + * @param $className Real name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Setter for template engine instances + * + * @param $templateInstance An instance of a template engine class + * @return void + */ + protected final function setTemplateInstance (CompileableTemplate $templateInstance) { + $this->templateInstance = $templateInstance; + } + + /** + * Getter for template engine instances + * + * @return $templateInstance An instance of a template engine class + */ + protected final function getTemplateInstance () { + return $this->templateInstance; + } + + /** + * Add content + * + * @param $newContent New content to add + * @return void + */ + protected final function addContent ($newContent) { + $this->content .= (string) trim($newContent)."\r\n"; + } + + /** + * Getter for content + * + * @return $content The rendered content by this helper + */ + protected final function getContent () { + return $this->content; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/web/.htaccess b/inc/classes/main/helper/web/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/helper/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php new file mode 100644 index 000000000..fb0f1b24d --- /dev/null +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -0,0 +1,589 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 WebFormHelper extends BaseHelper { + /** + * Wether the form tag is opened (keep at false or else your forms will + * never work!) + */ + private $formOpened = false; + + /** + * Name of the form + */ + private $formName = ""; + + /** + * Wether the group is opened or not + */ + private $groupOpened = false; + + /** + * Wether the sub group is opened or not + */ + private $subGroupOpened = false; + + /** + * Name of the sub group + */ + private $subGroupName = ""; + + // Class Constants + const EXCEPTION_FORM_NAME_INVALID = 0xb00; + const EXCEPTION_CLOSED_FORM = 0xb01; + const EXCEPTION_OPENED_FORM = 0xb02; + const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0xb03; + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Helper class for HTML forms"); + + // Create unique ID number + $this->createUniqueID(); + } + + /** + * Creates the helper class with the given template engine instance and form name + * + * @param $templateInstance An instance of a valid template engine + * @param $formName Name of the form + * @param $formId Value for "id" attribute (default: $formName) + * @return $helperInstance A preparedf instance of this class + */ + public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false) { + // Get new instance + $helperInstance = new WebFormHelper(); + + // Set template instance + $helperInstance->setTemplateInstance($templateInstance); + + // Is the form id not set? + if ($formId === false) { + // Use form id from form name + $formId = $formName; + } + + // Create the form + $helperInstance->addFormTag($formName, $formId); + + // Return the prepared instance + return $helperInstance; + } + + /** + * Add the form tag or close it an already opened form tag + * + * @param $formName Name of the form (default: false) + * @param $formId Id of the form (attribute "id"; default: false) + * @return void + * @throws InvalidFormNameException If the form name is invalid (=false) + */ + public function addFormTag ($formName = false, $formId = false) { + // When the form is not yet opened at least form name must be valid + if (($this->formOpened === false) && ($formName === false)) { + // Thrown an exception + throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID); + } + + // Close the form is default + $formContent = ""; + + // Check wether we shall open or close the form + if ($this->formOpened === false) { + // Add HTML code + $formContent = sprintf("
getConfigInstance()->readConfig('form_action'), + $this->getConfigInstance()->readConfig('form_method'), + $this->getConfigInstance()->readConfig('form_target') + ); + + // Is the form id set? + if ($formId !== false) { + // Then add it as well + $formContent .= sprintf(" id=\"%s_form\"", + $formId + ); + } + + // Add close bracket + $formContent .= ">"; + + // Open the form and remeber the form name + $this->formOpened = true; + $this->formName = $formName; + } else { + // Add the hidden field required to identify safely this form + $this->addInputHiddenField('form', $this->formName); + + // Is a group open? + if ($this->groupOpened === true) { + // Then automatically close it here + $this->addFormGroup("", ""); + } + + // @TODO Add some unique PIN here to bypass problems with some browser and/or extensions + // Simply close it + $this->formOpened = false; + } + + // Add it to the content + $this->addContent($formContent); + } + + /** + * Add a text input tag to the form or throw an exception if it is not yet + * opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputTextField ($fieldName, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldName, + $fieldValue + ); + + // And add it maybe with a "li" tag + $this->addContent($inputContent); + } + + /** + * Add a password input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputPasswordField ($fieldName, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldName, + $fieldValue + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a hidden input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputHiddenField ($fieldName, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldValue + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a checkbox input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldChecked Wether the field is checked (defaut: checked) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputCheckboxField ($fieldName, $fieldChecked = true) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Set wether the check box is checked... + $checked = " checked=\"checked\""; + if ($fieldChecked === false) $checked = " "; + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldName, + $checked + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a reset input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $buttonText Text displayed on the button + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputResetButton ($buttonText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "reset"), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $this->formName, + $buttonText + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a reset input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $buttonText Text displayed on the button + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputSubmitButton ($buttonText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "submit"), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $this->formName, + $this->formName, + $buttonText + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a form group or close an already opened and open a new one + * + * @param $groupName Name of the group + * @param $groupText Text including HTML to show above this group + * @return void + * @throws FormClosedException If no form has been opened before + * @throws EmptyVariableException If $groupName is not set + */ + public function addFormGroup ($groupName, $groupText) { + // Is a form opened? + if ($this->formOpened === false) { + // Throw exception here + throw new FormClosedException(array($this, $groupName), self::EXCEPTION_CLOSED_FORM); + } + + // At least the group name should be set + if ((empty($groupName)) && ($this->groupOpened === false)) { + // Throw exception here + throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Initialize content with closing div by default + $content = " \n"; + + // Is this group opened? + if ($this->groupOpened === false) { + // Begin the div/span blocks + $content = sprintf(" +
+ + %s + +
", + $groupName, + $groupName, + $groupName, + $groupText, + $groupName + ); + + // Add the content + $this->addContent($content); + + // Switch the state + $this->groupOpened = true; + } else { + // Is a sub group opened? + if ($this->subGroupOpened === true) { + // Close it here + $this->addFormSubGroup("", ""); + } + + // Add the content + $this->addContent($content); + + // Switch the state + $this->groupOpened = false; + + // All call it again if the group name is not empty + if (!empty($groupName)) { + $this->addFormGroup($groupName, $groupText); + } + } + } + + /** + * Add a form sub group or close an already opened and open a new one or + * throws an exception if no group has been opened before or if the sub + * group name is empty. + * + * @param $subGroupName Name of the group + * @param $subGroupText Text including HTML to show above this group + * @return void + * @throws FormGroupClosedException If no group has been opened before + * @throws EmptyVariableException If $subGroupName is not set + */ + public function addFormSubGroup ($subGroupName, $subGroupText) { + // Is a group opened? + if ($this->groupOpened === false) { + // Throw exception here + throw new FormGroupClosedException(array($this, $subGroupName), self::EXCEPTION_UNEXPECTED_CLOSED_GROUP); + } + + // At least the sub group name should be set + if ((empty($subGroupName)) && ($this->subGroupOpened === false)) { + // Throw exception here + throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Initialize content with closing div by default + $content = "
\n
"; + + // Is this group opened? + if ($this->subGroupOpened === false) { + // Begin the span block + $content = sprintf(" +
+ + %s + +
", + $subGroupName, + $subGroupName, + $subGroupName, + $subGroupText, + $subGroupName + ); + + // Add the content + $this->addContent($content); + + // Switch the state and remeber the name + $this->subGroupOpened = true; + $this->subGroupName = $subGroupName; + } else { + // Add the content + $this->addContent($content); + + // Switch the state + $this->subGroupOpened = false; + + // All call it again if sub group name is not empty + if (!empty($subGroupName)) { + $this->addFormSubGroup($subGroupName, $subGroupText); + } + } + } + + /** + * Add text surrounded by a span block when there is a group opened before + * or else by a div block. + * + * @param $fieldName Field name + * @param $fieldText Text for the field + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addFieldText ($fieldName, $fieldText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Set the block type + $block = "div"; + if ($this->groupOpened === true) $block = "span"; + + // Generate the content + $inputContent = sprintf(" <%s id=\"%s_text\"> + %s + ", + $block, + $fieldName, + $fieldText, + $block + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add text (notes) surrounded by a div block. Still opened groups or sub + * groups will be automatically closed. + * + * @param $formNotes The form notes we shell addd + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addFormNote ($formNotes) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM); + } + + // Is a group open? + if ($this->groupOpened === true) { + // Then automatically close it here + $this->addFormGroup("unknown", ""); + } + + // Generate the content + $inputContent = sprintf("
+ %s +
", + $formNotes + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Checks wether the registration requires a valid email address + * + * @return $required Wether the email address is required + */ + public function ifRegisterRequiresEmailVerification () { + $required = ($this->getConfigInstance()->readConfig('register_requires_email') == "Y"); + return $required; + } + + /** + * Checks wether profile data shall be asked + * + * @return $required Wether profile shall be asked + */ + public function ifRegisterIncludesProfile () { + $required = ($this->getConfigInstance()->readConfig('register_includes_profile') == "Y"); + return $required; + } + + /** + * Checks wether personal data shall be asked + * + * @return $required Wether personal data shall be asked + */ + public function ifRegisterIncludesPersonaData () { + $required = ($this->getConfigInstance()->readConfig('register_personal_data') == "Y"); + return $required; + } + + /** + * Checks wether email addresses can only be once used + * + * @return $isUnique + */ + public function ifEmailMustBeUnique () { + $isUnique = ($this->getConfigInstance()->readConfig('register_email_unique') == "Y"); + return $isUnique; + } + + /** + * Checks wether the specified chat protocol is enabled in this form + * + * @return $required Wether the specified chat protocol is enabled + */ + public function ifChatEnabled ($chatProtocol) { + $required = ($this->getConfigInstance()->readConfig(sprintf("chat_enabled_%s", $chatProtocol)) == "Y"); + return $required; + } + + /** + * Flushs the content out (not yet secured against open forms, etc.!) or + * throw an exception if it is not yet closed + * + * @return void + * @throws FormOpenedException If the form is still open + */ + public function flushContent () { + // Is the form still open? + if ($this->formOpened === true) { + // Throw an exception + throw new FormOpenedException ($this, self::EXCEPTION_OPENED_FORM); + } + + // Send content to template engine + $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent()); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/io/class_FileIOStream.php b/inc/classes/main/io/class_FileIoStream.php similarity index 96% rename from inc/classes/main/io/class_FileIOStream.php rename to inc/classes/main/io/class_FileIoStream.php index c9833465a..ee02a8d2f 100644 --- a/inc/classes/main/io/class_FileIOStream.php +++ b/inc/classes/main/io/class_FileIoStream.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 FileIOStream extends BaseFrameworkSystem implements FileInputStreamer, FileOutputStreamer { +class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, FileOutputStreamer { /** * Protected constructor */ @@ -30,7 +30,7 @@ class FileIOStream extends BaseFrameworkSystem implements FileInputStreamer, Fil parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Universal Datei-Ein-/Ausgabesystem"); + $this->setObjectDescription("Universal file I/O stream system"); // Create unique ID $this->createUniqueID(); @@ -44,11 +44,11 @@ class FileIOStream extends BaseFrameworkSystem implements FileInputStreamer, Fil * Create a file IO stream. This is a class for performing all actions * on files like creating, deleting and loading them. * - * @return $ioInstance An instance of FileIOStream + * @return $ioInstance An instance of FileIoStream */ - public final static function createFileIOStream () { + public final static function createFileIoStream () { // Create new instance - $ioInstance = new FileIOStream(); + $ioInstance = new FileIoStream(); // Return the instance return $ioInstance; diff --git a/inc/classes/main/io/class_FrameworkDirectoryPointer.php b/inc/classes/main/io/class_FrameworkDirectoryPointer.php index 5ad52ed70..f05bfc027 100644 --- a/inc/classes/main/io/class_FrameworkDirectoryPointer.php +++ b/inc/classes/main/io/class_FrameworkDirectoryPointer.php @@ -40,7 +40,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Verzeichnis-Handler"); + $this->setObjectDescription("Helper for handling directories"); // Create unique ID $this->createUniqueID(); diff --git a/inc/classes/main/io/class_FrameworkFileInputPointer.php b/inc/classes/main/io/class_FrameworkFileInputPointer.php index a38b0a3d1..b93c0026b 100644 --- a/inc/classes/main/io/class_FrameworkFileInputPointer.php +++ b/inc/classes/main/io/class_FrameworkFileInputPointer.php @@ -40,7 +40,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Dateiausgabe-Handler"); + $this->setObjectDescription("Handler for reading from files"); // Create unique ID $this->createUniqueID(); diff --git a/inc/classes/main/io/class_FrameworkFileOutputPointer.php b/inc/classes/main/io/class_FrameworkFileOutputPointer.php index 8cc07caaa..350cd7241 100644 --- a/inc/classes/main/io/class_FrameworkFileOutputPointer.php +++ b/inc/classes/main/io/class_FrameworkFileOutputPointer.php @@ -40,7 +40,7 @@ class FrameworkFileOutputPointer extends BaseFrameworkSystem { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Dateiausgabe-Handler"); + $this->setObjectDescription("Handler for writing to files"); // Create unique ID $this->createUniqueID(); diff --git a/inc/classes/main/language/class_LanguageSystem.php b/inc/classes/main/language/class_LanguageSystem.php index 35db75c56..73763676b 100644 --- a/inc/classes/main/language/class_LanguageSystem.php +++ b/inc/classes/main/language/class_LanguageSystem.php @@ -53,7 +53,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Sprachsystem"); + $this->setObjectDescription("Language sub-system"); // Create unique ID number $this->createUniqueID(); @@ -66,7 +66,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { /** * Creates an instance of the class LanguageSystem and prepares it for usage * - * @param $basePath The local base path for all language strings + * @param $basePath The local base path for all language strings * @return $langInstance An instance of LanguageSystem * @throws LanguagePathIsEmptyException If the provided $basePath is empty * @throws InvalidLanguagePathStringException If $basePath is no string @@ -101,7 +101,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { $langInstance->initLanguageStrings(); // Set language code from default config - $langInstance->setLanguageCode(FrameworkConfiguration::getInstance()->readConfig("default_lang")); + $langInstance->setLanguageCode(FrameworkConfiguration::getInstance()->readConfig('default_lang')); // Remember this instance self::$thisInstance = $langInstance; @@ -120,26 +120,37 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { } /** - * Initialize the array-object for all later language strings + * Setter for base path * + * @param $basePath The local base path for all templates * @return void */ - public function initLanguageStrings () { - $this->langStrings = new FrameworkArrayObject(); + protected final function setBasePath ($basePath) { + // And set it + $this->basePath = (string) $basePath; } /** - * Setter for base path + * Setter for language code * - * @param $basePath The local base path for all templates + * @param $langCode The language code for the current application * @return void */ - public final function setBasePath ($basePath) { + protected final function setLanguageCode ($langCode) { // Cast it - $basePath = (string) $basePath; + $langCode = (string) $langCode; - // And set it - $this->basePath = $basePath; + // And set it (only 2 chars) + $this->langCode = substr($langCode, 0, 2); + } + + /** + * Initialize the array-object for all later language strings + * + * @return void + */ + public function initLanguageStrings () { + $this->langStrings = new FrameworkArrayObject(); } /** @@ -152,17 +163,25 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { } /** - * Setter for language code + * Get the plain message from the cache variable for the given message id * - * @param $langCode The language code for the current application - * @return void + * @param $messageId The message id we shall find in the cache variable + * @return $messageText The plain message text */ - public final function setLanguageCode ($langCode) { - // Cast it - $langCode = (string) $langCode; + public function getMessage ($messageId) { + // Default is missing message text + $messageText = sprintf("!%s!", + $messageId + ); + + // Try to look it up in the cache variable + if ($this->langStrings->offsetExists($messageId)) { + // Return the message string + $messageText = $this->langStrings->offsetGet($messageId); + } - // And set it (only 2 chars) - $this->langCode = substr($langCode, 0, 2); + // Return the text + return $messageText; } } diff --git a/inc/classes/main/output/class_ConsoleOutput.php b/inc/classes/main/output/class_ConsoleOutput.php index 5d2b1c135..7eeb854ee 100644 --- a/inc/classes/main/output/class_ConsoleOutput.php +++ b/inc/classes/main/output/class_ConsoleOutput.php @@ -43,7 +43,7 @@ class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Console-Ausgabe-Handler"); + $this->setObjectDescription("Console output class"); // Create an unique ID $this->createUniqueID(); @@ -81,7 +81,7 @@ class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { */ public final static function getInstance() { if (is_null(self::$consoleInstance)) { - $contentType = FrameworkConfiguration::getInstance()->readConfig("web_content_type"); + $contentType = FrameworkConfiguration::getInstance()->readConfig('web_content_type'); self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType); } return self::$consoleInstance; diff --git a/inc/classes/main/output/class_WebOutput.php b/inc/classes/main/output/class_WebOutput.php index a687cea24..b1eecc9f3 100644 --- a/inc/classes/main/output/class_WebOutput.php +++ b/inc/classes/main/output/class_WebOutput.php @@ -38,7 +38,7 @@ class WebOutput extends BaseFrameworkSystem implements OutputStreamer { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Web-Ausgabe-Handler"); + $this->setObjectDescription("Class for web output e.g. XHTML code"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php index 6826d76b7..b95bab1bb 100644 --- a/inc/classes/main/request/class_HttpRequest.php +++ b/inc/classes/main/request/class_HttpRequest.php @@ -27,6 +27,13 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { */ private $requestData = array(); + /** + * Wether this request is valid and can be further processed. The default is + * valid so make sure your intercepting filters sets this attribute to false + * when they need to intercept the data flow. + */ + private $requestIsValid = true; + /** * Protected constructor * @@ -37,7 +44,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("HTTP-Anfrage"); + $this->setObjectDescription("HTTP request"); // Create unique ID number $this->createUniqueID(); @@ -145,6 +152,34 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { // Return the value return $headerValue; } + + /** + * Getter for request method. This getter might be useful for security filters + * + * @return $requestMethod Used request method + */ + public final function getRequestMethod () { + return $_SERVER['REQUEST_METHOD']; + } + + /** + * Sets wether the request was valid (default: true) + * + * @param $isValid Wether the request is valid + * @return void + */ + public final function requestIsValid ($isValid = true) { + $this->requestIsValid = (bool) $isValid; + } + + /** + * Returns wether this request is valid + * + * @return $requestIsValid Wether this request is valid + */ + public final function isRequestValid () { + return $this->requestIsValid; + } } // [EOF] diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php index d947d89e3..9345109a8 100644 --- a/inc/classes/main/resolver/class_BaseResolver.php +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -32,6 +32,11 @@ class BaseResolver extends BaseFrameworkSystem { */ private $commandPrefix = ""; + /** + * A controller instance + */ + private $controllerInstance = null; + /** * Protected constructor * @@ -42,9 +47,29 @@ class BaseResolver extends BaseFrameworkSystem { parent::__construct($class); // Clean up a little + $this->removeNumberFormaters(); $this->removeSystemArray(); } + /** + * Setter for controller instance (this surely breaks a bit the MVC patterm) + * + * @param $controllerInstance An instance of the controller + * @return void + */ + public final function setControllerInstance (Controller $controllerInstance) { + $this->controllerInstance = $controllerInstance; + } + + /** + * Getter for controller instance (this surely breaks a bit the MVC patterm) + * + * @return $controllerInstance An instance of the controller + */ + public final function getControllerInstance () { + return $this->controllerInstance; + } + /** * Setter for command name * @@ -94,7 +119,7 @@ class BaseResolver extends BaseFrameworkSystem { // Now, let us create the full name of the command class $class = sprintf("%s%sCommand", $this->commandPrefix, - ucfirst(strtolower($commandName)) + $this->convertToClassName($commandName) ); // Is this class already loaded? @@ -103,6 +128,13 @@ class BaseResolver extends BaseFrameworkSystem { $isValid = true; } + // Debug output + //echo "----- ".__METHOD__." -----
\n"; + //print($class."
");
+		//debug_print_backtrace();
+		//var_dump($isValid);
+		//print("
"); + // Set command name $this->setCommandName($commandName); diff --git a/inc/classes/main/resolver/local/class_LocalCommandResolver.php b/inc/classes/main/resolver/local/class_LocalCommandResolver.php deleted file mode 100644 index 87e0d69f8..000000000 --- a/inc/classes/main/resolver/local/class_LocalCommandResolver.php +++ /dev/null @@ -1,184 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software - * @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 LocalCommandResolver extends BaseResolver implements CommandResolver { - /** - * Last successfull resolved command - */ - private $lastCommandInstance = ""; - - /** - * Private constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set part description - $this->setObjectDescription("Lokaler Kommandoauflöser"); - - // Create unique ID number - $this->createUniqueID(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - - // Set prefix to "Local" - $this->setCommandPrefix("Local"); - } - - /** - * Creates an instance of a local command resolver with a given default command - * - * @param $defaultCommand The default command we shall execute - * @param $appInstance An instance of a manageable application helper class - * @return $resolverInstance The prepared command resolver instance - * @throws EmptyVariableException Thrown if the default command is not set - * @throws InvalidCommandException Thrown if the default command is invalid - */ - public final static function createLocalCommandResolver ($defaultCommand, ManageableApplication $appInstance) { - // Create the new instance - $resolverInstance = new LocalCommandResolver(); - - // Is the variable $defaultCommand set and the command is valid? - if (empty($defaultCommand)) { - // Then thrown an exception here - throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!$resolverInstance->isCommandValid($defaultCommand)) { - // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); - } - - // Set the application instance - $resolverInstance->setApplicationInstance($appInstance); - - // Return the prepared instance - return $resolverInstance; - } - - /** - * Returns an command instance for a given request class or null if - * MissingArrayElementsException was thrown - * - * @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 resolvCommandByRequest (Requestable $requestInstance) { - // Init variables - $commandName = ""; - $commandInstance = null; - - // Test if the required parameter is set - try { - // This goes fine so let's resolv the command - $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter")); - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig("default_command"); - - // Check if the command is valid - if (!$this->isCommandValid($commandName)) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // 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); - } - - // Set last command - $this->lastCommandInstance = $commandInstance; - } catch (MissingArrayElementsException $e) { - // Just catch it here... - } - - // Return the resolved command 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) { - // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); - - // Init command instance - $commandInstance = null; - - // Create command class name - $class = sprintf("Local%sCommand", - ucfirst(strtolower($commandName)) - ); - - // Is this class loaded? - if (!class_exists($class)) { - // Class not found, so try the default one or throw exception - if ($commandName != $defaultCommand) { - // Try the default command - return $this->loadCommand($defaultCommand); - } else { - // Still not found? - throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); - } - } - - // Initiate the command - $eval = sprintf("\$commandInstance = %s::create%s(\$this);", - $class, - $class - ); - - // Run the command - eval($eval); - - // Is the instance valid? - if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { - // Something is wrong - $commandInstance = null; - } - - // Return the result - return $commandInstance; - } -} - -// [EOF] -?> diff --git a/inc/classes/main/resolver/local/class_LocalControllerResolver.php b/inc/classes/main/resolver/local/class_LocalControllerResolver.php deleted file mode 100644 index 9c942098f..000000000 --- a/inc/classes/main/resolver/local/class_LocalControllerResolver.php +++ /dev/null @@ -1,189 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software - * @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 LocalControllerResolver extends BaseResolver implements ControllerResolver { - /** - * Last successfull resolved controller - */ - private $lastControllerName = ""; - - /** - * Private constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set part description - $this->setObjectDescription(""); - - // Create unique ID number - $this->createUniqueID(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - - // Set prefix to "Local" - $this->setCommandPrefix("Local"); - } - - /** - * Creates an instance of a resolver class with a given command - * - * @param $commandName The default command we shall execute - * @param $appInstance An instance of a manageable application helper class - * @return $resolverInstance The prepared command resolver instance - * @throws EmptyVariableException Thrown if the default command is not set - * @throws InvalidCommandException Thrown if the default command is invalid - */ - public final static function createLocalControllerResolver ($commandName, ManageableApplication $appInstance) { - // Create the new instance - $resolverInstance = new LocalControllerResolver(); - - // 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)) { - // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Set the application instance - $resolverInstance->setApplicationInstance($appInstance); - - // Return the prepared instance - return $resolverInstance; - } - - /** - * Resolves the default controller of the given command - * - * @return $controllerInstance A controller instance for the default - * command - * @throws InvalidCommandException Thrown if $commandName is - * invalid - * @throws InvalidControllerInstanceException Thrown if $commandInstance - * is invalid - */ - public function resolveDefaultController () { - // Init variables - $commandName = ""; - $controllerInstance = null; - - // Try to resolv the command - try { - // Get the command name - $commandName = $this->getCommandName(); - - // Check if the command is valid - if (!$this->isCommandValid($commandName)) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Get the command - $controllerInstance = $this->loadController($commandName); - - // And validate it - if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { - // This command has an invalid instance! - throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER); - } - - // Set last command - $this->lastCommandInstance = $controllerInstance; - } catch (MissingArrayElementsException $e) { - // Just catch it here... - } - - // Return the maybe resolved instance - return $controllerInstance; - } - - /** - * "Loads" a given controller and instances it if not yet cached - * - * @param $commandName A controller name we shall look for - * @return $controllerInstance A loaded controller instance - * @throws DefaultControllerException Thrown if even the default - * controller class is missing (bad!) - */ - private function loadController ($commandName) { - // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); - - // Init controller instance - $controllerInstance = null; - - // Default controller - $class = "LocalDefaultController"; - - // Generate the class name - if ($commandName != $defaultCommand) { - // Create controller class name - $class = sprintf("Local%sController", - ucfirst(strtolower($commandName)) - ); - } elseif ($this->getConfigInstance()->readConfig("home_with_news") == "Y") { - // Yes, display news in home then set default controller with news - $class = "LocalDefaultNewsController"; - } - - // Is this class loaded? - if (!class_exists($class)) { - // Class not found, so try the default one or throw exception - if ($commandName != $defaultCommand) { - // Try the default controller - return $this->loadController($defaultCommand); - } else { - // Still not found? - throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE); - } - } - - // Initiate the controller - $eval = sprintf("\$controllerInstance = %s::create%s(LocalCommandResolver::createLocalCommandResolver(\$commandName, \$this->getApplicationInstance()));", - $class, - $class - ); - - // Run the command - eval($eval); - - // Is the instance valid? - if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { - // Something is wrong - $controllerInstance = null; - } - - // Return the result - return $controllerInstance; - } -} - -// [EOF] -?> diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php index 2ab4e5003..47baef47b 100644 --- a/inc/classes/main/resolver/web/class_WebCommandResolver.php +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -37,15 +37,11 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Lokaler Kommandoauflöser"); + $this->setObjectDescription("Resolver for local web commands"); // Create unique ID number $this->createUniqueID(); - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - // Set prefix to "Web" $this->setCommandPrefix("Web"); } @@ -53,23 +49,23 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { /** * Creates an instance of a Web command resolver with a given default command * - * @param $defaultCommand The default command we shall execute + * @param $commandName The default command we shall execute * @param $appInstance An instance of a manageable application helper class * @return $resolverInstance The prepared command resolver instance * @throws EmptyVariableException Thrown if the default command is not set * @throws InvalidCommandException Thrown if the default command is invalid */ - public final static function createWebCommandResolver ($defaultCommand, ManageableApplication $appInstance) { + public final static function createWebCommandResolver ($commandName, ManageableApplication $appInstance) { // Create the new instance $resolverInstance = new WebCommandResolver(); - // Is the variable $defaultCommand set and the command is valid? - if (empty($defaultCommand)) { + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { // Then thrown an exception here throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!$resolverInstance->isCommandValid($defaultCommand)) { + } elseif (!$resolverInstance->isCommandValid($commandName)) { // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); } // Set the application instance @@ -98,10 +94,10 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { // Test if the required parameter is set try { // This goes fine so let's resolv the command - $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter")); + $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig('command_parameter')); // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig("default_command"); + if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command'); // Check if the command is valid if (!$this->isCommandValid($commandName)) { @@ -128,6 +124,33 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { 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()->readConfig('default_command'); + + // Check if the command is valid + if (!$this->isCommandValid($commandName)) { + // 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 * @@ -138,18 +161,18 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { */ private function loadCommand ($commandName) { // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); + $defaultCommand = $this->getConfigInstance()->readConfig('default_command'); // Init command instance $commandInstance = null; // Create command class name - $class = sprintf("Web%sCommand", - ucfirst(strtolower($commandName)) + $className = sprintf("Web%sCommand", + $this->convertToClassName($commandName) ); // Is this class loaded? - if (!class_exists($class)) { + if (!class_exists($className)) { // Class not found, so try the default one or throw exception if ($commandName != $defaultCommand) { // Try the default command @@ -162,8 +185,8 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { // Initiate the command $eval = sprintf("\$commandInstance = %s::create%s(\$this);", - $class, - $class + $className, + $className ); // Run the command diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php index 16ad0c2c4..9e50d9451 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -23,10 +23,15 @@ */ class WebControllerResolver extends BaseResolver implements ControllerResolver { /** - * Last successfull resolved controller + * Last successfull resolved controller (name) */ private $lastControllerName = ""; + /** + * Last successfull resolved controller (instance) + */ + private $lastControllerInstance = null; + /** * Protected constructor * @@ -37,15 +42,11 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription(""); + $this->setObjectDescription("Resolver for local web controllers"); // Create unique ID number $this->createUniqueID(); - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - // Set prefix to "Web" $this->setCommandPrefix("Web"); } @@ -89,7 +90,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { * @throws InvalidControllerInstanceException Thrown if $commandInstance * is invalid */ - public function resolveDefaultController () { + public function resolveCommandController () { // Init variables $commandName = ""; $controllerInstance = null; @@ -114,8 +115,8 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER); } - // Set last command - $this->lastCommandInstance = $controllerInstance; + // Set last controller + $this->lastControllerInstance = $controllerInstance; } catch (MissingArrayElementsException $e) { // Just catch it here... } @@ -133,8 +134,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { * controller class is missing (bad!) */ private function loadController ($commandName) { + // Debug message + //print("----- ".__METHOD__." -----
");
+		 //debug_print_backtrace();
+		 //print("
"); + // + // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); + $defaultCommand = $this->getConfigInstance()->readConfig('default_command'); // Init controller instance $controllerInstance = null; @@ -146,11 +153,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { if ($commandName != $defaultCommand) { // Create controller class name $class = sprintf("Web%sController", - ucfirst(strtolower($commandName)) + $this->convertToClassName($commandName) ); - } elseif ($this->getConfigInstance()->readConfig("home_with_news") == "Y") { + } elseif ($this->getConfigInstance()->readConfig('home_with_news') == "Y") { // Yes, display news in home then set default controller with news $class = "WebDefaultNewsController"; + } else { + // No nes at "home" page + $class = "WebDefaultController"; } // Is this class loaded? diff --git a/inc/classes/main/response/class_HttpResponse.php b/inc/classes/main/response/class_HttpResponse.php index 8172191ac..52ad2a76d 100644 --- a/inc/classes/main/response/class_HttpResponse.php +++ b/inc/classes/main/response/class_HttpResponse.php @@ -45,6 +45,11 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { */ private $templateEngine = null; + /** + * Fatal resolved messages from filters and so on + */ + private $fatalMessages = array(); + /** * Protected constructor * @@ -55,7 +60,7 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("HTTP-Antwort"); + $this->setObjectDescription("HTTP response"); // Create unique ID number $this->createUniqueID(); @@ -75,6 +80,9 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { // Get a new instance $responseInstance = new HttpResponse(); + // Set the application instance + $responseInstance->setApplicationInstance($appInstance); + // Initialize the template engine here $responseInstance->initTemplateEngine($appInstance); @@ -103,6 +111,15 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { $this->responseHeaders[$name] = $value; } + /** + * Reset the header array + * + * @return void + */ + public final function resetResponseHeaders () { + $this->responseHeaders = array(); + } + /** * "Writes" data to the response body * @@ -113,6 +130,16 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { $this->responseBody .= $output; } + /** + * Sets the response body to something new + * + * @param $output Output we shall sent in the HTTP response + * @return void + */ + public function setReponseBody ($output) { + $this->responseBody = $output; + } + /** * Flushs the cached HTTP response to the outer world * @@ -128,7 +155,7 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); } elseif (!headers_sent()) { // Send headers out - header("HTTP/1.0 {$this->responseStatus}"); + header("HTTP/1.1 {$this->responseStatus}"); // Used later $now = gmdate('D, d M Y H:i:s') . ' GMT'; @@ -147,10 +174,21 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { } } - // Flush the output to the world - $this->getWebOutputInstance()->output($this->responseBody); - $this->reponseBody = ""; - $this->responseHeaders = array(); + // Are there some error messages? + if (count($this->fatalMessages) == 0) { + // Flush the output to the world + $this->getWebOutputInstance()->output($this->responseBody); + } else { + // Display all error messages + $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages); + + // Send the error messages out to the world + $this->getWebOutputInstance()->output($this->responseBody); + } + + // Clear response header and body + $this->setReponseBody(""); + $this->resetResponseHeaders(); } /** @@ -171,6 +209,18 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { public final function getTemplateEngine () { return $this->templateEngine; } + + /** + * Adds a fatal message id to the response. The added messages can then be + * processed and outputed to the world + * + * @param $messageId The message id we shall add + * @return void + */ + public final function addFatalMessage ($messageId) { + // Adds the resolved message id to the fatal message list + $this->fatalMessages[] = $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId); + } } // [EOF] diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index 4c1500625..412d26ac4 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -123,7 +123,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Template-Engine"); + $this->setObjectDescription("Web template engine"); // Create unique ID number $this->createUniqueID(); @@ -138,7 +138,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * * @param $basePath The local base path for all templates * @param $langInstance An instance of LanguageSystem (default) - * @param $ioInstance An instance of FileIOHandler (default, middleware!) + * @param $ioInstance An instance of FileIoHandler (default, middleware!) * @return $tplInstance An instance of TemplateEngine * @throws BasePathIsEmptyException If the provided $basePath is empty * @throws InvalidBasePathStringException If $basePath is no string @@ -147,7 +147,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * @throws BasePathReadProtectedException If $basePath is * read-protected */ - public final static function createTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIOHandler $ioInstance) { + public final static function createTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) { // Get a new instance $tplInstance = new TemplateEngine(); @@ -177,14 +177,14 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Set the language and IO instances $tplInstance->setLanguageInstance($langInstance); - $tplInstance->setFileIOInstance($ioInstance); + $tplInstance->setFileIoInstance($ioInstance); // Set template extensions - $tplInstance->setRawTemplateExtension($cfgInstance->readConfig("raw_template_extension")); - $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig("code_template_extension")); + $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension')); + $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension')); // Absolute output path for compiled templates - $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig("compile_output_path")); + $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig('compile_output_path')); // Return the prepared instance return $tplInstance; @@ -518,7 +518,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate $ext = $this->getRawTemplateExtension(); // If we shall load a code-template we need to switch the file extension - if ($this->getTemplateType() == $this->getConfigInstance()->readConfig("code_template_type")) { + if ($this->getTemplateType() == $this->getConfigInstance()->readConfig('code_template_type')) { // Switch over to the code-template extension $ext = $this->getCodeTemplateExtension(); } @@ -548,7 +548,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ private function loadRawTemplateData ($fqfn) { // Get a input/output instance from the middleware - $ioInstance = $this->getFileIOInstance(); + $ioInstance = $this->getFileIoInstance(); // Validate the instance if (is_null($ioInstance)) { @@ -596,9 +596,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * * @param $rawData The raw template data we shall analyze * @return void - * @throws InvalidTemplateVariableNameException If a variable name - * in a template is - * invalid */ private function extractVariablesFromRawData ($rawData) { // Cast to string @@ -611,12 +608,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) { // Initialize all missing variables foreach ($variableMatches[3] as $key=>$var) { - // Is the variable name valid? - if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config")) { - // Invalid variable name - throw new InvalidTemplateVariableNameException(array($this, $this->getLastTemplate(), $variableMatches[1][$key], $this->getConfigInstance()), self::EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR); - } - // Try to assign it, empty strings are being ignored $this->assignTemplateVariable($variableMatches[1][$key], $var); } @@ -651,24 +642,24 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // RECURSIVE PROTECTION! BE CAREFUL HERE! if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) { - // Then try to search for code-templates first - try { - // Load the code template and remember it's contents - $this->loadCodeTemplate($template); - $this->loadedRawData[$template] = $this->getRawTemplateData(); + // Template not found, but maybe variable assigned? + if ($this->isVariableAlreadySet($template) !== false) { + // Use that content here + $this->loadedRawData[$template] = $this->readVariable($template); - // Remember this template for recursion detection - // RECURSIVE PROTECTION! + // Recursive protection: $this->loadedTemplates[] = $template; - } catch (FilePointerNotOpenedException $e) { - // Template not found, but maybe variable assigned? - if ($this->isVariableAlreadySet($template) !== false) { - // Use that content here - $this->loadedRawData[$template] = $this->readVariable($template); - - // Recursive protection: + } else { + // Then try to search for code-templates + try { + // Load the code template and remember it's contents + $this->loadCodeTemplate($template); + $this->loadedRawData[$template] = $this->getRawTemplateData(); + + // Remember this template for recursion detection + // RECURSIVE PROTECTION! $this->loadedTemplates[] = $template; - } else { + } catch (FilePointerNotOpenedException $e) { // Even this is not done... :/ $this->rawTemplates[] = $template; } @@ -914,7 +905,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function loadWebTemplate ($template) { // Set template type - $this->setTemplateType($this->getConfigInstance()->readConfig("web_template_type")); + $this->setTemplateType($this->getConfigInstance()->readConfig('web_template_type')); // Load the special template $this->loadTemplate($template); @@ -929,7 +920,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function loadEmailTemplate ($template) { // Set template type - $this->setTemplateType($this->getConfigInstance()->readConfig("email_template_type")); + $this->setTemplateType($this->getConfigInstance()->readConfig('email_template_type')); // Load the special template $this->loadTemplate($template); @@ -944,7 +935,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function loadCodeTemplate ($template) { // Set template type - $this->setTemplateType($this->getConfigInstance()->readConfig("code_template_type")); + $this->setTemplateType($this->getConfigInstance()->readConfig('code_template_type')); // Load the special template $this->loadTemplate($template); @@ -957,7 +948,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function compileVariables () { // Initialize the $content array - $validVar = $this->getConfigInstance()->readConfig("tpl_valid_var"); + $validVar = $this->getConfigInstance()->readConfig('tpl_valid_var'); $dummy = array(); // Iterate through all variables @@ -982,22 +973,64 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate unset($idx); unset($currVariable); - // Finalize the compilation of template variables - $this->finalizeVariableCompilation(); + // Run the compilation twice to get content from helper classes in + $cnt = 0; + while ($cnt < 3) { + // Finalize the compilation of template variables + $this->finalizeVariableCompilation(); - // Prepare the eval() command for comiling the template - $eval = sprintf("\$result = \"%s\";", - addslashes($this->getRawTemplateData()) - ); + // Prepare the eval() command for comiling the template + $eval = sprintf("\$result = \"%s\";", + addslashes($this->getRawTemplateData()) + ); - // Debug message - if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", - $this->__toString(), - htmlentities($eval) - )); + // This loop does remove the backslashes (\) in PHP parameters + // @TODO Make this some nicer... + while (strpos($eval, ""))); + $evalMiddle = stripslashes($evalMiddle); + + // Remove the middle part from right one + $evalRight = substr($evalRight, (strpos($evalRight, "?>") + 2)); + + // And put all together + $eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight); + } // END - while + + // Prepare PHP code for eval() command + $eval = str_replace( + "<%php", "\";", + str_replace( + "%>", "\$result .= \"", $eval + ) + ); + + // Debug message + if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", + $this->__toString(), + htmlentities($eval) + )); + + // Run the constructed command. This will "compile" all variables in + eval($eval); - // Run the constructed command. This will "compile" all variables in - eval($eval); + // Set raw template data + $this->setRawTemplateData($result); + $cnt++; + } // Set the new content $this->setCompiledData($result); @@ -1008,15 +1041,15 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * * @return void * @throws UnexpectedTemplateTypeException If the template type is - * not "code" + * not "code" * @throws InvalidArrayCountException If an unexpected array - * count has been found + * count has been found */ public final function compileTemplate () { // We will only work with template type "code" from configuration - if ($this->getTemplateType() != $this->getConfigInstance()->readConfig("code_template_type")) { + if ($this->getTemplateType() != $this->getConfigInstance()->readConfig('code_template_type')) { // Abort here - throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig("code_template_type")), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); + throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig('code_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); } // END - if // Get the raw data. @@ -1158,6 +1191,23 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Get the content and set it in the response class $responseInstance->writeToBody($this->getCompiledData()); } + + /** + * Assigns all the application data with template variables + * + * @param $appInstance A manageable application instance + * @return void + */ + public function assignApplicationData (ManageableApplication $appInstance) { + // Get long name and assign it + $this->assignVariable("app_full_name" , $appInstance->getAppName()); + + // Get short name and assign it + $this->assignVariable("app_short_name", $appInstance->getAppShortName()); + + // Get version number and assign it + $this->assignVariable("app_version" , $appInstance->getAppVersion()); + } } // [EOF] diff --git a/inc/classes/main/user/.htaccess b/inc/classes/main/user/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/user/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php new file mode 100644 index 000000000..53e8b46ef --- /dev/null +++ b/inc/classes/main/user/class_User.php @@ -0,0 +1,103 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 User extends BaseFrameworkSystem implements ManageableUser { + /** + * Username + */ + private $username = ""; + + // Exceptions + const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; + + /** + * Private constructor + * + * @return void + */ + protected function __construct ($class = "") { + // Is the class name empty? Then this is not a specialized user class + if (empty($class)) $class = __CLASS__; + + // Call parent constructor + parent::__construct($class); + + // Set part description + $this->setObjectDescription("Generic user class"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this user class by a provided username. This + * factory method will check if the username is already taken and if not + * so it will throw an exception. + * + * @param $username Username we need a class instance for + * @return $userInstance An instance of this user class + * @throws UsernameMissingException If the username does not exist + */ + public final static function createUserByUsername ($userName) { + // Get a new instance + $userInstance = new User(); + + // Set the username + $userInstance->setUsername($userName); + + // Check if the username exists + if (!$userInstance->ifUsernameExists()) { + // Throw an exception here + throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND); + } + + // Return the instance + return $userInstance; + } + + /** + * Setter for username + * + * @param $userName The username to set + * @return void + */ + protected final function setUsername ($userName) { + $this->userNane = $userName; + } + + /** + * Getter for username + * + * @return $userName The username to set + */ + public final function getUsername () { + return $this->userNane; + } +} + +// [EOF] +?> diff --git a/inc/classes/middleware/compressor/class_CompressorChannel.php b/inc/classes/middleware/compressor/class_CompressorChannel.php index fd04ac118..1b33041fd 100644 --- a/inc/classes/middleware/compressor/class_CompressorChannel.php +++ b/inc/classes/middleware/compressor/class_CompressorChannel.php @@ -55,7 +55,7 @@ class CompressorChannel extends BaseMiddleware { // Read all directories but no sub directories while ($dir = $dirPointer->readDirectoryExcept(array("..", ".", ".htaccess"))) { // Is this a class file? - if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == FrameworkConfiguration::getInstance()->readConfig("php_extension"))) { + if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == FrameworkConfiguration::getInstance()->readConfig('php_extension'))) { // Get the compressor's name. That's why you must name // your files like your classes and also that's why you // must keep on class in one file. diff --git a/inc/classes/middleware/io/class_FileIOHandler.php b/inc/classes/middleware/io/class_FileIoHandler.php similarity index 94% rename from inc/classes/middleware/io/class_FileIOHandler.php rename to inc/classes/middleware/io/class_FileIoHandler.php index 8c7a47aa9..c41f7cb2d 100644 --- a/inc/classes/middleware/io/class_FileIOHandler.php +++ b/inc/classes/middleware/io/class_FileIoHandler.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class FileIOHandler extends BaseMiddleware { +class FileIoHandler extends BaseMiddleware { /** * The *real* file input class we shall use for reading data */ @@ -67,13 +67,13 @@ class FileIOHandler extends BaseMiddleware { * * @return $ioInstance A prepared instance of FilIOHandler */ - public final static function createFileIOHandler () { + public final static function createFileIoHandler () { // Get instance - $ioHandler = new FileIOHandler(); + $ioHandler = new FileIoHandler(); // Set the *real* file IO instances (both the same) - $ioHandler->setInputStream(FileIOStream::createFileIOStream()); - $ioHandler->setOutputStream(FileIOStream::createFileIOStream()); + $ioHandler->setInputStream(FileIoStream::createFileIoStream()); + $ioHandler->setOutputStream(FileIoStream::createFileIoStream()); // Return instance return $ioHandler; diff --git a/inc/config.php b/inc/config.php index 9b307c07c..d5622f3cb 100644 --- a/inc/config.php +++ b/inc/config.php @@ -25,16 +25,19 @@ */ // Load the class from inc/config direktory -@require_once(dirname(__FILE__) . "/config/class_FrameworkConfiguration.php"); +@require_once(dirname(__FILE__) . '/config/class_FrameworkConfiguration.php'); // Get a new configuration instance $cfg = FrameworkConfiguration::createFrameworkConfiguration(); // CFG: SERVER-PATH -$cfg->definePath(dirname(dirname(__FILE__)) . "/"); // DON'T MISS THE TRAILING SLASH!!! +$cfg->definePath(dirname(dirname(__FILE__)) . '/'); // DON'T MISS THE TRAILING SLASH!!! // CFG: DATABASE-TYPE -$cfg->defineDatabaseType("local"); +$cfg->defineDatabaseType('local'); + +// CFG: LOCAL-DB-PATH +$cfg->setConfigEntry('local_db_path', 'db/'); // CFG: TIME-ZONE $cfg->setDefaultTimezone("Europe/Berlin"); @@ -43,106 +46,103 @@ $cfg->setDefaultTimezone("Europe/Berlin"); $cfg->setMagicQuotesRuntime(false); // CFG: PHP-SCRIPT-EXTENSION -$cfg->setConfigEntry("php_extension", ".php"); +$cfg->setConfigEntry('php_extension', ".php"); // CFG: CLASS-PREFIX -$cfg->setConfigEntry("class_prefix", "class_"); +$cfg->setConfigEntry('class_prefix', "class_"); // CFG: CLASS-SUFFIX -$cfg->setConfigEntry("class_suffix", ".php"); +$cfg->setConfigEntry('class_suffix', ".php"); // CFG: RAW-TEMPLATE-EXTENSION -$cfg->setConfigEntry("raw_template_extension", ".tpl"); +$cfg->setConfigEntry('raw_template_extension', ".tpl"); // CFG: CODE-TEMPLATE-EXTENSION -$cfg->setConfigEntry("code_template_extension", ".ctp"); +$cfg->setConfigEntry('code_template_extension', ".ctp"); // CFG: SELECTOR-GET -$cfg->setConfigEntry("app_selector_get", "app"); +$cfg->setConfigEntry('app_selector_get', "app"); + +// CFG: SELECTOR-PATH +$cfg->setConfigEntry('selector_path', "selector"); // CFG: APPLICATION-HELPER -$cfg->setConfigEntry("app_helper_class", "ApplicationHelper"); +$cfg->setConfigEntry('app_helper_class', "ApplicationHelper"); -// CFG: SELECTOR-PATH -$cfg->setConfigEntry("selector_path", "selector"); +// CFG: LAUNCH-METHOD +$cfg->setConfigEntry('entry_method', "entryPoint"); // CFG: TEMPLATE-BASE-PATH -$cfg->setConfigEntry("tpl_base_path", "templates/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('tpl_base_path', "templates/"); // DON'T MISS THE TRAILING SLASH! // CFG: LANGUAGE-BASE-PATH -$cfg->setConfigEntry("lang_base_path", "inc/language/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('lang_base_path', "inc/language/"); // DON'T MISS THE TRAILING SLASH! // CFG: COMPRESSOR-BASE-PATH -$cfg->setConfigEntry("compressor_base_path", "inc/classes/main/compressor/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('compressor_base_path', "inc/classes/main/compressor/"); // DON'T MISS THE TRAILING SLASH! // CFG: APPLICATION-PATH -$cfg->setConfigEntry("application_path", "application"); +$cfg->setConfigEntry('application_path', "application"); // CFG: COMPILE-OUTPUT-PATH -$cfg->setConfigEntry("compile_output_path", "templates/_compiled/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('compile_output_path', "templates/_compiled/"); // DON'T MISS THE TRAILING SLASH! // CFG: TEMPLATE-ENGINE -$cfg->setConfigEntry("tpl_engine", "TemplateEngine"); +$cfg->setConfigEntry('tpl_engine', "TemplateEngine"); // CFG: DEBUG-ENGINE -$cfg->setConfigEntry("debug_engine", "DebugWebOutput"); +$cfg->setConfigEntry('debug_engine', "DebugWebOutput"); // CFG: DEFAULT-LANGUAGE -$cfg->setConfigEntry("default_lang", "de"); // A two-char language string: de for german, en for english and so on +$cfg->setConfigEntry('default_lang', "de"); // A two-char language string: de for german, en for english and so on // CFG: WEB-TEMPLATE-TYPE -$cfg->setConfigEntry("web_template_type", "html"); +$cfg->setConfigEntry('web_template_type', "html"); // CFG: EMAIL-TEMPLATE-TYPE -$cfg->setConfigEntry("email_template_type", "emails"); +$cfg->setConfigEntry('email_template_type', "emails"); // CFG: CODE-TEMPLATE-TYPE -$cfg->setConfigEntry("code_template_type", "code"); +$cfg->setConfigEntry('code_template_type', "code"); // CFG: WEB-ENGINE -$cfg->setConfigEntry("web_engine", "WebOutput"); +$cfg->setConfigEntry('web_engine', "WebOutput"); // CFG: SELECTOR-TEMPLATE-PREFIX -$cfg->setConfigEntry("tpl_selector_prefix", "selector"); +$cfg->setConfigEntry('tpl_selector_prefix', "selector"); // CFG: WEB-CONTENT-TYPE -$cfg->setConfigEntry("web_content_type", "text/html"); +$cfg->setConfigEntry('web_content_type', "text/html"); // CFG: VALID-TEMPLATE-VARIABLE -$cfg->setConfigEntry("tpl_valid_var", "content"); +$cfg->setConfigEntry('tpl_valid_var', "content"); // CFG: META-AUTHOR -$cfg->setConfigEntry("meta_author", "Roland Häder"); +$cfg->setConfigEntry('meta_author', "Roland Häder"); // CFG: META-PUBLISHER -$cfg->setConfigEntry("meta_publisher", "Roland Häder"); +$cfg->setConfigEntry('meta_publisher', "Roland Häder"); // CFG: META-KEYWORDS -$cfg->setConfigEntry("meta_keywords", "test,test,test"); +$cfg->setConfigEntry('meta_keywords', "test,test,test"); // CFG: META-DESCRIPTION -$cfg->setConfigEntry("meta_description", "A lame description for an application framework"); - -// CFG: LAUNCH-METHOD -$cfg->setConfigEntry("entry_method", "entryPoint"); +$cfg->setConfigEntry('meta_description', "A lame description for an application framework"); // CFG: SELECTOR-MAIN-TEMPLATE -$cfg->setConfigEntry("selector_main_tpl", "selector_main"); +$cfg->setConfigEntry('selector_main_tpl', "selector_main"); // CFG: SELECTOR-APPS-TEMPLATE -$cfg->setConfigEntry("selector_apps_tpl", "selector_apps"); +$cfg->setConfigEntry('selector_apps_tpl', "selector_apps"); // CFG: SELECTOR-NAME -$cfg->setConfigEntry("selector_name", "selector"); +$cfg->setConfigEntry('selector_name', "selector"); // CFG: DEFAULT-APPLICATION -$cfg->setConfigEntry("default_application", "selector"); +$cfg->setConfigEntry('default_application', "selector"); // CFG: VERBOSE-LEVEL -$cfg->setConfigEntry("verbose_level", 0); - -// CFG: COMMAND-PARAMETER -$cfg->setConfigEntry("command_parameter", "page"); +$cfg->setConfigEntry('verbose_level', 0); // [EOF] ?> diff --git a/inc/config/config-hubmaster.php b/inc/config/config-hubmaster.php index 1ec81dfae..0c59d29df 100644 --- a/inc/config/config-hubmaster.php +++ b/inc/config/config-hubmaster.php @@ -25,64 +25,64 @@ $cfg = FrameworkConfiguration::getInstance(); // CFG: HUB-LISTEN-ADDR -$cfg->setConfigEntry("hub_listen_addr", "0.0.0.0"); +$cfg->setConfigEntry('hub_listen_addr', "0.0.0.0"); // CFG: HUB-LISTEN-PORT (zero = auto-choose) -$cfg->setConfigEntry("hub_listen_port", 9060); +$cfg->setConfigEntry('hub_listen_port', 9060); // CFG: HUB-MAX-AUTH-TRIES -$cfg->setConfigEntry("hub_max_auth_tries", 3); +$cfg->setConfigEntry('hub_max_auth_tries', 3); // CFG: HUB-MSG-AUTH-TRIES -$cfg->setConfigEntry("hub_msg_auth_tries", "AUTH_MAX_TRIES"); +$cfg->setConfigEntry('hub_msg_auth_tries', "AUTH_MAX_TRIES"); // CFG: HUB-MSG-SPOOFING -$cfg->setConfigEntry("hub_msg_spoofing", "SPOOFING"); +$cfg->setConfigEntry('hub_msg_spoofing', "SPOOFING"); // CFG: HUB-MSG-AUTH-REPLY -$cfg->setConfigEntry("hub_msg_auth_reply_timeout", "TIMEOUT_AUTH"); +$cfg->setConfigEntry('hub_msg_auth_reply_timeout', "TIMEOUT_AUTH"); // CFG: HUB-MSG-BYE -$cfg->setConfigEntry("hub_msg_bye", "BYE"); +$cfg->setConfigEntry('hub_msg_bye', "BYE"); // CFG: HUB-MASTER-IP -$cfg->setConfigEntry("hub_master_ip", "192.168.1.17"); +$cfg->setConfigEntry('hub_master_ip', "192.168.1.17"); // CFG: HUB-MASTER-PORT -$cfg->setConfigEntry("hub_master_port", 9060); +$cfg->setConfigEntry('hub_master_port', 9060); // CFG: HUB-AUTH-REQUEST -$cfg->setConfigEntry("hub_auth_request", "AUTH"); +$cfg->setConfigEntry('hub_auth_request', "AUTH"); // CFG: HUB-AUTH-REQUEST-TIMEOUT (5 seconds for whole auth procedure shall be fine) -$cfg->setConfigEntry("hub_auth_request_timeout", 5); +$cfg->setConfigEntry('hub_auth_request_timeout', 5); // CFG: HUB-PEER-HELLO -$cfg->setConfigEntry("hub_peer_hello", "HELLO"); +$cfg->setConfigEntry('hub_peer_hello', "HELLO"); // CFG: HUB-HELLO-REPLY -$cfg->setConfigEntry("hub_hello_reply", "ELHO"); +$cfg->setConfigEntry('hub_hello_reply', "ELHO"); // CFG: HUB-HELLO-TIMEOUT -$cfg->setConfigEntry("hub_hello_timeout", 30); +$cfg->setConfigEntry('hub_hello_timeout', 30); // CFG: HUB-HELLO-RETRIES -$cfg->setConfigEntry("hub_hello_retires", 3); +$cfg->setConfigEntry('hub_hello_retires', 3); // CFG: HUB-PEER-PING -$cfg->setConfigEntry("hub_peer_ping", "PING"); +$cfg->setConfigEntry('hub_peer_ping', "PING"); // CFG: HUB-PING-REPLY -$cfg->setConfigEntry("hub_ping_reply", "PONG"); +$cfg->setConfigEntry('hub_ping_reply', "PONG"); // CFG: HUB-PING-TIMEOUT -$cfg->setConfigEntry("hub_ping_timeout", 10); +$cfg->setConfigEntry('hub_ping_timeout', 10); // CFG: HUB-PING-MAXDROPS -$cfg->setConfigEntry("hub_ping_maxdrops", 3); +$cfg->setConfigEntry('hub_ping_maxdrops', 3); // CFG: HUB-PEER-MISS-PONG -$cfg->setConfigEntry("hub_peer_miss_pong", "PONG_MISS"); +$cfg->setConfigEntry('hub_peer_miss_pong', "PONG_MISS"); // [EOF] ?> diff --git a/inc/database.php b/inc/database.php index ad29f0e49..62e64fb92 100644 --- a/inc/database.php +++ b/inc/database.php @@ -34,7 +34,11 @@ This will choose the local-file-based database type (layer)"); } // Generate FQFN for the database layer -$INC = sprintf("%sinc/database/lib-%s%s", PATH, _DB_TYPE, FrameworkConfiguration::getInstance()->readConfig("php_extension")); +$INC = sprintf("%sinc/database/lib-%s%s", + PATH, + _DB_TYPE, + FrameworkConfiguration::getInstance()->readConfig('php_extension') +); // Load the database layer include if ((file_exists($INC)) && (is_file($INC)) && (is_readable($INC))) { diff --git a/inc/database/lib-local.php b/inc/database/lib-local.php index a689fed4b..95b0f8954 100644 --- a/inc/database/lib-local.php +++ b/inc/database/lib-local.php @@ -3,10 +3,10 @@ * Initializes the local file database class * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @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 @@ -19,30 +19,30 @@ * 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 . + * along with this program. If not, see . */ // Zum Testen speichern wir in lokale Dateien (LocalFileDatabase) try { - $layer = LocalFileDatabase::createLocalFileDatabase(PATH . "db/", FileIOHandler::getInstance()); + $layer = LocalFileDatabase::createLocalFileDatabase(PATH . FrameworkConfiguration::getInstance()->readConfig('local_db_path'), FileIoHandler::getInstance()); } catch (SavePathIsEmptyException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathNotFoundException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathIsNoDirectoryException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathReadProtectedException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathWriteProtectedException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } diff --git a/inc/file_io.php b/inc/file_io.php index 92c96b6c4..de20bf54c 100644 --- a/inc/file_io.php +++ b/inc/file_io.php @@ -5,10 +5,10 @@ * instances will we generated. * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @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 @@ -21,11 +21,11 @@ * 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 . + * along with this program. If not, see . */ // Get the instance -$io = FileIOHandler::createFileIOHandler(); +$io = FileIoHandler::createFileIoHandler(); // [EOF] ?> diff --git a/inc/includes.php b/inc/includes.php index c9158581e..b699ea911 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -3,10 +3,10 @@ * Loads more include files by using the generic class loader * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @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 @@ -19,11 +19,11 @@ * 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 . + * along with this program. If not, see . */ // Include the class loader function -require(sprintf("%sinc/loader/class_ClassLoader%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); +require(sprintf("%sinc/loader/class_ClassLoader%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); /** * Is the devel package included? @@ -32,7 +32,7 @@ if (is_dir(sprintf("%sdevel", PATH))) { /** * Load all development includes */ - ClassLoader::getInstance()->loadClasses("devel"); + ClassLoader::getInstance()->loadClasses('devel'); } // Shall we include additional configs where you can configure some things? Then diff --git a/inc/language.php b/inc/language.php index 552dc4589..60c9e28eb 100644 --- a/inc/language.php +++ b/inc/language.php @@ -23,7 +23,7 @@ try { $lang = LanguageSystem::createLanguageSystem(sprintf("%s%s", PATH, - FrameworkConfiguration::getInstance()->readConfig("lang_base_path") + FrameworkConfiguration::getInstance()->readConfig('lang_base_path') )); } catch (LanguagePathIsEmptyException $e) { ApplicationEntryPoint::app_die(sprintf("[Main:] The language sub-system could not be initialized for the following reason: %s", diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 736649689..edbe3cb2f 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -101,8 +101,8 @@ class ClassLoader { $this->dirList = new ArrayObject(); // Set suffix and prefix from configuration - $this->suffix = $cfgInstance->readConfig("class_suffix"); - $this->prefix = $cfgInstance->readConfig("class_prefix"); + $this->suffix = $cfgInstance->readConfig('class_suffix'); + $this->prefix = $cfgInstance->readConfig('class_prefix'); // Estimate length of prefix and suffix for substr() function (cache) $this->sufLen = strlen($this->suffix); @@ -289,9 +289,9 @@ class ClassLoader { } // Initial load of core classes and the FrameworkDirectoryPointer class -require_once(sprintf("%sinc/classes/interfaces/class_FrameworkInterface%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); -require_once(sprintf("%sinc/classes/main/class_BaseFrameworkSystem%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); -require_once(sprintf("%sinc/classes/main/io/class_FrameworkDirectoryPointer%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); +require_once(sprintf("%sinc/classes/interfaces/class_FrameworkInterface%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); +require_once(sprintf("%sinc/classes/main/class_BaseFrameworkSystem%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); +require_once(sprintf("%sinc/classes/main/io/class_FrameworkDirectoryPointer%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); // Initialize the class loader $loader = new ClassLoader(FrameworkConfiguration::getInstance()); diff --git a/inc/output.php b/inc/output.php index 20f3fe8f5..7b9302a0a 100644 --- a/inc/output.php +++ b/inc/output.php @@ -23,7 +23,7 @@ */ // Get a debugger instance -$debug = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getInstance()->readConfig("debug_engine")); +$debug = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getInstance()->readConfig('debug_engine')); // Empty string should be ignored and used for testing the middleware DebugMiddleware::getInstance()->output(""); diff --git a/inc/selector.php b/inc/selector.php index 2133c11e7..e608de177 100644 --- a/inc/selector.php +++ b/inc/selector.php @@ -23,23 +23,23 @@ */ // Does the user has an application specified? -if (!empty($_GET[FrameworkConfiguration::getInstance()->readConfig("app_selector_get")])) { +if (!empty($_GET[FrameworkConfiguration::getInstance()->readConfig('app_selector_get')])) { // Set the application from string - $application = (string) $_GET[FrameworkConfiguration::getInstance()->readConfig("app_selector_get")]; + $application = (string) $_GET[FrameworkConfiguration::getInstance()->readConfig('app_selector_get')]; } elseif (!empty($_SERVER['argv'][1])) { // Set the application from string $application = (string) $_SERVER['argv'][1]; - $app = explode("=", trim($application)); - if ($app[0] == FrameworkConfiguration::getInstance()->readConfig("app_selector_get")) { + $app = explode('=', trim($application)); + if ($app[0] == FrameworkConfiguration::getInstance()->readConfig('app_selector_get')) { // Application is valid! $application = trim($app[1]); } else { // Invalid entry found, first must be "app"! - $application = FrameworkConfiguration::getInstance()->readConfig("default_application"); + $application = FrameworkConfiguration::getInstance()->readConfig('default_application'); } } else { // Set the "application selector" application - $application = FrameworkConfiguration::getInstance()->readConfig("default_application"); + $application = FrameworkConfiguration::getInstance()->readConfig('default_application'); } // Secure it, by keeping out tags @@ -50,7 +50,7 @@ $application = preg_replace('/([^a-z_-])+/i', "", $application); // Try to load these includes in the given order $configAppIncludes = array( - sprintf("class_%s", FrameworkConfiguration::getInstance()->readConfig("app_helper_class")), // The ApplicationHelper class + sprintf("class_%s", FrameworkConfiguration::getInstance()->readConfig('app_helper_class')), // The ApplicationHelper class "config", // The application's own configuration "init", // The application initializer "loader", // The application's class loader @@ -70,20 +70,20 @@ foreach ($configAppIncludes as $inc) { // Generate a FQFN for the helper class $fqfn = sprintf("%s%s/%s/%s%s", PATH, - FrameworkConfiguration::getInstance()->readConfig("application_path"), + FrameworkConfiguration::getInstance()->readConfig('application_path'), $application, $inc, - FrameworkConfiguration::getInstance()->readConfig("php_extension") + FrameworkConfiguration::getInstance()->readConfig('php_extension') ); // Does the include file exists? if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) { // Load it require_once($fqfn); - } elseif (FrameworkConfiguration::getInstance()->readConfig("verbose_level") > 0) { + } elseif (FrameworkConfiguration::getInstance()->readConfig('verbose_level') > 0) { // File is missing trigger_error(sprintf("Cannot load application script %s! File is missing or read-protected.", - $inc . FrameworkConfiguration::getInstance()->readConfig("php_extension") + $inc . FrameworkConfiguration::getInstance()->readConfig('php_extension') )); } } diff --git a/index.php b/index.php index 86b8c446e..9cabcb0a8 100644 --- a/index.php +++ b/index.php @@ -8,10 +8,10 @@ * But good little boys and girls would always initialize their variables... ;-) * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @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 @@ -24,7 +24,7 @@ * 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 . + * along with this program. If not, see . */ class ApplicationEntryPoint { /** @@ -50,6 +50,15 @@ class ApplicationEntryPoint { * @return void */ public static function app_die ($message = "") { + // Is this method already called? + if (defined('EMERGENCY_EXIT_CALLED')) { + // Then output the text directly + die($message); + } + + // This method shall not be called twice + define('EMERGENCY_EXIT_CALLED', true); + // Is a message set? if (empty($message)) { // No message provided @@ -65,7 +74,7 @@ class ApplicationEntryPoint { if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) { // Use the template engine for putting out (nicer look) the message try { - $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", LanguageSystem::getInstance(), FileIOHandler::getInstance());", + $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", \$lang, \$io);", FrameworkConfiguration::getInstance()->readConfig("tpl_engine"), FrameworkConfiguration::getInstance()->readConfig("tpl_engine"), PATH, @@ -90,8 +99,19 @@ class ApplicationEntryPoint { )); } - // Assign message + // Backtrace holen und aufbereiten + $backtraceArray = debug_backtrace(); + $backtrace = ""; + foreach ($backtraceArray as $key=>$trace) { + if (!isset($trace['file'])) $trace['file'] = __FILE__; + if (!isset($trace['line'])) $trace['line'] = 5; + if (!isset($trace['args'])) $trace['args'] = array(); + $backtrace .= "".basename($trace['file']).":".$trace['line'].", ".$trace['function']."(".count($trace['args']).")
"; + } + + // Assign variables $tplEngine->assignVariable("message", $message); + $tplEngine->assignVariable("backtrace", $backtrace); // Load the template $tplEngine->loadCodeTemplate("emergency_exit"); @@ -109,7 +129,7 @@ class ApplicationEntryPoint { exit(); } else { // Output message and die - die(sprintf("[Main:] Emergency exit reached: %s", + die(sprintf("[Main:] Emergency exit reached: %s", $message )); } -- 2.39.5