]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/user/class_User.php
Access level fixed, registry is able to return instances
[shipsimu.git] / inc / classes / main / user / class_User.php
index ad4498cb56db5dee9b704e27ea3b583b6bc709d5..564d0ecf21e652ccf63c3ed54fbf4d1a5631d212 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class User extends BaseFrameworkSystem implements ManageableUser {
+class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
        /**
-        * Username
+        * Username of current user
         */
-       private $username = "";
+       private $userName = "";
+
+       /**
+        * Email of current user
+        */
+       private $email = "";
 
        // Exceptions
        const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
@@ -58,7 +63,7 @@ class User extends BaseFrameworkSystem implements ManageableUser {
         * factory method will check if the username is already taken and if not
         * so it will throw an exception.
         *
-        * @param       $username               Username we need a class instance for
+        * @param       $userName               Username we need a class instance for
         * @return      $userInstance   An instance of this user class
         * @throws      UsernameMissingException        If the username does not exist
         */
@@ -79,6 +84,24 @@ class User extends BaseFrameworkSystem implements ManageableUser {
                return $userInstance;
        }
 
+       /**
+        * Creates an instance of this user class by a provided email address. This
+        * factory method will not check if the email address is there.
+        *
+        * @param       $email                  Email address of the user
+        * @return      $userInstance   An instance of this user class
+        */
+       public final static function createUserByEmail ($email) {
+               // Get a new instance
+               $userInstance = new User();
+
+               // Set the username
+               $userInstance->setEmail($email);
+
+               // Return the instance
+               return $userInstance;
+       }
+
        /**
         * Setter for username
         *
@@ -86,7 +109,17 @@ class User extends BaseFrameworkSystem implements ManageableUser {
         * @return      void
         */
        protected final function setUsername ($userName) {
-               $this->userNane = $userName;
+               $this->UserName = $userName;
+       }
+
+       /**
+        * Setter for email
+        *
+        * @param       $email  The email to set
+        * @return      void
+        */
+       protected final function setEmail ($email) {
+               $this->userName = $email;
        }
 
        /**
@@ -95,7 +128,16 @@ class User extends BaseFrameworkSystem implements ManageableUser {
         * @return      $userName       The username to get
         */
        public final function getUsername () {
-               return $this->userNane;
+               return $this->userName;
+       }
+
+       /**
+        * Getter for email
+        *
+        * @return      $email  The email to get
+        */
+       public final function getEmail () {
+               return $this->email;
        }
 
        /**
@@ -103,7 +145,7 @@ class User extends BaseFrameworkSystem implements ManageableUser {
         *
         * @return      $exists         Wether the username exists
         */
-       protected function ifUsernameExists () {
+       public function ifUsernameExists () {
                // By default the username does exist
                $exists = true;