3 namespace CoreFramework\Factory\Login;
6 * A factory class for socket registries
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class LoginFactory extends ObjectFactory {
29 * Protected constructor
33 protected function __construct () {
34 // Call parent constructor
35 parent::__construct(__CLASS__);
39 * Returns a singleton login instance for given request instance.
41 * @param $requestInstance An instance of a Requestable class
42 * @return $loginInstance An instance of a login helper (@TODO Use actual interface name)
44 public static final function createLoginObjectByRequest (Requestable $requestInstance) {
45 // Get registry instance
46 $registryInstance = Registry::getRegistry();
48 // Do we have an instance in the registry?
49 if ($registryInstance->instanceExists('login_helper')) {
50 // Then use this instance
51 $loginInstance = $registryInstance->getInstance('login_helper');
53 // Probe on member instance
55 // Try to instance member login class
56 $loginInstance = self::createObjectByConfiguredName('user_login_class');
59 $loginInstance->testLogin($requestInstance);
60 } catch (UnexpectedGuestAccountException $e) {
61 // Then try guest login
62 $loginInstance = self::createObjectByConfiguredName('guest_login_class');
65 $loginInstance->testLogin($requestInstance);
68 // Set the instance in registry for further use
69 $registryInstance->addInstance('login_helper', $loginInstance);
72 // Return the instance
73 return $loginInstance;