3 namespace CoreFramework\User\Guest;
5 // Import framework stuff
6 use CoreFramework\Registry\Registerable;
9 * A generic class for handling guests
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class Guest extends BaseUser implements ManageableGuest, Registerable {
32 const EXCEPTION_USERNAME_NOT_FOUND = 0x170;
33 const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x171;
34 const EXCEPTION_USER_PASS_MISMATCH = 0x172;
35 const EXCEPTION_USER_NOT_GUEST = 0x173;
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Creates a user by a given request instance
50 * @param $requestInstance An instance of a Requestable class
51 * @return $userInstance An instance of this user class
52 * @todo Add more ways over creating user classes
54 public static final function createGuestByRequest (Requestable $requestInstance) {
55 // Determine if by email or username
56 if (!is_null($requestInstance->getRequestElement('username'))) {
58 $userInstance = self::createGuestByUserName($requestInstance->getRequestElement('username'));
59 } elseif (!is_null($requestInstance->getRequestElement('email'))) {
61 $userInstance = self::createGuestByEmail($requestInstance->getRequestElement('email'));
64 $userInstance = new Guest();
65 $userInstance->debugBackTrace('More ways of creating user classes are needed here.');
69 // Return the prepared instance
74 * Creates an instance of this user class by a provided username. This
75 * factory method will check if username is already taken and if not so it
76 * will throw an exception.
78 * @param $userName Username we need a class instance for
79 * @return $userInstance An instance of this user class
80 * @throws UsernameMissingException If the username does not exist
81 * @throws UserNoGuestException If the user is no guest account
83 public static final function createGuestByUsername ($userName) {
85 $userInstance = new Guest();
88 $userInstance->setUserName($userName);
90 // Check if username exists
91 if ($userInstance->ifUsernameExists() === FALSE) {
92 // Throw an exception here
93 throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
94 } elseif ($userInstance->isGuest() === FALSE) {
95 // Sanity check on 'guest' status failed
96 throw new UserNoGuestException(array($userInstance, $userName), self::EXCEPTION_USER_NOT_GUEST_STATUS);
99 // Return the instance
100 return $userInstance;
104 * Creates an instance of this user class by a provided email address. This
105 * factory method will not check if email address is there.
107 * @param $email Email address of the user
108 * @return $userInstance An instance of this user class
110 public static final function createGuestByEmail ($email) {
111 // Get a new instance
112 $userInstance = new Guest();
115 $userInstance->setEmail($email);
117 // Return the instance
118 return $userInstance;
122 * Updates the last activity timestamp and last performed action in the
123 * database result. You should call flushPendingUpdates() to flush these updates
124 * to the database layer.
126 * @param $requestInstance A requestable class instance
129 public function updateLastActivity (Requestable $requestInstance) {
130 // No activity will be logged for guest accounts
134 * Flushs all pending updates to the database layer
138 public function flushPendingUpdates () {
139 // No updates will be flushed to database!