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