* 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
// Return the instance
return $wrapperInstance;
}
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
}
// [EOF]
* 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;
}
}
* @return void
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get member class
- $userClass = $this->getConfigInstance()->getConfigEntry('user_class');
-
// 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) {
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