Code base synced
[mailer.git] / inc / classes / main / controller / class_BaseController.php
index a2bf81158444abaea1aef399342006ba2683eee4..69fa4d154669961f2f8b39156ccfea78c1bfa20b 100644 (file)
@@ -6,7 +6,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @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
  *
  * 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 BaseController extends BaseFrameworkSystem {
+class BaseController extends BaseFrameworkSystem implements Registerable {
        /**
-        * Instance of a CommandResolver class
+        * Generic filter chains
         */
-       private $resolverInstance = null;
-
-       /**
-        * Pre filter chain instance
-        */
-       private $preFilterChain = null;
-
-       /**
-        * Post filter chain instance
-        */
-       private $postFilterChain = null;
+       private $filterChains = array();
 
        /**
         * Protected constructor
         *
+        * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($class) {
+       protected function __construct ($className) {
                // Call parent constructor
-               parent::__construct($class);
+               parent::__construct($className);
 
                // Clean up a little
                $this->removeNumberFormaters();
                $this->removeSystemArray();
 
                // Initialize both filter chains
-               $this->preFilterChain  = FilterChain::createFilterChain();
-               $this->postFilterChain = FilterChain::createFilterChain();
-       }
+               $this->initFilterChain('pre');
+               $this->initFilterChain('post');
 
-       /**
-        * Getter for a command resolver instance
-        *
-        * @return      $resolverInstance       An instance of a command resolver class
-        */
-       public final function getResolverInstance () {
-               return $this->resolverInstance;
+               // Add this controller to the registry
+               Registry::getRegistry()->addInstance('controller', $this);
        }
 
        /**
-        * Setter for a command resolver instance
+        * Private method to initialize a given filter chain
         *
-        * @param       $resolverInstance       An instance of a command resolver class
+        * @param       $filterChain    Name of the filter chain
         * @return      void
         */
-       public final function setResolverInstance (CommandResolver $resolverInstance) {
-               $this->resolverInstance = $resolverInstance;
+       private function initFilterChain ($filterChain) {
+               $this->filterChains[$filterChain] = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
        }
 
        /**
@@ -84,7 +69,7 @@ class BaseController extends BaseFrameworkSystem {
         */
        public function addPreFilter (Filterable $filterInstance) {
                // Add the pre filter
-               $this->preFilterChain->addFilter($filterInstance);
+               $this->filterChains['pre']->addFilter($filterInstance);
        }
 
        /**
@@ -95,7 +80,7 @@ class BaseController extends BaseFrameworkSystem {
         */
        public function addPostFilter (Filterable $filterInstance) {
                // Add the post filter
-               $this->postFilterChain->addFilter($filterInstance);
+               $this->filterChains['post']->addFilter($filterInstance);
        }
 
        /**
@@ -107,7 +92,7 @@ class BaseController extends BaseFrameworkSystem {
         */
        protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
                // Execute all pre filters
-               $this->preFilterChain->processFilters($requestInstance, $responseInstance);
+               $this->filterChains['pre']->processFilters($requestInstance, $responseInstance);
        }
 
        /**
@@ -119,7 +104,7 @@ class BaseController extends BaseFrameworkSystem {
         */
        protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
                // Execute all post filters
-               $this->postFilterChain->processFilters($requestInstance, $responseInstance);
+               $this->filterChains['post']->processFilters($requestInstance, $responseInstance);
        }
 }