]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/factories/web/class_NewsFactory.php
More smaller fixes, factory added to ship-simu
[shipsimu.git] / inc / classes / main / factories / web / class_NewsFactory.php
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ü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]