]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/factories/login/class_LoginFactory.php
More fixes ...
[core.git] / inc / classes / main / factories / login / class_LoginFactory.php
index 1bc386929233562270527ca86ab2839cebf53af1..3faf50eb7e0b7a6edcbb708ff181f273663b5a2f 100644 (file)
  * 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
+        * @return      $loginInstance          An instance of a login helper (@TODO Use actual interface name)
         */
-       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?
-               if ($registryInstance->instanceExists($wrapperName)) {
+               if ($registryInstance->instanceExists('login_helper')) {
                        // Then use this instance
-                       $wrapperInstance = $registryInstance->getInstance($wrapperName);
+                       $loginInstance = $registryInstance->getInstance('login_helper');
                } else {
-                       // Get the registry instance
-                       $wrapperInstance = self::createObjectByConfiguredName($wrapperName);
+                       // Probe on member instance
+                       try {
+                               // Try to instance member login class
+                               $loginInstance = self::createObjectByConfiguredName('user_login_class');
+
+                               // Test login
+                               $loginInstance->testLogin($requestInstance);
+                       } catch (UnexpectedGuestAccountException $e) {
+                               // Then try guest login
+                               $loginInstance = self::createObjectByConfiguredName('guest_login_class');
+
+                               // Test login again
+                               $loginInstance->testLogin($requestInstance);
+                       }
 
                        // Set the instance in registry for further use
-                       $registryInstance->addInstance($wrapperName, $wrapperInstance);
+                       $registryInstance->addInstance('login_helper', $loginInstance);
                }
 
                // Return the instance
-               return $wrapperInstance;
-       }
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
+               return $loginInstance;
        }
 }