From 0a4c7d2793ad13bfe4798f947ef39529f32b6567 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 14 May 2008 19:57:42 +0000 Subject: [PATCH] getConfigInstance() is now protected, factories added --- .gitattributes | 4 ++ .../main/class_BaseFrameworkSystem.php | 2 +- .../class_WebDefaultNewsController.php | 10 +-- inc/classes/main/factories/.htaccess | 1 + .../main/factories/class_BaseFactory.php | 42 ++++++++++++ inc/classes/main/factories/web/.htaccess | 1 + .../main/factories/web/class_NewsFactory.php | 66 +++++++++++++++++++ .../main/language/class_LanguageSystem.php | 2 +- .../main/template/class_TemplateEngine.php | 2 +- .../compressor/class_CompressorChannel.php | 2 +- templates/de/code/header.ctp | 2 +- 11 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 inc/classes/main/factories/.htaccess create mode 100644 inc/classes/main/factories/class_BaseFactory.php create mode 100644 inc/classes/main/factories/web/.htaccess create mode 100644 inc/classes/main/factories/web/class_NewsFactory.php diff --git a/.gitattributes b/.gitattributes index 7e55742..a5e046f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -274,6 +274,10 @@ inc/classes/main/debug/class_DebugWebOutput.php -text inc/classes/main/extended/.htaccess -text inc/classes/main/extended/class_ObjectLimits.php -text inc/classes/main/extended/class_SerializationContainer.php -text +inc/classes/main/factories/.htaccess -text +inc/classes/main/factories/class_BaseFactory.php -text +inc/classes/main/factories/web/.htaccess -text +inc/classes/main/factories/web/class_NewsFactory.php -text inc/classes/main/io/.htaccess -text inc/classes/main/io/class_FileIOStream.php -text inc/classes/main/io/class_FrameworkDirectoryPointer.php -text diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 4abdf29..8dbbdaa 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -304,7 +304,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * * @return $cfhInstance - Configuration instance */ - public final function getConfigInstance () { + protected final function getConfigInstance () { return self::$cfgInstance; } diff --git a/inc/classes/main/controller/default/class_WebDefaultNewsController.php b/inc/classes/main/controller/default/class_WebDefaultNewsController.php index b9f1ee8..835f94b 100644 --- a/inc/classes/main/controller/default/class_WebDefaultNewsController.php +++ b/inc/classes/main/controller/default/class_WebDefaultNewsController.php @@ -85,7 +85,7 @@ class WebDefaultNewsController extends BaseController implements Controller { $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); // Load the news here - $this->loadNews($requestInstance); + $this->loadNewsByRequest($requestInstance); // Execute the command $commandInstance->execute($requestInstance, $responseInstance); @@ -95,14 +95,14 @@ class WebDefaultNewsController extends BaseController implements Controller { } /** - * Loads news from the connected database for later usage + * Loads news by a given request * * @param $requestInstance An instance of a request class * @return void */ - private function loadNews (Requestable $requestInstance) { - // Get the news page variable from the request instance - $newsPage = $requestInstance->getRequestElement("news_page"); + private function loadNewsByRequest (Requestable $requestInstance) { + // Generate a new news object but not carring about which concrete we have + $newsInstance = NewsFactory::createFactoryByRequest($requestInstance)->createNewsObject(); } } diff --git a/inc/classes/main/factories/.htaccess b/inc/classes/main/factories/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/factories/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/factories/class_BaseFactory.php b/inc/classes/main/factories/class_BaseFactory.php new file mode 100644 index 0000000..11c8ec9 --- /dev/null +++ b/inc/classes/main/factories/class_BaseFactory.php @@ -0,0 +1,42 @@ + + * @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 BaseFactory extends BaseFrameworkSystem { + /** + * Private constructor + * + * @param $class Name of the real class (not BaseFactory) + * @return void + */ + protected function __construct ($class) { + // Call parent constructor + parent::__construct($class); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/factories/web/.htaccess b/inc/classes/main/factories/web/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/factories/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/factories/web/class_NewsFactory.php b/inc/classes/main/factories/web/class_NewsFactory.php new file mode 100644 index 0000000..d863891 --- /dev/null +++ b/inc/classes/main/factories/web/class_NewsFactory.php @@ -0,0 +1,66 @@ + + * @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 NewsFactory extends BaseFactory { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("News-Fabrik für Webseiten"); + + // Create unique ID number + $this->createUniqueID(); + } + + /** + * Singleton getter for a special factory instance depending on the given + * request + * + * @param $requestInstance An instance of a request class + * @return $factoryInstance An instance of a NewsFactory class + */ + public final static function createFactoryByRequest (Requestable $requestInstance) { + // Generate the new instance + $factoryInstance = new NewsFactory(); + + // Get the element name + $element = FrameworkConfiguration::getInstance()->readConfig("app_selector_get"); + + // Analyze the request, first get the Uni* application name (short one from URL) + $appVariable = $requestInstance->getRequestElement($element); + + // Add more code here... + + // Return the prepared factory instance + return $factoryInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/language/class_LanguageSystem.php b/inc/classes/main/language/class_LanguageSystem.php index 4aa9490..35db75c 100644 --- a/inc/classes/main/language/class_LanguageSystem.php +++ b/inc/classes/main/language/class_LanguageSystem.php @@ -101,7 +101,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { $langInstance->initLanguageStrings(); // Set language code from default config - $langInstance->setLanguageCode($langInstance->getConfigInstance()->readConfig("default_lang")); + $langInstance->setLanguageCode(FrameworkConfiguration::getInstance()->readConfig("default_lang")); // Remember this instance self::$thisInstance = $langInstance; diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index e11b84d..4c15006 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -167,7 +167,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate } // Get configuration instance - $cfgInstance = $tplInstance->getConfigInstance(); + $cfgInstance = FrameworkConfiguration::getInstance(); // Set the base path $tplInstance->setBasePath($basePath); diff --git a/inc/classes/middleware/compressor/class_CompressorChannel.php b/inc/classes/middleware/compressor/class_CompressorChannel.php index b5fa565..fd04ac1 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) == $cInstance->getConfigInstance()->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/templates/de/code/header.ctp b/templates/de/code/header.ctp index 2b2457d..b82ab23 100644 --- a/templates/de/code/header.ctp +++ b/templates/de/code/header.ctp @@ -1,5 +1,5 @@ - + $content[title] -- 2.30.2