Debug lines commented out
[core.git] / inc / classes / main / filter / class_FilterChain.php
1 <?php
2 /**
3  * A filter chain for pre and post filters
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007 - 2009 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 FilterChain extends BaseFrameworkSystem {
25         /**
26          * All filters together
27          */
28         private $filters = array();
29
30         /**
31          * Protected constructor
32          *
33          * @return      void
34          */
35         protected function __construct () {
36                 // Call parent constructor
37                 parent::__construct(__CLASS__);
38
39                 // Clean up a little
40                 $this->removeNumberFormaters();
41                 $this->removeSystemArray();
42         }
43
44         /**
45          * Creates an instance of this class
46          *
47          * @return      $chainInstance  An instance of this class
48          */
49         public final static function createFilterChain () {
50                 // Get a new instance
51                 $chainInstance = new FilterChain();
52
53                 // Return the prepared instance
54                 return $chainInstance;
55         }
56
57         /**
58          * Add a new filter
59          *
60          * @param       $filerInstance  An instance of a filter class
61          * @return      void
62          */
63         public final function addFilter (Filterable $filterInstance) {
64                 $this->filters[] = $filterInstance;
65         }
66
67         /**
68          * Process all added filters
69          *
70          * @param       $requestInstance        An instance of a request class
71          * @param       $responseInstance       An instance of a response class
72          * @return      void
73          */
74         public function processFilters (Requestable $requestInstance, Responseable $responseInstance) {
75                 // Run all filters
76                 //* DEBUG */ echo "COUNT=".count($this->filters)."<br />\n";
77                 foreach ($this->filters as $filterInstance) {
78                         // Try to execute this filter
79                         try {
80                                 //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.<br />\n";
81                                 $filterInstance->execute($requestInstance, $responseInstance);
82                                 //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.<br />\n";
83                         } catch (FilterChainException $e) {
84                                 // This exception can be thrown to just skip any further processing
85                                 break;
86                         }
87                 } // END - foreach
88         }
89 }
90
91 // [EOF]
92 ?>