]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/factories/login/class_LoginFactory.php
This is more flexible so better take it.
[core.git] / inc / classes / main / factories / login / class_LoginFactory.php
index 1bc386929233562270527ca86ab2839cebf53af1..01b042cc6a32f463b5f8b78471e603f3de2d2b2a 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
         */
-       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);
+                       $userInstance = $registryInstance->getInstance('login_helper');
                } 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
-                       $registryInstance->addInstance($wrapperName, $wrapperInstance);
+                       $registryInstance->addInstance('login_helper', $userInstance);
                }
 
                // Return the instance
-               return $wrapperInstance;
-       }
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
+               return $userInstance;
        }
 }