]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/controller/class_BaseController.php
Type-hints fixed, header docs fixed, exceptions deprecated
[shipsimu.git] / inc / classes / main / controller / class_BaseController.php
index 607e042af3541c0177bf87c042d6ee5c40ba3e23..1686f42f7c23238c475019c33017ad2df808915b 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /**
- * A generic controller class
+ * A generic controller class. You should extend this base class if you want to
+ * write your own controller. You get the advantage that you can use the pre and
+ * post filters.
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
  * 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 {
-       /**
-        * Instance of a CommandResolver class
-        */
-       private $resolverInstance = null;
-
+class BaseController extends BaseFrameworkSystem implements Registerable {
        /**
         * Pre filter chain instance
         */
@@ -40,39 +37,23 @@ class BaseController extends BaseFrameworkSystem {
        /**
         * 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->preFilterChain  = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
+               $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class');
 
-       /**
-        * 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;
+               // Add this controller to the registry
+               Registry::getRegistry()->addInstance('controller', $this);
        }
 
        /**
@@ -105,6 +86,7 @@ class BaseController extends BaseFrameworkSystem {
         * @return      void
         */
        protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
+               // Execute all pre filters
                $this->preFilterChain->processFilters($requestInstance, $responseInstance);
        }
 
@@ -116,6 +98,7 @@ class BaseController extends BaseFrameworkSystem {
         * @return      void
         */
        protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
+               // Execute all post filters
                $this->postFilterChain->processFilters($requestInstance, $responseInstance);
        }
 }