3 namespace Org\Mxchange\CoreFramework\User\Guest;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Manager\Guest\ManageableGuest;
7 use Org\Mxchange\CoreFramework\Registry\Registerable;
8 use Org\Mxchange\CoreFramework\Request\Requestable;
9 use Org\Mxchange\CoreFramework\User\BaseUser;
12 * A generic class for handling guests
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.shipsimu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 class Guest extends BaseUser implements ManageableGuest, Registerable {
35 const EXCEPTION_USERNAME_NOT_FOUND = 0x170;
36 const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x171;
37 const EXCEPTION_USER_PASS_MISMATCH = 0x172;
38 const EXCEPTION_USER_NOT_GUEST = 0x173;
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
51 * Creates a user by a given request instance
53 * @param $requestInstance An instance of a Requestable class
54 * @return $userInstance An instance of this user class
55 * @todo Add more ways over creating user classes
57 public static final function createGuestByRequest (Requestable $requestInstance) {
58 // Determine if by email or username
59 if (!is_null($requestInstance->getRequestElement('username'))) {
61 $userInstance = self::createGuestByUserName($requestInstance->getRequestElement('username'));
62 } elseif (!is_null($requestInstance->getRequestElement('email'))) {
64 $userInstance = self::createGuestByEmail($requestInstance->getRequestElement('email'));
67 $userInstance = new Guest();
68 $userInstance->debugBackTrace('More ways of creating user classes are needed here.');
72 // Return the prepared instance
77 * Creates an instance of this user class by a provided username. This
78 * factory method will check if username is already taken and if not so it
79 * will throw an exception.
81 * @param $userName Username we need a class instance for
82 * @return $userInstance An instance of this user class
83 * @throws UsernameMissingException If the username does not exist
84 * @throws UserNoGuestException If the user is no guest account
86 public static final function createGuestByUsername ($userName) {
88 $userInstance = new Guest();
91 $userInstance->setUserName($userName);
93 // Check if username exists
94 if ($userInstance->ifUsernameExists() === false) {
95 // Throw an exception here
96 throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
97 } elseif ($userInstance->isGuest() === false) {
98 // Sanity check on 'guest' status failed
99 throw new UserNoGuestException(array($userInstance, $userName), self::EXCEPTION_USER_NOT_GUEST_STATUS);
102 // Return the instance
103 return $userInstance;
107 * Creates an instance of this user class by a provided email address. This
108 * factory method will not check if email address is there.
110 * @param $email Email address of the user
111 * @return $userInstance An instance of this user class
113 public static final function createGuestByEmail ($email) {
114 // Get a new instance
115 $userInstance = new Guest();
118 $userInstance->setEmail($email);
120 // Return the instance
121 return $userInstance;
125 * Updates the last activity timestamp and last performed action in the
126 * database result. You should call flushPendingUpdates() to flush these updates
127 * to the database layer.
129 * @param $requestInstance A requestable class instance
132 public function updateLastActivity (Requestable $requestInstance) {
133 // No activity will be logged for guest accounts
137 * Flushs all pending updates to the database layer
141 public function flushPendingUpdates () {
142 // No updates will be flushed to database!