]> git.mxchange.org Git - shipsimu.git/commitdiff
Registerable instances now possible, some fixes in filters
authorRoland Häder <roland@mxchange.org>
Mon, 2 Jun 2008 18:13:56 +0000 (18:13 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 2 Jun 2008 18:13:56 +0000 (18:13 +0000)
.gitattributes
application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php
inc/classes/interfaces/registry/.htaccess [new file with mode: 0644]
inc/classes/interfaces/registry/class_Register.php [new file with mode: 0644]
inc/classes/interfaces/registry/class_Registerable.php [new file with mode: 0644]
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/filter/validator/class_EmailValidatorFilter.php
inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
inc/classes/main/registry/class_Registry.php
inc/classes/main/user/class_User.php

index 056bd05426e2426b930b0fbe1d173b1b4e78ade9..7a53fb085722f743633bd490e9d6268041784b36 100644 (file)
@@ -256,6 +256,9 @@ inc/classes/interfaces/io/output/.htaccess -text
 inc/classes/interfaces/io/output/class_OutputStreamer.php -text
 inc/classes/interfaces/language/.htaccess -text
 inc/classes/interfaces/language/class_ManageableLanguage.php -text
+inc/classes/interfaces/registry/.htaccess -text
+inc/classes/interfaces/registry/class_Register.php -text
+inc/classes/interfaces/registry/class_Registerable.php -text
 inc/classes/interfaces/request/.htaccess -text
 inc/classes/interfaces/request/class_Requestable.php -text
 inc/classes/interfaces/resolver/.htaccess -text
index a419393fb379cc4b97305fd579662c0bb39b63c7..29a6da4ae9a9f84f1ca8dee04c1d27f8e575d771 100644 (file)
@@ -59,8 +59,8 @@ class WebShipsimuRegisterCommand extends BaseCommand implements Commandable {
                $controllerInstance = $resolverInstance->getControllerInstance();
 
                // @TODO Add some more pre/post filters to the controller
-               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_validator'));
                $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_validator'));
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_validator'));
 
                // Return the prepared instance
                return $commandInstance;
diff --git a/inc/classes/interfaces/registry/.htaccess b/inc/classes/interfaces/registry/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/interfaces/registry/class_Register.php b/inc/classes/interfaces/registry/class_Register.php
new file mode 100644 (file)
index 0000000..770755e
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * An interface for registries
+ *
+ * @author             Roland Haeder <webmaster@mxchange.org>
+ * @version            0.0.0
+ * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Register extends FrameworkInterface {
+       /**
+        * Checks wether an instance key was found
+        *
+        * @param       $instanceKey    The key holding an instance in the registry
+        * @return      $exists                 Wether the key exists in the registry
+        */
+       function instanceExists ($instanceKey);
+}
+
+//
+?>
diff --git a/inc/classes/interfaces/registry/class_Registerable.php b/inc/classes/interfaces/registry/class_Registerable.php
new file mode 100644 (file)
index 0000000..f1d60f2
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * A class for registerable classes
+ *
+ * @author             Roland Haeder <webmaster@mxchange.org>
+ * @version            0.0.0
+ * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Registerable extends FrameworkInterface {
+}
+
+//
+?>
index 28627720d238a7c104d3e13e4fdcb717faecc7c2..0d8213210adf2000e0592850a8902b8258cf1755 100644 (file)
@@ -249,6 +249,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                                } elseif (is_string($arg)) {
                                        // String
                                        $argsString .= "\"".$arg."\"(string)";
+                               } elseif (is_null($arg)) {
+                                       // Null
+                                       $argsString .= "(null)";
                                } else {
                                        // Unknown type (please report!)
                                        $argsString .= $arg."(unknown!)";
@@ -629,10 +632,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * Formats computer generated price values into human-understandable formats
         * with thousand and decimal seperators.
         *
-        * @param               $value  The in computer format value for a price
-        * @param               $currency       The currency symbol (use HTML-valid characters!)
-        * @param               $decNum Number of decimals after commata
-        * @return      $price  The for the current language formated price string
+        * @param       $value          The in computer format value for a price
+        * @param       $currency       The currency symbol (use HTML-valid characters!)
+        * @param       $decNum         Number of decimals after commata
+        * @return      $price          The for the current language formated price string
         * @throws      MissingDecimalsThousandsSeperatorException      If decimals or
         *                                                                                              thousands seperator
         *                                                                                              is missing
index a2f5628efc46c863d3d7f0c990cbd82728245ede..8d9117bd89460dba4bfc13b609b9ecba9f1d8db6 100644 (file)
@@ -135,20 +135,23 @@ class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable {
                // Default is already taken
                $alreadyTaken = true;
 
+               // Initialize instance
+               $userInstance = null;
+
                // Get a registry instance
                $registry = Registry::getInstance();
 
                // Is the user already there?
-               if ($registry->keyExists('userInstance')) {
+               if ($registry->instanceExists('user')) {
                        // Use the instance for checking for the email
-                       $userInstance = $registry->getInstance('userInstance');
+                       $userInstance = $registry->getInstance('user');
                        $userInstance->setEmailAddress($email);
                } else {
                        // If this instance is created then the username *does* exist
-                       $userInstance = User::createUserByEmail($userName);
+                       $userInstance = User::createUserByEmail($email);
 
                        // Remember this user instance in our registry for later usage
-                       $registry->addInstance('userInstance', $userInstance);
+                       $registry->addInstance('user', $userInstance);
                }
 
                // Does the email exist?
index cb82296417ac0c9536da564ace58fa199b84fcad..38471cdecb248553e631194a19bdcd18724a68b5 100644 (file)
@@ -110,6 +110,9 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                // Default is already taken
                $alreadyTaken = true;
 
+               // Initialize instance
+               $userInstance = null;
+
                // Get a registry instance
                $registry = Registry::getInstance();
 
@@ -119,14 +122,18 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                        $userInstance = $registry->getInstance('user');
                } else {
                        // If this instance is created then the username *does* exist
-                       $userInstance = User::createUserByUsername($userName);
-
-                       // Remember this user instance in our registry for later usage
-                       $registry->addInstance('user', $userInstance);
+                       try {
+                               $userInstance = User::createUserByUsername($userName);
+
+                               // Remember this user instance in our registry for later usage
+                               $registry->addInstance('user', $userInstance);
+                       } catch (UsernameMissingException $e) {
+                               // User was not found
+                       }
                }
 
                // Does the username exist?
-               if (!$userInstance->ifUsernameExists()) {
+               if ((is_null($userInstance)) || (!$userInstance->ifUsernameExists())) {
                        // This username is still available
                        $alreadyTaken = false;
                }
index 8c69c2dd2718f816b0be0f19158ac1fa51793542..0ceda2c0c4016ebd04830884fd93aff9770d1ecf 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 Registry extends BaseFrameworkSystem {
+class Registry extends BaseFrameworkSystem implements Register {
        /**
         * Instance of this class
         */
        private static $selfInstance = null;
 
+       /**
+        * Instance registry
+        */
+       private $instanceRegistry = array();
+
        /**
         * Protected constructor
         *
@@ -62,6 +67,31 @@ class Registry extends BaseFrameworkSystem {
                // Return the instance
                return self::$selfInstance;
        }
+
+       /**
+        * Checks wether an instance key was found
+        *
+        * @param       $instanceKey    The key holding an instance in the registry
+        * @return      $exists                 Wether the key exists in the registry
+        */
+       public function instanceExists ($instanceKey) {
+               // Does this key exists?
+               $exists = (isset($this->instanceRegistry[$instanceKey]));
+
+               // Return the result
+               return $exists;
+       }
+
+       /**
+        * Adds/overwrites a new instance to the registry at the given key
+        *
+        * @param       $instanceKey            The key to identify the instance
+        * @param       $objectInstance         An instance we shall store
+        * @return      void
+        */
+       public function addInstance ($instanceKey, Registerable $objectInstance) {
+               $this->instanceRegistry[$instanceKey] = $objectInstance;
+       }
 }
 
 // [EOF]
index 7d1d060cdbb96207a8e816dfc740913d3ea9feb7..05afd6dab226b11a4c7530e081af2d96301fe813 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;
@@ -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;
        }
 
        /**