]> git.mxchange.org Git - shipsimu.git/commitdiff
More smaller fixes, factory added to ship-simu
authorRoland Häder <roland@mxchange.org>
Thu, 15 May 2008 09:27:16 +0000 (09:27 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 15 May 2008 09:27:16 +0000 (09:27 +0000)
20 files changed:
.gitattributes
application/ship-simu/main/class_
application/ship-simu/main/class_WorksContract.php
application/ship-simu/main/companies/class_ShippingCompany.php
application/ship-simu/main/factories/.htaccess [new file with mode: 0644]
application/ship-simu/main/factories/class_ShipSimuNewsFactory.php [new file with mode: 0644]
application/ship-simu/main/ships/class_BaseShip.php
inc/classes/exceptions/main/class_ClassNotFoundException.php
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/commands/web/class_WebHomeCommand.php
inc/classes/main/controller/default/class_WebDefaultController.php
inc/classes/main/controller/default/class_WebDefaultNewsController.php
inc/classes/main/controller/registration/class_DefaultRegistrationController.php
inc/classes/main/factories/class_BaseFactory.php
inc/classes/main/factories/objects/.htaccess [new file with mode: 0644]
inc/classes/main/factories/objects/class_ObjectFactory.php [new file with mode: 0644]
inc/classes/main/factories/web/class_NewsFactory.php
inc/classes/main/resolver/class_BaseResolver.php
inc/classes/main/resolver/web/class_WebCommandResolver.php
inc/classes/main/resolver/web/class_WebControllerResolver.php

index a5e046ff5cf496882900cd5bfaef7dba402b7d0f..bc7b93097b16b9082c1bda67f832af7f44aa780e 100644 (file)
@@ -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
index 9644fd588c50c8b7a5f4f1054962c771c2b5f5ae..af4096f64df8b08521927573a48ac0c0f6ba584e 100644 (file)
@@ -1,7 +1,47 @@
-
+<?php
+/**
+ * 
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index fdcc74a9ce80c64b43e404b99c19da54d067b6cb..cd2f0450937712276cd6003454b166802fa0e11a 100644 (file)
@@ -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());
                }
index 1dba1682a48dd4647dc26627af58786644b99097..dec3a3228f0316d3467e2536b03d8f15df224b4f 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..7e60b34
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * A class for the special news object factory
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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&uuml;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]
+?>
index 4799c0e5ea8b65caeb19cced8910b27654d1a9bf..6e0ef56d26b545a3a71e5cc2794c65f4e5027dd2 100644 (file)
@@ -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...
index 897f220b9c6157b399ba2a993e1ac8d1aab8eaa5..b77de9a7feba906fcfc938cf9c90669948e472cc 100644 (file)
@@ -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 <u>%s</u> konnte nicht gefunden werden!", $class);
 
index 8dbbdaa9ab71a2827fdaab8433143381fce5cb76..f341fc9d33f2335b07cd8966133fc15df9a36337 100644 (file)
@@ -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
index f45b0d7960f141b6f729b14d811da9b7ff9f9adf..9629b9742d54b8f00261a19ee64c26e3f4b8b33c 100644 (file)
@@ -23,7 +23,7 @@
  */
 class WebHomeCommand extends BaseCommand implements Commandable {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 38d92ce366590be62b9524b76a0bb7c03d732ee8..9830891940ee7417009244ca9ca43d72b412032d 100644 (file)
@@ -28,7 +28,7 @@ class WebWebDefaultController extends BaseController implements Controller {
        private $resolverInstance = null;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 835f94b88ea3393fd94aafdf5149c8924b9519cc..ea690a9ec85d13399fadf5d64537cdb4142f8bda 100644 (file)
@@ -28,7 +28,7 @@ class WebDefaultNewsController extends BaseController implements Controller {
        private $resolverInstance = null;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 2f15e400db7221498f4e0c33db858315cc207abe..24d7040f7a93be7f5f99069bcf3a38daa386a327 100644 (file)
@@ -24,7 +24,7 @@
  */
 class DefaultRegistrationController extends BaseController implements Controller {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 11c8ec960649c541d8d78cd127a4f13cf0994ff2..db2611c28913aa784557c8d4b945eda19865cf59 100644 (file)
  */
 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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..fd983ca
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+/**
+ * An general object factory
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index d86389119c5577ad1559281779de68da09abdcf1..3da66f9f7bd7f759fb74bebbbd6a14ef3f25a7b7 100644 (file)
  */
 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&uuml;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]
index d442ef38e465b9cb9d926912e67879aad2e2b8b4..d947d89e318df1e89495e419d8d9f3fa06088edb 100644 (file)
@@ -33,7 +33,7 @@ class BaseResolver extends BaseFrameworkSystem {
        private $commandPrefix = "";
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 30b31b5240dd13284fd9235720fb0b5ae4cecaaf..2ab4e50035275e81cff71b98f26c6673a72d4dad 100644 (file)
@@ -28,7 +28,7 @@ class WebCommandResolver extends BaseResolver implements CommandResolver {
        private $lastCommandInstance = "";
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index c3bebd50f41c85f2f197b2fa634c23ccf8239cc0..16ad0c2c40dbbbcbfa2e7a46eeb7b352cbd6a97b 100644 (file)
@@ -28,7 +28,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
        private $lastControllerName = "";
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */