addFilter() should also throw an InvalidFilterChainException
[core.git] / inc / classes / main / controller / class_BaseController.php
index 5e56de17156a857b5954b8bb03dc0b947cf4a8bc..95827c5e89eeb3ce87638972f9994ff6433e8471 100644 (file)
@@ -29,6 +29,9 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
         */
        private $filterChains = array();
 
+       // Exception constants
+       const EXCEPTION_FILTER_CHAIN_INVALID = 0xf10;
+
        /**
         * Protected constructor
         *
@@ -67,8 +70,16 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
         * @param       $filterGroup    Group of the filter
         * @param       $filterInstance         An instance of a filter
         * @return      void
+        * @throws      InvalidFilterChainException     If the filter chain is invalid
         */
        protected function addFilter ($filterGroup, Filterable $filterInstance) {
+               // Test if the filter is there
+               if (!isset($this->filterChains[$filterGroup])) {
+                       // Throw an exception here
+                       throw new InvalidFilterChainException(array($this, $filterGroup), self::EXCEPTION_FILTER_CHAIN_INVALID);
+               } // END - if
+
+               // Add the filter
                $this->filterChains[$filterGroup]->addFilter($filterInstance);
        }
 
@@ -101,8 +112,16 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
         * @param       $requestInstance        An instance of a request class
         * @param       $responseInstance       An instance of a response class
         * @return      void
+        * @throws      InvalidFilterChainException     If the filter chain is invalid
         */
        protected function executeFilters ($filterGroup, Requestable $requestInstance, Responseable $responseInstance) {
+               // Test if the filter is there
+               if (!isset($this->filterChains[$filterGroup])) {
+                       // Throw an exception here
+                       throw new InvalidFilterChainException(array($this, $filterGroup), self::EXCEPTION_FILTER_CHAIN_INVALID);
+               } // END - if
+
+               // Run all filters
                $this->filterChains[$filterGroup]->processFilters($requestInstance, $responseInstance);
        }