Intercepting filter basicly added, generic form processor implemented (unfinished...
[shipsimu.git] / inc / classes / main / controller / class_BaseController.php
index f7aea5c307922c9a30552ed64bc1ea21d72f7790..607e042af3541c0177bf87c042d6ee5c40ba3e23 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseController extends BaseFrameworkSystem {
+       /**
+        * Instance of a CommandResolver class
+        */
+       private $resolverInstance = null;
+
+       /**
+        * Pre filter chain instance
+        */
+       private $preFilterChain = null;
+
+       /**
+        * Post filter chain instance
+        */
+       private $postFilterChain = null;
+
        /**
         * Protected constructor
         *
@@ -33,6 +48,75 @@ class BaseController extends BaseFrameworkSystem {
 
                // Clean up a little
                $this->removeNumberFormaters();
+               $this->removeSystemArray();
+
+               // Initialize both filter chains
+               $this->preFilterChain  = FilterChain::createFilterChain();
+               $this->postFilterChain = FilterChain::createFilterChain();
+       }
+
+       /**
+        * Getter for a command resolver instance
+        *
+        * @
+        * @return      $resolverInstance       An instance of a command resolver class
+        */
+       public final function getResolverInstance () {
+               return $this->resolverInstance;
+       }
+
+       /**
+        * Setter for a command resolver instance
+        *
+        * @param       $resolverInstance       An instance of a command resolver class
+        * @return      void
+        */
+       public final function setResolverInstance (CommandResolver $resolverInstance) {
+               $this->resolverInstance = $resolverInstance;
+       }
+
+       /**
+        * Adds a filter to the pre filter chain
+        *
+        * @param       $filterInstance         An instance of a filter
+        * @return      void
+        */
+       public function addPreFilter (Filterable $filterInstance) {
+               // Add the pre filter
+               $this->preFilterChain->addFilter($filterInstance);
+       }
+
+       /**
+        * Adds a filter to the post filter chain
+        *
+        * @param       $filterInstance         An instance of a filter
+        * @return      void
+        */
+       public function addPostFilter (Filterable $filterInstance) {
+               // Add the post filter
+               $this->postFilterChain->addFilter($filterInstance);
+       }
+
+       /**
+        * Executes all pre filters
+        *
+        * @param       $requestInstance        An instance of a request class
+        * @param       $responseInstance       An instance of a response class
+        * @return      void
+        */
+       protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
+               $this->preFilterChain->processFilters($requestInstance, $responseInstance);
+       }
+
+       /**
+        * Executes all post filters
+        *
+        * @param       $requestInstance        An instance of a request class
+        * @param       $responseInstance       An instance of a response class
+        * @return      void
+        */
+       protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
+               $this->postFilterChain->processFilters($requestInstance, $responseInstance);
        }
 }