This is more flexible so better take it.
authorRoland Haeder <roland@mxchange.org>
Sat, 18 Apr 2015 10:15:44 +0000 (12:15 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 18 Apr 2015 10:15:44 +0000 (12:15 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/main/factories/database/class_DatabaseWrapperFactory.php
inc/classes/main/factories/login/class_LoginFactory.php
inc/classes/main/filter/verifier/class_UserUnconfirmedVerifierFilter.php
inc/classes/main/user/guest/class_Guest.php

index f77492843408dcbcdc311e32cc253f06a7b69ee3..5ecdea49a702be2cc9816e07a86261906f8039e2 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class DatabaseWrapperFactory extends ObjectFactory {
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class DatabaseWrapperFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
        /**
         * Returns a singleton socket registry instance. If an instance is found in
         * the registry it will be returned, else a new instance is created and
        /**
         * Returns a singleton socket registry instance. If an instance is found in
         * the registry it will be returned, else a new instance is created and
@@ -48,16 +58,6 @@ class DatabaseWrapperFactory extends ObjectFactory {
                // Return the instance
                return $wrapperInstance;
        }
                // Return the instance
                return $wrapperInstance;
        }
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
 }
 
 // [EOF]
 }
 
 // [EOF]
index 1bc386929233562270527ca86ab2839cebf53af1..01b042cc6a32f463b5f8b78471e603f3de2d2b2a 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class LoginFactory extends ObjectFactory {
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class LoginFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
        /**
         * Returns a singleton login instance for given request instance.
         *
         * @param       $requestInstance        An instance of a Requestable class
         * @return      $wrapperInstance        A database wrapper instance
         */
        /**
         * Returns a singleton login instance for given request instance.
         *
         * @param       $requestInstance        An instance of a Requestable class
         * @return      $wrapperInstance        A database wrapper instance
         */
-       public static final function createWrapperByConfiguredName (Requestable $requestInstance) {
-               // 
-               die('requestInstance=<pre>'.print_r($requestInstance, TRUE).'</pre>');
-
+       public static final function createLoginObjectByRequest (Requestable $requestInstance) {
                // Get registry instance
                $registryInstance = Registry::getRegistry();
 
                // Do we have an instance in the registry?
                // Get registry instance
                $registryInstance = Registry::getRegistry();
 
                // Do we have an instance in the registry?
-               if ($registryInstance->instanceExists($wrapperName)) {
+               if ($registryInstance->instanceExists('login_helper')) {
                        // Then use this instance
                        // Then use this instance
-                       $wrapperInstance = $registryInstance->getInstance($wrapperName);
+                       $userInstance = $registryInstance->getInstance('login_helper');
                } else {
                } else {
-                       // Get the registry instance
-                       $wrapperInstance = self::createObjectByConfiguredName($wrapperName);
+                       // Probe on member instance
+                       try {
+                               // Get class name
+                               $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry('user_class');
+
+                               // Try to instance it
+                               $userInstance = call_user_func_array(array($className, 'createMemberByRequest'), array($requestInstance));
+                       } catch (UnexpectedGuestAccountException $e) {
+                               // Then try it with guest account
+                               $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry('guest_class');
+
+                               // Try to instance it
+                               $userInstance = call_user_func_array(array($className, 'createGuestByRequest'), array($requestInstance));
+                       }
 
                        // Set the instance in registry for further use
 
                        // Set the instance in registry for further use
-                       $registryInstance->addInstance($wrapperName, $wrapperInstance);
+                       $registryInstance->addInstance('login_helper', $userInstance);
                }
 
                // Return the instance
                }
 
                // Return the instance
-               return $wrapperInstance;
-       }
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
+               return $userInstance;
        }
 }
 
        }
 }
 
index 2bdaf07c75f879cfd9662fad857f7bb25be40c79..c8e6f427362c8c2d962c07cb586624a414ad51ab 100644 (file)
@@ -53,11 +53,8 @@ class UserUnconfirmedVerifierFilter extends BaseFilter implements Filterable {
         * @return      void
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
         * @return      void
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
-               // Get member class
-               $userClass = $this->getConfigInstance()->getConfigEntry('user_class');
-
                // Get a user instance for comparison
                // Get a user instance for comparison
-               $userInstance = call_user_func_array(array($userClass, 'createMemberByRequest'), array($requestInstance));
+               $userInstance = LoginFactory::createLoginObjectByRequest($requestInstance);
 
                // Is the email address valid?
                if ($userInstance->ifEmailAddressExists() === FALSE) {
 
                // Is the email address valid?
                if ($userInstance->ifEmailAddressExists() === FALSE) {
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