]> git.mxchange.org Git - shipsimu.git/blob - inc/classes/main/controller/class_BaseController.php
607e042af3541c0177bf87c042d6ee5c40ba3e23
[shipsimu.git] / inc / classes / main / controller / class_BaseController.php
1 <?php
2 /**
3  * A generic controller class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BaseController extends BaseFrameworkSystem {
25         /**
26          * Instance of a CommandResolver class
27          */
28         private $resolverInstance = null;
29
30         /**
31          * Pre filter chain instance
32          */
33         private $preFilterChain = null;
34
35         /**
36          * Post filter chain instance
37          */
38         private $postFilterChain = null;
39
40         /**
41          * Protected constructor
42          *
43          * @return      void
44          */
45         protected function __construct ($class) {
46                 // Call parent constructor
47                 parent::__construct($class);
48
49                 // Clean up a little
50                 $this->removeNumberFormaters();
51                 $this->removeSystemArray();
52
53                 // Initialize both filter chains
54                 $this->preFilterChain  = FilterChain::createFilterChain();
55                 $this->postFilterChain = FilterChain::createFilterChain();
56         }
57
58         /**
59          * Getter for a command resolver instance
60          *
61          * @
62          * @return      $resolverInstance       An instance of a command resolver class
63          */
64         public final function getResolverInstance () {
65                 return $this->resolverInstance;
66         }
67
68         /**
69          * Setter for a command resolver instance
70          *
71          * @param       $resolverInstance       An instance of a command resolver class
72          * @return      void
73          */
74         public final function setResolverInstance (CommandResolver $resolverInstance) {
75                 $this->resolverInstance = $resolverInstance;
76         }
77
78         /**
79          * Adds a filter to the pre filter chain
80          *
81          * @param       $filterInstance         An instance of a filter
82          * @return      void
83          */
84         public function addPreFilter (Filterable $filterInstance) {
85                 // Add the pre filter
86                 $this->preFilterChain->addFilter($filterInstance);
87         }
88
89         /**
90          * Adds a filter to the post filter chain
91          *
92          * @param       $filterInstance         An instance of a filter
93          * @return      void
94          */
95         public function addPostFilter (Filterable $filterInstance) {
96                 // Add the post filter
97                 $this->postFilterChain->addFilter($filterInstance);
98         }
99
100         /**
101          * Executes all pre filters
102          *
103          * @param       $requestInstance        An instance of a request class
104          * @param       $responseInstance       An instance of a response class
105          * @return      void
106          */
107         protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) {
108                 $this->preFilterChain->processFilters($requestInstance, $responseInstance);
109         }
110
111         /**
112          * Executes all post filters
113          *
114          * @param       $requestInstance        An instance of a request class
115          * @param       $responseInstance       An instance of a response class
116          * @return      void
117          */
118         protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) {
119                 $this->postFilterChain->processFilters($requestInstance, $responseInstance);
120         }
121 }
122
123 // [EOF]
124 ?>