From 513666fabf8bdb9ef98374bd53b6be20654c4971 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 5 May 2008 23:22:08 +0000 Subject: [PATCH] Base updated from ship-simu code --- .gitattributes | 41 ++++ inc/classes/exceptions/controller/.htaccess | 1 + .../class_DefaultControllerException.php | 45 +++++ .../main/class_EmptyVariableException.php | 46 +++++ .../main/class_InvalidCommandException.php | 46 +++++ .../class_InvalidCommandInstanceException.php | 46 +++++ .../main/class_InvalidControllerException.php | 46 +++++ ...ss_ResponseHeadersAlreadySentException.php | 45 +++++ inc/classes/interfaces/class_ | 28 +++ inc/classes/interfaces/commands/.htaccess | 1 + .../interfaces/commands/class_Commandable.php | 36 ++++ inc/classes/interfaces/controller/.htaccess | 1 + .../controller/class_Controller.php | 36 ++++ inc/classes/interfaces/request/.htaccess | 1 + .../interfaces/request/class_Requestable.php | 68 +++++++ inc/classes/interfaces/resolver/.htaccess | 1 + .../resolver/class_CommandResolver.php | 44 ++++ .../resolver/class_ControllerResolver.php | 34 ++++ inc/classes/interfaces/response/.htaccess | 1 + .../response/class_Responseable.php | 63 ++++++ inc/classes/main/class_ | 47 +++++ inc/classes/main/commands/.htaccess | 1 + .../main/commands/class_BaseCommand.php | 85 ++++++++ inc/classes/main/commands/local/.htaccess | 1 + .../commands/local/class_LocalHomeCommand.php | 117 +++++++++++ inc/classes/main/controller/.htaccess | 1 + inc/classes/main/controller/class_ | 46 +++++ .../main/controller/class_BaseController.php | 40 ++++ inc/classes/main/controller/default/.htaccess | 1 + .../default/class_LocalDefaultController.php | 96 +++++++++ .../class_LocalDefaultNewsController.php | 111 ++++++++++ .../main/controller/registration/.htaccess | 1 + .../class_DefaultRegistrationController.php | 71 +++++++ inc/classes/main/request/.htaccess | 1 + .../main/request/class_HttpRequest.php | 151 ++++++++++++++ inc/classes/main/resolver/.htaccess | 1 + .../main/resolver/class_BaseResolver.php | 115 +++++++++++ inc/classes/main/resolver/local/.htaccess | 1 + .../local/class_LocalCommandResolver.php | 184 +++++++++++++++++ .../local/class_LocalControllerResolver.php | 189 ++++++++++++++++++ inc/classes/main/response/.htaccess | 1 + .../main/response/class_HttpResponse.php | 161 +++++++++++++++ 42 files changed, 2052 insertions(+) create mode 100644 inc/classes/exceptions/controller/.htaccess create mode 100644 inc/classes/exceptions/controller/class_DefaultControllerException.php create mode 100644 inc/classes/exceptions/main/class_EmptyVariableException.php create mode 100644 inc/classes/exceptions/main/class_InvalidCommandException.php create mode 100644 inc/classes/exceptions/main/class_InvalidCommandInstanceException.php create mode 100644 inc/classes/exceptions/main/class_InvalidControllerException.php create mode 100644 inc/classes/exceptions/main/class_ResponseHeadersAlreadySentException.php create mode 100644 inc/classes/interfaces/class_ create mode 100644 inc/classes/interfaces/commands/.htaccess create mode 100644 inc/classes/interfaces/commands/class_Commandable.php create mode 100644 inc/classes/interfaces/controller/.htaccess create mode 100644 inc/classes/interfaces/controller/class_Controller.php create mode 100644 inc/classes/interfaces/request/.htaccess create mode 100644 inc/classes/interfaces/request/class_Requestable.php create mode 100644 inc/classes/interfaces/resolver/.htaccess create mode 100644 inc/classes/interfaces/resolver/class_CommandResolver.php create mode 100644 inc/classes/interfaces/resolver/class_ControllerResolver.php create mode 100644 inc/classes/interfaces/response/.htaccess create mode 100644 inc/classes/interfaces/response/class_Responseable.php create mode 100644 inc/classes/main/class_ create mode 100644 inc/classes/main/commands/.htaccess create mode 100644 inc/classes/main/commands/class_BaseCommand.php create mode 100644 inc/classes/main/commands/local/.htaccess create mode 100644 inc/classes/main/commands/local/class_LocalHomeCommand.php create mode 100644 inc/classes/main/controller/.htaccess create mode 100644 inc/classes/main/controller/class_ create mode 100644 inc/classes/main/controller/class_BaseController.php create mode 100644 inc/classes/main/controller/default/.htaccess create mode 100644 inc/classes/main/controller/default/class_LocalDefaultController.php create mode 100644 inc/classes/main/controller/default/class_LocalDefaultNewsController.php create mode 100644 inc/classes/main/controller/registration/.htaccess create mode 100644 inc/classes/main/controller/registration/class_DefaultRegistrationController.php create mode 100644 inc/classes/main/request/.htaccess create mode 100644 inc/classes/main/request/class_HttpRequest.php create mode 100644 inc/classes/main/resolver/.htaccess create mode 100644 inc/classes/main/resolver/class_BaseResolver.php create mode 100644 inc/classes/main/resolver/local/.htaccess create mode 100644 inc/classes/main/resolver/local/class_LocalCommandResolver.php create mode 100644 inc/classes/main/resolver/local/class_LocalControllerResolver.php create mode 100644 inc/classes/main/response/.htaccess create mode 100644 inc/classes/main/response/class_HttpResponse.php diff --git a/.gitattributes b/.gitattributes index 9771ed95d..f2cc2248d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -61,6 +61,8 @@ inc/classes/exceptions/container/.htaccess -text inc/classes/exceptions/container/class_ContainerItemIsNoArrayException.php -text inc/classes/exceptions/container/class_ContainerItemIsNullException.php -text inc/classes/exceptions/container/class_ContainerMaybeDamagedException.php -text +inc/classes/exceptions/controller/.htaccess -text +inc/classes/exceptions/controller/class_DefaultControllerException.php -text inc/classes/exceptions/database/.htaccess -text inc/classes/exceptions/database/local_file/.htaccess -text inc/classes/exceptions/database/local_file/class_SavePathIsEmptyException.php -text @@ -89,10 +91,14 @@ inc/classes/exceptions/main/class_ClassNotFoundException.php -text inc/classes/exceptions/main/class_ConfigEntryIsEmptyException.php -text inc/classes/exceptions/main/class_ConfigEntryNotFoundException.php -text inc/classes/exceptions/main/class_DimNotFoundInArrayException.php -text +inc/classes/exceptions/main/class_EmptyVariableException.php -text inc/classes/exceptions/main/class_ExceptionNotChangedException.php -text inc/classes/exceptions/main/class_ExceptionNotFoundException.php -text inc/classes/exceptions/main/class_GetterNotFoundException.php -text inc/classes/exceptions/main/class_InvalidArrayCountException.php -text +inc/classes/exceptions/main/class_InvalidCommandException.php -text +inc/classes/exceptions/main/class_InvalidCommandInstanceException.php -text +inc/classes/exceptions/main/class_InvalidControllerException.php -text inc/classes/exceptions/main/class_InvalidObjectException.php -text inc/classes/exceptions/main/class_MissingArrayElementsException.php -text inc/classes/exceptions/main/class_MissingDecimalsThousandsSeperatorException.php -text @@ -101,6 +107,7 @@ inc/classes/exceptions/main/class_NoArrayCreatedException.php -text inc/classes/exceptions/main/class_NoArrayException.php -text inc/classes/exceptions/main/class_NoObjectException.php -text inc/classes/exceptions/main/class_NullPointerException.php -text +inc/classes/exceptions/main/class_ResponseHeadersAlreadySentException.php -text inc/classes/exceptions/main/class_VariableIsNotSetException.php -text inc/classes/exceptions/template/.htaccess -text inc/classes/exceptions/template/class_BasePathIsEmptyException.php -text @@ -114,9 +121,14 @@ inc/classes/exceptions/template/class_ViewHelperNotFoundException.php -text inc/classes/interfaces/.htaccess -text inc/classes/interfaces/application/.htaccess -text inc/classes/interfaces/application/class_ManageableApplication.php -text +inc/classes/interfaces/class_ -text inc/classes/interfaces/class_FrameworkInterface.php -text +inc/classes/interfaces/commands/.htaccess -text +inc/classes/interfaces/commands/class_Commandable.php -text inc/classes/interfaces/compressor/.htaccess -text inc/classes/interfaces/compressor/class_Compressor.php -text +inc/classes/interfaces/controller/.htaccess -text +inc/classes/interfaces/controller/class_Controller.php -text inc/classes/interfaces/database/.htaccess -text inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php -text inc/classes/interfaces/database/frontend/.htaccess -text @@ -136,18 +148,38 @@ inc/classes/interfaces/io/output/.htaccess -text inc/classes/interfaces/io/output/class_OutputStreamer.php -text inc/classes/interfaces/language/.htaccess -text inc/classes/interfaces/language/class_ManageableLanguage.php -text +inc/classes/interfaces/request/.htaccess -text +inc/classes/interfaces/request/class_Requestable.php -text +inc/classes/interfaces/resolver/.htaccess -text +inc/classes/interfaces/resolver/class_CommandResolver.php -text +inc/classes/interfaces/resolver/class_ControllerResolver.php -text +inc/classes/interfaces/response/.htaccess -text +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/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_BaseCommand.php -text +inc/classes/main/commands/local/.htaccess -text +inc/classes/main/commands/local/class_LocalHomeCommand.php -text inc/classes/main/compressor/.htaccess -text inc/classes/main/compressor/class_Bzip2Compressor.php -text inc/classes/main/compressor/class_GzipCompressor.php -text inc/classes/main/compressor/class_NullCompressor.php -text inc/classes/main/console/.htaccess -text inc/classes/main/console/class_ConsoleTools.php -text +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/registration/.htaccess -text +inc/classes/main/controller/registration/class_DefaultRegistrationController.php -text inc/classes/main/database/.htaccess -text inc/classes/main/database/class_BaseDatabaseFrontend.php -text inc/classes/main/database/classes/.htaccess -text @@ -169,6 +201,15 @@ inc/classes/main/language/class_LanguageSystem.php -text inc/classes/main/output/.htaccess -text inc/classes/main/output/class_ConsoleOutput.php -text inc/classes/main/output/class_WebOutput.php -text +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/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/middleware/.htaccess -text diff --git a/inc/classes/exceptions/controller/.htaccess b/inc/classes/exceptions/controller/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/exceptions/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/controller/class_DefaultControllerException.php b/inc/classes/exceptions/controller/class_DefaultControllerException.php new file mode 100644 index 000000000..aead2d439 --- /dev/null +++ b/inc/classes/exceptions/controller/class_DefaultControllerException.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 DefaultControllerException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $resolverInstance An instance of a resolver class + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(ControllerResolver $resolverInstance, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolv default controller. Maybe missing?", + $resolverInstance->__toString(), + $this->getLine() + ); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/main/class_EmptyVariableException.php b/inc/classes/exceptions/main/class_EmptyVariableException.php new file mode 100644 index 000000000..a41527648 --- /dev/null +++ b/inc/classes/exceptions/main/class_EmptyVariableException.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 EmptyVariableException extends FrameworkException { + /** + * The constructor + * + * @param $msgArray Message array holding all needed data + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $msgArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Variable %s is not set.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/main/class_InvalidCommandException.php b/inc/classes/exceptions/main/class_InvalidCommandException.php new file mode 100644 index 000000000..b0bc623ca --- /dev/null +++ b/inc/classes/exceptions/main/class_InvalidCommandException.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 InvalidCommandException extends FrameworkException { + /** + * The constructor + * + * @param $message Message from the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $msgArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Invalid command %s detected.", + $msgArray[0]->__toString(), + $this->getLine(), + htmlentities(strip_tags($msgArray[1]), ENT_QUOTES) + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/main/class_InvalidCommandInstanceException.php b/inc/classes/exceptions/main/class_InvalidCommandInstanceException.php new file mode 100644 index 000000000..e802e9e24 --- /dev/null +++ b/inc/classes/exceptions/main/class_InvalidCommandInstanceException.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 InvalidCommandInstanceException extends FrameworkException { + /** + * The constructor + * + * @param $message Message from the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $msgArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Invalid command %s detected.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/main/class_InvalidControllerException.php b/inc/classes/exceptions/main/class_InvalidControllerException.php new file mode 100644 index 000000000..3caf2a513 --- /dev/null +++ b/inc/classes/exceptions/main/class_InvalidControllerException.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 InvalidControllerInstanceException extends FrameworkException { + /** + * The constructor + * + * @param $msgArray Array with data from the exception point + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $msgArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Invalid controller %s detected.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/main/class_ResponseHeadersAlreadySentException.php b/inc/classes/exceptions/main/class_ResponseHeadersAlreadySentException.php new file mode 100644 index 000000000..72751d91f --- /dev/null +++ b/inc/classes/exceptions/main/class_ResponseHeadersAlreadySentException.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 ResponseHeadersAlreadySentException extends FrameworkException { + /** + * The constructor + * + * @param $message Message from 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] Headers are already sent!", + $class->__toString(), + $this->getLine() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/class_ b/inc/classes/interfaces/class_ new file mode 100644 index 000000000..055ad90d6 --- /dev/null +++ b/inc/classes/interfaces/class_ @@ -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 extends FrameworkInterface { +} + +// +?> diff --git a/inc/classes/interfaces/commands/.htaccess b/inc/classes/interfaces/commands/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/interfaces/commands/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/commands/class_Commandable.php b/inc/classes/interfaces/commands/class_Commandable.php new file mode 100644 index 000000000..4b3eaba9f --- /dev/null +++ b/inc/classes/interfaces/commands/class_Commandable.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 Commandable extends FrameworkInterface { + /** + * 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 + */ + function execute (Requestable $requestInstance, Responseable $responseInstance); +} + +// +?> diff --git a/inc/classes/interfaces/controller/.htaccess b/inc/classes/interfaces/controller/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/interfaces/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/controller/class_Controller.php b/inc/classes/interfaces/controller/class_Controller.php new file mode 100644 index 000000000..f06f583df --- /dev/null +++ b/inc/classes/interfaces/controller/class_Controller.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 Controller extends FrameworkInterface { + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + function handleRequest (Requestable $requestInstance, Responseable $responseInstance); +} + +// +?> diff --git a/inc/classes/interfaces/request/.htaccess b/inc/classes/interfaces/request/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/interfaces/request/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/request/class_Requestable.php b/inc/classes/interfaces/request/class_Requestable.php new file mode 100644 index 000000000..08dd5b170 --- /dev/null +++ b/inc/classes/interfaces/request/class_Requestable.php @@ -0,0 +1,68 @@ + + * @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 Requestable extends FrameworkInterface { + /** + * Prepares the HTTP request data for usage by currently copying + * $_REQUEST into a private attribute. Later on we can add more + * things for initialization here. + * + * @return void + */ + function prepareRequestData (); + + /** + * Checks wether a request element is set + * @param $element Name of the request element we want to check + * @return $isSet Wether the request element is set + * @throws MissingArrayElementsException Thrown if a request element is not set + */ + function isRequestElementSet ($element); + + /** + * Getter for request element or 'null' if the element was not found + * + * @param $element Name of the request element we want to check + * @return $value Value of the found request element or 'null' if the + * element was not found + */ + function getRequestElement ($element); + + /** + * Wrapper method for array_key() function for the request data array + * + * @return $array An array containing all array keys to return + */ + function getParameterNames (); + + /** + * Getter for a header element or 'null' if the header was not found + * + * @param $headerName Name of the header + * @return $headerValue Value of the header or 'null' if not found + */ + function getHeader ($headerName); +} + +// +?> diff --git a/inc/classes/interfaces/resolver/.htaccess b/inc/classes/interfaces/resolver/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/interfaces/resolver/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/resolver/class_CommandResolver.php b/inc/classes/interfaces/resolver/class_CommandResolver.php new file mode 100644 index 000000000..2793eb5cc --- /dev/null +++ b/inc/classes/interfaces/resolver/class_CommandResolver.php @@ -0,0 +1,44 @@ + + * @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 CommandResolver extends FrameworkInterface { + /** + * Returns an command instance for a given request class + * + * @param $requestInstance An instance of a request class + * @return $commandInstance An instance of the resolved command + */ + function resolvCommandByRequest (Requestable $requestInstance); + + /** + * Checks wether the given command is valid + * + * @param $commandName The default command we shall execute + * @return $isValid Wether the given command is valid + * @throws EmptyVariableException Thrown if the given command is not set + */ + function isCommandValid ($commandName); +} + +// +?> diff --git a/inc/classes/interfaces/resolver/class_ControllerResolver.php b/inc/classes/interfaces/resolver/class_ControllerResolver.php new file mode 100644 index 000000000..e953ceee2 --- /dev/null +++ b/inc/classes/interfaces/resolver/class_ControllerResolver.php @@ -0,0 +1,34 @@ + + * @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 ControllerResolver extends FrameworkInterface { + /** + * Resolves the default controller of the given command + * + * @return $controllerInstance A controller instance for the default command + */ + function resolveDefaultController (); +} + +// +?> diff --git a/inc/classes/interfaces/response/.htaccess b/inc/classes/interfaces/response/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/interfaces/response/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/response/class_Responseable.php b/inc/classes/interfaces/response/class_Responseable.php new file mode 100644 index 000000000..d8fdaee1f --- /dev/null +++ b/inc/classes/interfaces/response/class_Responseable.php @@ -0,0 +1,63 @@ + + * @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 Responseable extends FrameworkInterface { + /** + * Setter for status + * + * @param $status New response status + * @return void + */ + function setResponseStatus ($status); + + /** + * Add header element + * + * @param $name Name of header element + * @param $value Value of header element + * @return void + */ + function addHeader ($name, $value); + + /** + * "Writes" data to the response body + * + * @param $output Output we shall sent in the HTTP response + * @return void + */ + function writeToBody ($output); + + /** + * Flushs the cached HTTP response to the outer world + * + * @param $foce Wether we shall force the output or abort if headers are + * already sent with an exception + * @return void + * @throws ResponseHeadersAlreadySentException Thrown if headers are + * already sent + */ + function flushResponse($force=false); +} + +// +?> diff --git a/inc/classes/main/class_ b/inc/classes/main/class_ new file mode 100644 index 000000000..af4096f64 --- /dev/null +++ b/inc/classes/main/class_ @@ -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 extends BaseFrameworkSystem { + /** + * 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(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/commands/.htaccess b/inc/classes/main/commands/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/commands/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/commands/class_BaseCommand.php b/inc/classes/main/commands/class_BaseCommand.php new file mode 100644 index 000000000..825b2b052 --- /dev/null +++ b/inc/classes/main/commands/class_BaseCommand.php @@ -0,0 +1,85 @@ + + * @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 BaseCommand extends BaseFrameworkSystem { + /** + * The controller we need for this command + */ + private $controllerName = ""; + + /** + * Resolver instance + */ + private $resolverInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct ($class) { + // Call parent constructor + parent::__construct($class); + } + + /** + * Setter for controller name + * + * @param $controllerName Name of the controller assigned with this command + * @return void + */ + public final function setControllerName ($controllerName) { + $this->controllerName = (string) $controllerName; + } + + /** + * Getter for controller name + * + * @return $controllerName Name of the controller assigned with this command + */ + public final function getControllerName () { + return $this->controllerName; + } + + /** + * Setter for resolver instance + * + * @param $resolverInstance Instance of a command resolver class + * @return void + */ + public final function setResolverInstance (CommandResolver $resolverInstance) { + $this->resolverInstance = $resolverInstance; + } + + /** + * Getter for resolver instance + * + * @return $resolverInstance Instance of a command resolver class + */ + public final function getResolverInstance () { + return $this->resolverInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/commands/local/.htaccess b/inc/classes/main/commands/local/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/commands/local/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/commands/local/class_LocalHomeCommand.php b/inc/classes/main/commands/local/class_LocalHomeCommand.php new file mode 100644 index 000000000..58e1a76d9 --- /dev/null +++ b/inc/classes/main/commands/local/class_LocalHomeCommand.php @@ -0,0 +1,117 @@ + + * @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 LocalHomeCommand extends BaseCommand implements Commandable { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription("Home-Command"); + + // 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 createLocalHomeCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new LocalHomeCommand(); + + // 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); + + // 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 home template + $templateInstance->loadWebTemplate("home"); + + // Assign the home template with the master template as a content ... ;) + $templateInstance->assignTemplateWithVariable("home", "content"); + + // Load the master template + $templateInstance->loadCodeTemplate($masterTemplate); + + // Set title + $title = ucfirst($requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter"))); + if (empty($title)) $title = "Home"; + $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/controller/.htaccess b/inc/classes/main/controller/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/controller/class_ b/inc/classes/main/controller/class_ new file mode 100644 index 000000000..8ac8f489a --- /dev/null +++ b/inc/classes/main/controller/class_ @@ -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 Controller extends BaseController { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Ein spezieller Controller"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php new file mode 100644 index 000000000..f7aea5c30 --- /dev/null +++ b/inc/classes/main/controller/class_BaseController.php @@ -0,0 +1,40 @@ + + * @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 BaseController extends BaseFrameworkSystem { + /** + * Protected constructor + * + * @return void + */ + protected function __construct ($class) { + // Call parent constructor + parent::__construct($class); + + // Clean up a little + $this->removeNumberFormaters(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/controller/default/.htaccess b/inc/classes/main/controller/default/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/controller/default/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/controller/default/class_LocalDefaultController.php b/inc/classes/main/controller/default/class_LocalDefaultController.php new file mode 100644 index 000000000..a79243a7d --- /dev/null +++ b/inc/classes/main/controller/default/class_LocalDefaultController.php @@ -0,0 +1,96 @@ + + * @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 LocalLocalDefaultController 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 für alle übrigen Anfragen"); + + // 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 createLocalDefaultController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new LocalDefaultController(); + + // 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); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushResponse(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/controller/default/class_LocalDefaultNewsController.php b/inc/classes/main/controller/default/class_LocalDefaultNewsController.php new file mode 100644 index 000000000..90d3ec7ba --- /dev/null +++ b/inc/classes/main/controller/default/class_LocalDefaultNewsController.php @@ -0,0 +1,111 @@ + + * @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/registration/.htaccess b/inc/classes/main/controller/registration/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/controller/registration/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/controller/registration/class_DefaultRegistrationController.php b/inc/classes/main/controller/registration/class_DefaultRegistrationController.php new file mode 100644 index 000000000..2f15e400d --- /dev/null +++ b/inc/classes/main/controller/registration/class_DefaultRegistrationController.php @@ -0,0 +1,71 @@ + + * @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 DefaultRegistrationController extends BaseController implements Controller { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Ein Standart-Anmelde-Controller"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @return $controllerInstance A prepared instance of this class + */ + public final static function createDefaultRegistrationController () { + // Create the instance + $controllerInstance = new DefaultRegistrationController(); + + // Return the prepared instance + return $controllerInstance; + } + + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { + die(__METHOD__.": Stub!"); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/request/.htaccess b/inc/classes/main/request/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/request/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php new file mode 100644 index 000000000..6826d76b7 --- /dev/null +++ b/inc/classes/main/request/class_HttpRequest.php @@ -0,0 +1,151 @@ + + * @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 HttpRequest extends BaseFrameworkSystem implements Requestable { + /** + * Array for the request data + */ + private $requestData = array(); + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("HTTP-Anfrage"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class and prepares it a little + * + * @return $httpInstance An instance of this class + */ + public final static function createHttpRequest () { + // Create an instance + $httpInstance = new HttpRequest(); + + // Prepare the HTTP request data for usage + $httpInstance->prepareRequestData(); + + // Return the prepared instance + return $httpInstance; + } + + /** + * Prepares the HTTP request data for usage by currently copying + * $_REQUEST into a private attribute. Later on we can add more + * things for initialization here. + * + * @return void + */ + public function prepareRequestData () { + // Copy the $_REQUEST array + $this->requestData = $_REQUEST; + } + + /** + * Checks wether a request element is set + * @param $element Name of the request element we want to check + * @return $isSet Wether the request element is set + * @throws MissingArrayElementsException Thrown if a request element is not set + */ + public function isRequestElementSet ($element) { + // Is this element found? + if (!isset($this->requestData[$element])) { + // Then throw an exception + throw new MissingArrayElementsException(array($this, 'requestData', $element), self::EXCEPTION_MISSING_ELEMENT); + } + + // All clear + return true; + } + + /** + * Getter for request element or 'null' if the element was not found + * + * @param $element Name of the request element we want to check + * @return $value Value of the found request element or 'null' if the + * element was not found + */ + public function getRequestElement ($element) { + // Initialize value + $value = null; + + try { + if ($this->isRequestElementSet($element)) { + $value = $this->requestData[$element]; + } + } catch (MissingArrayElementsException $e) { + // Do nothing here + } + + // Return the element's value + return $value; + } + + /** + * Wrapper method for array_key() function for the request data array + * + * @return $array An array containing all array keys to return + */ + public function getParameterNames () { + return array_keys($this->requestData); + } + + /** + * Getter for a header element or 'null' if the header was not found + * + * @param $headerName Name of the header + * @return $headerValue Value of the header or 'null' if not found + */ + public function getHeader ($headerName) { + // Default return value on error + $headerValue = null; + + // Construct the name + $name = 'HTTP_' . strtolower(str_replace('-', '_', $headerName)); + + // Does this header exist? + if (isset($_SERVER[$name])) { + $headerValue = $_SERVER[$name]; + } + + // Return the value + return $headerValue; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/.htaccess b/inc/classes/main/resolver/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/resolver/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php new file mode 100644 index 000000000..d442ef38e --- /dev/null +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -0,0 +1,115 @@ + + * @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 BaseResolver extends BaseFrameworkSystem { + /** + * Validated command name + */ + private $commandName = ""; + + /** + * Prefix for local, remote or other resolver + */ + private $commandPrefix = ""; + + /** + * Private constructor + * + * @return void + */ + protected function __construct ($class) { + // Call parent constructor + parent::__construct($class); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Setter for command name + * + * @param $commandName Last validated command name + * @return void + */ + protected final function setCommandName ($commandName) { + $this->commandName = $commandName; + } + + /** + * Getter for command name + * + * @return $commandName Last validated command name + */ + protected final function getCommandName () { + return $this->commandName; + } + + /** + * Setter for command prefix + * + * @param $commandPrefix Last validated commandPrefix + * @return void + */ + protected final function setCommandPrefix ($commandPrefix) { + $this->commandPrefix = $commandPrefix; + } + + /** + * Checks wether the given command is valid + * + * @param $commandName The default command we shall execute + * @return $isValid Wether the given command is valid + * @throws EmptyVariableException Thrown if the given command is not set + */ + public function isCommandValid ($commandName) { + // By default nothing shall be valid + $isValid = false; + + // Is a command set? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($this, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Now, let us create the full name of the command class + $class = sprintf("%s%sCommand", + $this->commandPrefix, + ucfirst(strtolower($commandName)) + ); + + // Is this class already loaded? + if (class_exists($class)) { + // This class does exist. :-) + $isValid = true; + } + + // Set command name + $this->setCommandName($commandName); + + // Return the result + return $isValid; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/local/.htaccess b/inc/classes/main/resolver/local/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/resolver/local/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/local/class_LocalCommandResolver.php b/inc/classes/main/resolver/local/class_LocalCommandResolver.php new file mode 100644 index 000000000..87e0d69f8 --- /dev/null +++ b/inc/classes/main/resolver/local/class_LocalCommandResolver.php @@ -0,0 +1,184 @@ + + * @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 new file mode 100644 index 000000000..9c942098f --- /dev/null +++ b/inc/classes/main/resolver/local/class_LocalControllerResolver.php @@ -0,0 +1,189 @@ + + * @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/response/.htaccess b/inc/classes/main/response/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/inc/classes/main/response/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/response/class_HttpResponse.php b/inc/classes/main/response/class_HttpResponse.php new file mode 100644 index 000000000..3679fe96a --- /dev/null +++ b/inc/classes/main/response/class_HttpResponse.php @@ -0,0 +1,161 @@ + + * @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 HttpResponse extends BaseFrameworkSystem implements Responseable { + /** + * Response status + */ + private $responseStatus = "200 OK"; + + /** + * Array with all headers + */ + private $responseHeaders = array(); + + /** + * Body of the response + */ + private $responseBody = ""; + + /** + * Instance of the template engine + */ + private $templateEngine = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("HTTP-Antwort"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an object of this class + * + * @param $appInstance An instance of a manageable application + * @return $responseInstance A prepared instance of this class + */ + public final static function createHttpResponse (ManageableApplication $appInstance) { + // Get a new instance + $responseInstance = new HttpResponse(); + + // Initialize the template engine here + $responseInstance->initTemplateEngine($appInstance); + + // Return the prepared instance + return $responseInstance; + } + + /** + * Setter for status + * + * @param $status New response status + * @return void + */ + public final function setResponseStatus ($status) { + $this->responseStatus = (string) $status; + } + + /** + * Add header element + * + * @param $name Name of header element + * @param $value Value of header element + * @return void + */ + public final function addHeader ($name, $value) { + $this->responseHeaders[$name] = $value; + } + + /** + * "Writes" data to the response body + * + * @param $output Output we shall sent in the HTTP response + * @return void + */ + public function writeToBody ($output) { + $this->responseBody .= $output; + } + + /** + * Flushs the cached HTTP response to the outer world + * + * @param $foce Wether we shall force the output or abort if headers are + * already sent with an exception + * @return void + * @throws ResponseHeadersAlreadySentException Thrown if headers are + * already sent + */ + public function flushResponse ($force=false) { + if ((headers_sent()) && (!$force)) { + // Headers are already sent! + throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); + } elseif (!headers_sent()) { + // Send headers out + header("HTTP/1.0 {$this->responseStatus}"); + foreach ($this->responseHeaders as $name=>$value) { + header("{$name}: {$value}"); + } + } + + // Flush the output to the world + $this->getWebOutputInstance()->output($this->responseBody); + $this->reponseBody = ""; + $this->responseHeaders = array(); + } + + /** + * Initializes the template engine instance + * + * @param $appInstance An instance of a manageable application + * @return void + */ + public final function initTemplateEngine (ManageableApplication $appInstance) { + $this->templateEngine = $this->prepareTemplateEngine($appInstance); + } + + /** + * Getter for the template engine instance + * + * @return $templateEngine An instance of the used template engine + */ + public final function getTemplateEngine () { + return $this->templateEngine; + } +} + +// [EOF] +?> -- 2.39.5