From: Roland Häder Date: Thu, 15 May 2008 09:27:16 +0000 (+0000) Subject: More smaller fixes, factory added to ship-simu X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=commitdiff_plain;h=2fd5f8ecd793f9ec3004cf53629cc7b2c52522cc More smaller fixes, factory added to ship-simu --- diff --git a/.gitattributes b/.gitattributes index a5e046f..bc7b930 100644 --- a/.gitattributes +++ b/.gitattributes @@ -77,6 +77,8 @@ application/ship-simu/main/drives/.htaccess -text application/ship-simu/main/drives/class_BaseDrive.php -text application/ship-simu/main/drives/motor/.htaccess -text application/ship-simu/main/drives/motor/class_Motor.php -text +application/ship-simu/main/factories/.htaccess -text +application/ship-simu/main/factories/class_ShipSimuNewsFactory.php -text application/ship-simu/main/parts/.htaccess -text application/ship-simu/main/parts/class_BaseShipPart.php -text application/ship-simu/main/parts/maschineroom/.htaccess -text @@ -276,6 +278,8 @@ 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/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/io/.htaccess -text diff --git a/application/ship-simu/main/class_ b/application/ship-simu/main/class_ index 9644fd5..af4096f 100644 --- a/application/ship-simu/main/class_ +++ b/application/ship-simu/main/class_ @@ -1,7 +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 { /** - * Limits this object with an ObjectLimits instance + * Private constructor + * + * @return void */ - public function limitObject (ObjectLimits $limitInstance) { - die("limitObject() reached! Stub!"); + 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/application/ship-simu/main/class_WorksContract.php b/application/ship-simu/main/class_WorksContract.php index fdcc74a..cd2f045 100644 --- a/application/ship-simu/main/class_WorksContract.php +++ b/application/ship-simu/main/class_WorksContract.php @@ -91,7 +91,7 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { // Existiert die Klasse ueberhaupt? if (!class_exists($shipType)) { // Klasse nicht gefunden - throw new ClassNotFoundException ($shipType, 0); + throw new ClassNotFoundException ($shipType, self::EXCEPTION_CLASS_NOT_FOUND); } // Schiff-Instanz temporaer erzeugen und in den Bauvertrag einfuegen @@ -242,7 +242,7 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { $this->getShipInstance()->getShipName() )); } - } catch(ClassNotFoundException $e) { + } catch (ClassNotFoundException $e) { // Throw it again... throw new ClassNotFoundException($e->getMessage(), $e->getCode()); } diff --git a/application/ship-simu/main/companies/class_ShippingCompany.php b/application/ship-simu/main/companies/class_ShippingCompany.php index 1dba168..dec3a32 100644 --- a/application/ship-simu/main/companies/class_ShippingCompany.php +++ b/application/ship-simu/main/companies/class_ShippingCompany.php @@ -426,7 +426,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // Is the class there? if (!class_exists($shipType)) { // Throw exception - throw new ClassNotFoundException($shipType, 0); + throw new ClassNotFoundException($shipType, self::EXCEPTION_CLASS_NOT_FOUND); } // Create dummy ship diff --git a/application/ship-simu/main/factories/.htaccess b/application/ship-simu/main/factories/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/factories/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/factories/class_ShipSimuNewsFactory.php b/application/ship-simu/main/factories/class_ShipSimuNewsFactory.php new file mode 100644 index 0000000..7e60b34 --- /dev/null +++ b/application/ship-simu/main/factories/class_ShipSimuNewsFactory.php @@ -0,0 +1,60 @@ + + * @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 ShipSimuNewsFactory extends BaseFrameworkSystem { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("News-Objektefabrik für Ship-Simu"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @return $factoryInstance An instance of this class + */ + public final static function createShipSimuNewsFactory () { + // Get a new instance + $factoryInstance = new ShipSimuNewsFactory(); + + // Return the prepared instance + return $factoryInstance; + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/ships/class_BaseShip.php b/application/ship-simu/main/ships/class_BaseShip.php index 4799c0e..6e0ef56 100644 --- a/application/ship-simu/main/ships/class_BaseShip.php +++ b/application/ship-simu/main/ships/class_BaseShip.php @@ -87,7 +87,7 @@ class BaseShip extends BaseSimulator { eval($eval); } else { // Nicht vorhanden, dann Ausnahme werfen! - throw new ClassNotFoundException($partClass, 0); + throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND); } // Das Einbauen versuchen... diff --git a/inc/classes/exceptions/main/class_ClassNotFoundException.php b/inc/classes/exceptions/main/class_ClassNotFoundException.php index 897f220..b77de9a 100644 --- a/inc/classes/exceptions/main/class_ClassNotFoundException.php +++ b/inc/classes/exceptions/main/class_ClassNotFoundException.php @@ -25,11 +25,11 @@ class ClassNotFoundException extends FrameworkException { /** * The constructor * - * @param $message Message from the exception + * @param $class Class' name we have no class found for * @param $code Code number for the exception * @return void */ - public function __construct (BaseFrameworkSystem $class, $code) { + public function __construct ($class, $code) { // Add a message around the missing class $message = sprintf("Die interne Script-Klasse %s konnte nicht gefunden werden!", $class); diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 8dbbdaa..f341fc9 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -149,6 +149,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_INVALID_CONTROLLER = 0x032; const EXCEPTION_HEADERS_ALREADY_SENT = 0x033; const EXCEPTION_DEFAUL_CONTROLLER_GONE = 0x034; + const EXCEPTION_CLASS_NOT_FOUND = 0x035; /** * In the super constructor these system classes shall be ignored or else diff --git a/inc/classes/main/commands/web/class_WebHomeCommand.php b/inc/classes/main/commands/web/class_WebHomeCommand.php index f45b0d7..9629b97 100644 --- a/inc/classes/main/commands/web/class_WebHomeCommand.php +++ b/inc/classes/main/commands/web/class_WebHomeCommand.php @@ -23,7 +23,7 @@ */ class WebHomeCommand extends BaseCommand implements Commandable { /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/controller/default/class_WebDefaultController.php b/inc/classes/main/controller/default/class_WebDefaultController.php index 38d92ce..9830891 100644 --- a/inc/classes/main/controller/default/class_WebDefaultController.php +++ b/inc/classes/main/controller/default/class_WebDefaultController.php @@ -28,7 +28,7 @@ class WebWebDefaultController extends BaseController implements Controller { private $resolverInstance = null; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/controller/default/class_WebDefaultNewsController.php b/inc/classes/main/controller/default/class_WebDefaultNewsController.php index 835f94b..ea690a9 100644 --- a/inc/classes/main/controller/default/class_WebDefaultNewsController.php +++ b/inc/classes/main/controller/default/class_WebDefaultNewsController.php @@ -28,7 +28,7 @@ class WebDefaultNewsController extends BaseController implements Controller { private $resolverInstance = null; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/controller/registration/class_DefaultRegistrationController.php b/inc/classes/main/controller/registration/class_DefaultRegistrationController.php index 2f15e40..24d7040 100644 --- a/inc/classes/main/controller/registration/class_DefaultRegistrationController.php +++ b/inc/classes/main/controller/registration/class_DefaultRegistrationController.php @@ -24,7 +24,7 @@ */ class DefaultRegistrationController extends BaseController implements Controller { /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/factories/class_BaseFactory.php b/inc/classes/main/factories/class_BaseFactory.php index 11c8ec9..db2611c 100644 --- a/inc/classes/main/factories/class_BaseFactory.php +++ b/inc/classes/main/factories/class_BaseFactory.php @@ -23,7 +23,12 @@ */ class BaseFactory extends BaseFrameworkSystem { /** - * Private constructor + * An instance of the real factory class + */ + private $realFactoryInstance = null; + + /** + * Protected constructor * * @param $class Name of the real class (not BaseFactory) * @return void @@ -32,10 +37,32 @@ class BaseFactory extends BaseFrameworkSystem { // Call parent constructor parent::__construct($class); + // Create unique ID number + $this->createUniqueID(); + // Clean up a little $this->removeNumberFormaters(); $this->removeSystemArray(); } + + /** + * Setter for the *real* factory instance + * + * @param $realFactoryInstance An instance of the real factory class + * @return void + */ + public final function setRealFactoryInstance (BaseFrameworkSystem $realFactoryInstance) { + $this->realFactoryInstance = $realFactoryInstance; + } + + /** + * Getter for the *real* factory instance + * + * @return $realFactoryInstance An instance of the real factory class + */ + protected final function getRealFactoryInstance () { + return $this->realFactoryInstance; + } } // [EOF] diff --git a/inc/classes/main/factories/objects/.htaccess b/inc/classes/main/factories/objects/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/factories/objects/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/factories/objects/class_ObjectFactory.php b/inc/classes/main/factories/objects/class_ObjectFactory.php new file mode 100644 index 0000000..fd983ca --- /dev/null +++ b/inc/classes/main/factories/objects/class_ObjectFactory.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 ObjectFactory extends BaseFactory { + /** + * Protected constructor + * + * @param $class Name of the real class (not BaseFactory) + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set object description + $this->setObjectDescription("Objekte-Fabrik"); + } + + /** + * Creates a new object given by the name or throws an exception if + * the class was not found. No parameters for the object are currently + * supported. + * + * @param $className Name of the class we shall construct + * @return $objectInstance An instance of the requested object + * @throws ClassNotFoundException If the requested class was not found + * @throws EmptyVariableException If a variable is empty unexpectly + */ + public final static function createObjectByName ($className) { + // First get an instance of this factory + $factoryInstance = new ObjectFactory(); + + // Is the class name valid and is the class there? + if (empty($className)) { + // Throw an exception here + throw new EmptyVariableException(array($factoryInstance, 'className'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (!class_exists($className)) { + // Then throw an exception + throw new ClassNotFoundException($className, self::EXCEPTION_CLASS_NOT_FOUND); + } + + // Then Prepare the eval() command + $eval = sprintf("\$objectInstance = %s::create%s();", + $className, + $className + ); + + // Run the command + eval($eval); + + // Return the prepared instance + return $objectInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/factories/web/class_NewsFactory.php b/inc/classes/main/factories/web/class_NewsFactory.php index d863891..3da66f9 100644 --- a/inc/classes/main/factories/web/class_NewsFactory.php +++ b/inc/classes/main/factories/web/class_NewsFactory.php @@ -23,7 +23,12 @@ */ class NewsFactory extends BaseFactory { /** - * Private constructor + * Instance of a request class + */ + private $requestInstance = null; + + /** + * Protected constructor * * @return void */ @@ -33,9 +38,6 @@ class NewsFactory extends BaseFactory { // Set part description $this->setObjectDescription("News-Fabrik für Webseiten"); - - // Create unique ID number - $this->createUniqueID(); } /** @@ -49,17 +51,66 @@ class NewsFactory extends BaseFactory { // Generate the new instance $factoryInstance = new NewsFactory(); - // Get the element name + // Get the element name from configuration $element = FrameworkConfiguration::getInstance()->readConfig("app_selector_get"); // Analyze the request, first get the Uni* application name (short one from URL) - $appVariable = $requestInstance->getRequestElement($element); + $appName = $requestInstance->getRequestElement($element); + + // Initialize some variables + $className = ""; + $className2 = $appName; + + // Then construct the class name + foreach (array("_", "-") as $exp) { + $array = explode($exp, $className2); + foreach ($array as $el) { + $className .= ucfirst(strtolower($el)); + } - // Add more code here... + // Copy it back and clear the class name + $className2 = $className; + $className = ""; + } + + // After all is done, copy it back and add this class' name + $className = $className2 . $factoryInstance->__toString(); + + // Once we have that name, try to load initialize it + $realFactoryInstance = ObjectFactory::createObjectByName($className); + + // And assign it with the factory + $factoryInstance->setRealFactoryInstance($realFactoryInstance); + + // Remember the request we have used for later usage + $factoryInstance->setRequestInstance($requestInstance); // Return the prepared factory instance return $factoryInstance; } + + /** + * Setter for the request instance + * + * @param $requestInstance An instance of a request object + * @return void + */ + public final function setRequestInstance (Requestable $requestInstance) { + $this->requestInstance = $requestInstance; + } + + /** + * Creates a new object instance and returns it + * + * @return $newsInstance An instance of a news object + */ + public function createNewsObject () { + // Ask the real factory class for doing this + $newsInstance = $this->getRealFactoryInstance()->createNewObject($this->requestInstance); + + // And return it + return $newsInstance; + } } // [EOF] diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php index d442ef3..d947d89 100644 --- a/inc/classes/main/resolver/class_BaseResolver.php +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -33,7 +33,7 @@ class BaseResolver extends BaseFrameworkSystem { private $commandPrefix = ""; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php index 30b31b5..2ab4e50 100644 --- a/inc/classes/main/resolver/web/class_WebCommandResolver.php +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -28,7 +28,7 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { private $lastCommandInstance = ""; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php index c3bebd5..16ad0c2 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -28,7 +28,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { private $lastControllerName = ""; /** - * Private constructor + * Protected constructor * * @return void */