Introduced executeGenericPrePostCommand() which will execute a command with
[core.git] / inc / classes / main / controller / class_BaseController.php
index e604b54c977ce53bfd468a77dd73ab5bed6da882..3b0d24c18cd3f878fdd0880b07bc4448fcea3209 100644 (file)
@@ -54,6 +54,36 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
                Registry::getRegistry()->addInstance('controller', $this);
        }
 
+       /**
+        * Executes a command with pre and post filters
+        *
+        * @param       $requestInstance        A Requestable class
+        * @param       $responseInstance       A Responseable class
+        * @return      void
+        */
+       public function executeGenericPrePostCommand (Requestable $requestInstance, Responseable $responseInstance) {
+               // Get the command instance from the resolver by sending a request instance to the resolver
+               $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+               // Add more filters by the command
+               $commandInstance->addExtraFilters($this, $requestInstance);
+
+               // Run the pre filters
+               $this->executePreFilters($requestInstance, $responseInstance);
+
+               // This request was valid! :-D
+               $requestInstance->requestIsValid();
+
+               // Execute the command
+               $commandInstance->execute($requestInstance, $responseInstance);
+
+               // Run the post filters
+               $this->executePostFilters($requestInstance, $responseInstance);
+
+               // Flush the response out
+               $responseInstance->flushBuffer();
+       }
+
        /**
         * Private method to initialize a given filter chain
         *
@@ -110,6 +140,16 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
                $this->addFilter(self::FILTER_CHAIN_POST_COMMAND, $filterInstance);
        }
 
+       /**
+        * Add a shutdown filter
+        *
+        * @param       $filterInstance         A Filterable class
+        * @return      void
+        */
+       public function addShutdownFilter (Filterable $filterInstance) {
+               $this->addFilter('shutdown', $filterInstance);
+       }
+
        /**
         * Executes given filter chain chain
         *
@@ -154,16 +194,6 @@ class BaseController extends BaseFrameworkSystem implements Registerable {
                $this->executeFilters(self::FILTER_CHAIN_POST_COMMAND, $requestInstance, $responseInstance);
        }
 
-       /**
-        * Add a shutdown filter
-        *
-        * @param       $filterInstance         A Filterable class
-        * @return      void
-        */
-       public function addShutdownFilter (Filterable $filterInstance) {
-               $this->addFilter('shutdown', $filterInstance);
-       }
-
        /**
         * Executes all shutdown filters
         *