All filters rewritten to throw FilterChainException
authorRoland Häder <roland@mxchange.org>
Wed, 11 Mar 2009 03:27:05 +0000 (03:27 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 11 Mar 2009 03:27:05 +0000 (03:27 +0000)
13 files changed:
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/filter/class_FilterChain.php
inc/classes/main/filter/payment/class_PaymentDiscoveryFilter.php
inc/classes/main/filter/validator/class_EmailValidatorFilter.php
inc/classes/main/filter/validator/class_PasswordValidatorFilter.php
inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
inc/classes/main/filter/verifier/class_AccountPasswordVerifierFilter.php
inc/classes/main/filter/verifier/class_ConfirmCodeVerifierFilter.php
inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php
inc/classes/main/filter/verifier/class_PasswordVerifierFilter.php
inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php
inc/classes/main/filter/verifier/class_UserNameVerifierFilter.php
inc/classes/main/registry/class_Registry.php

index 5cc9d81..acea78d 100644 (file)
@@ -149,6 +149,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        const EXCEPTION_ASSERTION_FAILED             = 0x037;
        const EXCEPTION_FILE_CANNOT_BE_READ          = 0x038;
        const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
+       const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x040;
 
        /**
         * In the super constructor these system classes shall be ignored or else
@@ -175,7 +176,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        );
 
        /**
-        * Private super constructor
+        * Protected super constructor
         *
         * @param       $className      Name of the class
         * @return      void
index 9e22ee9..4477726 100644 (file)
@@ -73,13 +73,13 @@ class FilterChain extends BaseFrameworkSystem {
         */
        public function processFilters (Requestable $requestInstance, Responseable $responseInstance) {
                // Run all filters
-               //* DEBUG */ echo "COUNT=".count($this->filters)."<br />\n";
+               /* DEBUG */ echo "COUNT=".count($this->filters)."<br />\n";
                foreach ($this->filters as $filterInstance) {
                        // Try to execute this filter
                        try {
-                               //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.<br />\n";
+                               /* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.<br />\n";
                                $filterInstance->execute($requestInstance, $responseInstance);
-                               //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.<br />\n";
+                               /* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.<br />\n";
                        } catch (FilterChainException $e) {
                                // This exception can be thrown to just skip any further processing
                                break;
index 2439cb5..38891e5 100644 (file)
@@ -95,6 +95,7 @@ class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
         * @todo        0% done
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Try to get real discovery class
@@ -116,7 +117,7 @@ class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessagePlain($e->getMessage());
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } catch (ClassNotFoundException $e) {
                        // Something bad happend
                        $requestInstance->requestIsValid(false);
@@ -126,7 +127,7 @@ class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessagePlain($e->getMessage());
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                }
        }
 }
index fe09faa..9dabfc3 100644 (file)
@@ -54,6 +54,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get Email from request
@@ -74,7 +75,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable {
                                $responseInstance->addFatalMessage('email_unset');
 
                                // Abort here
-                               return false;
+                               throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                        } elseif ((empty($email1)) || (empty($email2))) {
                                // Email is empty
                                $requestInstance->requestIsValid(false);
@@ -92,7 +93,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable {
                                } // END - if
 
                                // Abort here
-                               return false;
+                               throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                        } elseif ($this->ifEmailIsTaken($email1)) {
                                // Email is already taken
                                $requestInstance->requestIsValid(false);
@@ -101,7 +102,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable {
                                $responseInstance->addFatalMessage('email_taken');
 
                                // Abort here
-                               return false;
+                               throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                        } elseif ($email1 != $email2) {
                                // Emails didn't match
                                $requestInstance->requestIsValid(false);
@@ -110,7 +111,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable {
                                $responseInstance->addFatalMessage('emails_mismatch');
 
                                // Abort here
-                               return false;
+                               throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                        } // END - elseif
                } elseif (empty($email)) {
                        // Empty field!
@@ -120,7 +121,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('email_empty');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } // END - elseif
        }
 
index 3bb5ecb..ba39cda 100644 (file)
@@ -52,6 +52,7 @@ class PasswordValidatorFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get passwords
@@ -67,7 +68,7 @@ class PasswordValidatorFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('password_unset');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif ((empty($password1)) || (empty($password2))) {
                        // Password is empty
                        $requestInstance->requestIsValid(false);
@@ -85,7 +86,7 @@ class PasswordValidatorFilter extends BaseFilter implements Filterable {
                        } // END - if
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif ($password1 != $password2) {
                        // Passwords didn't match
                        $requestInstance->requestIsValid(false);
@@ -94,7 +95,7 @@ class PasswordValidatorFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('pass_mismatch');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } // END - elseif
        }
 }
index 81ff531..9095068 100644 (file)
@@ -53,6 +53,7 @@ class UserNameValidatorFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get username from request
@@ -67,7 +68,7 @@ class UserNameValidatorFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_unset');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif (empty($userName)) {
                        // Empty field!
                        $requestInstance->requestIsValid(false);
@@ -76,7 +77,7 @@ class UserNameValidatorFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_empty');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif ($this->ifUserNameIsTaken($userName)) {
                        // Username is already taken
                        $requestInstance->requestIsValid(false);
@@ -85,7 +86,7 @@ class UserNameValidatorFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_taken');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                }
        }
 
index 35f38ce..95aea2b 100644 (file)
@@ -53,6 +53,7 @@ class AccountPasswordVerifierFilter extends BaseFilter implements Filterable {
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
         * @throws      AccountPasswordMismatchException        If the account password does not match
+        * @throws      FilterChainException                            If this filter fails to operate
         * @todo        Rewrite handling of different password fields
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
@@ -73,7 +74,7 @@ class AccountPasswordVerifierFilter extends BaseFilter implements Filterable {
                                $responseInstance->addFatalMessage('password_unset');
 
                                // Abort here
-                               return false;
+                               throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                        } // END - if
                } // END - if
 
@@ -85,8 +86,8 @@ class AccountPasswordVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('password_empty');
 
                        // Abort here
-                       return false;
-               }
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
+               } // END - if
 
                // Get a user instance
                $userInstance = Registry::getRegistry()->getInstance('user');
index 8f42640..e8e55c4 100644 (file)
@@ -52,6 +52,7 @@ class ConfirmCodeVerifierFilter extends BaseFilter implements Filterable {
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
         * @throws      NullPointerException    If the user instance from registry is null
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get confirmation code from request
@@ -66,7 +67,7 @@ class ConfirmCodeVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('confirm_code_unset');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif (empty($confirmCode)) {
                        // Email is empty
                        $requestInstance->requestIsValid(false);
@@ -75,7 +76,7 @@ class ConfirmCodeVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('confirm_code_empty');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                }
 
                // Get a user instance from registry
index d4c3bfd..dda9a2e 100644 (file)
@@ -52,6 +52,7 @@ class PasswordGuestVerifierFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get password
@@ -66,7 +67,7 @@ class PasswordGuestVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('password_unset');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif (empty($password)) {
                        // Password is empty
                        $requestInstance->requestIsValid(false);
@@ -75,7 +76,7 @@ class PasswordGuestVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('password_empty');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                }
        }
 }
index 309371c..d924c5b 100644 (file)
@@ -52,6 +52,7 @@ class PasswordVerifierFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get password
@@ -66,7 +67,7 @@ class PasswordVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('password_unset');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif (empty($password)) {
                        // Password is empty
                        $requestInstance->requestIsValid(false);
@@ -75,7 +76,7 @@ class PasswordVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('password_empty');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                }
        }
 }
index 51c2e6f..b6ad60b 100644 (file)
@@ -53,6 +53,7 @@ class UserGuestVerifierFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get username from request
@@ -67,7 +68,7 @@ class UserGuestVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_guest_unset');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif (empty($userName)) {
                        // Empty field!
                        $requestInstance->requestIsValid(false);
@@ -76,7 +77,7 @@ class UserGuestVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_guest_empty');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif ($this->ifUserGuestIsTaken($userName) === false) {
                        // Username is already taken
                        $requestInstance->requestIsValid(false);
@@ -85,7 +86,7 @@ class UserGuestVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_guest_not_found');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                }
 
                // Set the element for compatiblity reasons
index 82d1eeb..32f0aa2 100644 (file)
@@ -53,6 +53,7 @@ class UserNameVerifierFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
+        * @throws      FilterChainException    If this filter fails to operate
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get username from request
@@ -67,7 +68,7 @@ class UserNameVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_unset');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif (empty($userName)) {
                        // Empty field!
                        $requestInstance->requestIsValid(false);
@@ -76,7 +77,7 @@ class UserNameVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_empty');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                } elseif ($this->ifUserNameIsTaken($userName) === false) {
                        // Username is already taken
                        $requestInstance->requestIsValid(false);
@@ -85,7 +86,7 @@ class UserNameVerifierFilter extends BaseFilter implements Filterable {
                        $responseInstance->addFatalMessage('username_not_found');
 
                        // Abort here
-                       return false;
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
                }
        }
 
index 243c2b4..d5ad6e6 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
- * A registry for several data types
+ * A registry for several data types and objects. Objects should be added by
+ * addInstance() and therefore must implement the interface Registerable.
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
@@ -62,7 +63,7 @@ class Registry extends BaseFrameworkSystem implements Register {
                if (is_null(self::$registryInstance)) {
                        // Not yet, so create one
                        self::$registryInstance = new Registry();
-               }
+               } // END - if
 
                // Return the instance
                return self::$registryInstance;
@@ -126,7 +127,7 @@ class Registry extends BaseFrameworkSystem implements Register {
                // Is the instance there?
                if ($this->instanceExists($instanceKey)) {
                        $objectInstance = $this->instanceRegistry[$instanceKey];
-               }
+               } // END - if
 
                // Return the result
                return $objectInstance;