Payment introduced, minor rewrites
[shipsimu.git] / inc / classes / main / controller / class_BaseController.php
index 1c4d442f5aca51619ce255e8394867e3d39e1185..69fa4d154669961f2f8b39156ccfea78c1bfa20b 100644 (file)
  */
 class BaseController extends BaseFrameworkSystem implements Registerable {
        /**
-        * Pre filter chain instance
+        * Generic filter chains
         */
-       private $preFilterChain = null;
-
-       /**
-        * Post filter chain instance
-        */
-       private $postFilterChain = null;
+       private $filterChains = array();
 
        /**
         * Protected constructor
@@ -49,13 +44,23 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
                $this->removeSystemArray();
 
                // Initialize both filter chains
-               $this->preFilterChain  = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
-               $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
+               $this->initFilterChain('pre');
+               $this->initFilterChain('post');
 
                // Add this controller to the registry
                Registry::getRegistry()->addInstance('controller', $this);
        }
 
+       /**
+        * Private method to initialize a given filter chain
+        *
+        * @param       $filterChain    Name of the filter chain
+        * @return      void
+        */
+       private function initFilterChain ($filterChain) {
+               $this->filterChains[$filterChain] = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
+       }
+
        /**
         * Adds a filter to the pre filter chain
         *
@@ -64,7 +69,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
         */
        public function addPreFilter (Filterable $filterInstance) {
                // Add the pre filter
-               $this->preFilterChain->addFilter($filterInstance);
+               $this->filterChains['pre']->addFilter($filterInstance);
        }
 
        /**
@@ -75,7 +80,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
         */
        public function addPostFilter (Filterable $filterInstance) {
                // Add the post filter
-               $this->postFilterChain->addFilter($filterInstance);
+               $this->filterChains['post']->addFilter($filterInstance);
        }
 
        /**
@@ -87,7 +92,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
         */
        protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
                // Execute all pre filters
-               $this->preFilterChain->processFilters($requestInstance, $responseInstance);
+               $this->filterChains['pre']->processFilters($requestInstance, $responseInstance);
        }
 
        /**
@@ -99,7 +104,7 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
         */
        protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
                // Execute all post filters
-               $this->postFilterChain->processFilters($requestInstance, $responseInstance);
+               $this->filterChains['post']->processFilters($requestInstance, $responseInstance);
        }
 }