X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ffactories%2Flogin%2Fclass_LoginFactory.php;h=01b042cc6a32f463b5f8b78471e603f3de2d2b2a;hp=1bc386929233562270527ca86ab2839cebf53af1;hb=6fd01888b51f210394c4b7bb5e0ac2a28efb0c99;hpb=ddead341812b4924bc1591780090444c6f58e9a5 diff --git a/inc/classes/main/factories/login/class_LoginFactory.php b/inc/classes/main/factories/login/class_LoginFactory.php index 1bc38692..01b042cc 100644 --- a/inc/classes/main/factories/login/class_LoginFactory.php +++ b/inc/classes/main/factories/login/class_LoginFactory.php @@ -22,43 +22,52 @@ * along with this program. If not, see . */ 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=
'.print_r($requestInstance, TRUE).'
'); - + 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; } }