This is more flexible so better take it.
[core.git] / inc / classes / main / user / guest / class_Guest.php
index e2911cf3b81709c56e7c094eb4219085c1aeeae9..6fdefc7f5b52a28676e9095b9c62bda77ea65641 100644 (file)
@@ -38,6 +38,32 @@ class Guest extends BaseUser implements ManageableGuest, Registerable {
                parent::__construct(__CLASS__);
        }
 
                parent::__construct(__CLASS__);
        }
 
+       /**
+        * Creates a user by a given request instance
+        *
+        * @param       $requestInstance        An instance of a Requestable class
+        * @return      $userInstance           An instance of this user class
+        * @todo        Add more ways over creating user classes
+        */
+       public static final function createGuestByRequest (Requestable $requestInstance) {
+               // Determine if by email or username
+               if (!is_null($requestInstance->getRequestElement('username'))) {
+                       // Username supplied
+                       $userInstance = self::createGuestByUserName($requestInstance->getRequestElement('username'));
+               } elseif (!is_null($requestInstance->getRequestElement('email'))) {
+                       // Email supplied
+                       $userInstance = self::createGuestByEmail($requestInstance->getRequestElement('email'));
+               } else {
+                       // Unsupported mode
+                       $userInstance = new Guest();
+                       $userInstance->debugBackTrace('More ways of creating user classes are needed here.');
+                       exit();
+               }
+
+               // Return the prepared instance
+               return $userInstance;
+       }
+
        /**
         * Creates an instance of this user class by a provided username. This
         * factory method will check if username is already taken and if not so it
        /**
         * Creates an instance of this user class by a provided username. This
         * factory method will check if username is already taken and if not so it