1a0729e28632e42a79ad7e98a4c27ec5e73e6d58
[core.git] / inc / main / classes / filter / checkboxes / class_RulesAcceptedFilter.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Filter\RulesCheckbox;
4
5 /**
6  * A filter for checking if the user has accepted the rules. This is mainly
7  * used and done in registration process and should not be removed from your
8  * application.
9  *
10  * @author              Roland Haeder <webmaster@shipsimu.org>
11  * @version             0.0.0
12  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
13  * @license             GNU GPL 3.0 or any newer version
14  * @link                http://www.shipsimu.org
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29 class RulesAcceptedFilter extends BaseFilter implements Filterable {
30         /**
31          * Protected constructor
32          *
33          * @return      void
34          */
35         protected function __construct () {
36                 // Call parent constructor
37                 parent::__construct(__CLASS__);
38         }
39
40         /**
41          * Creates an instance of this filter class
42          *
43          * @return      $filterInstance                 An instance of this filter class
44          */
45         public static final function createRulesAcceptedFilter () {
46                 // Get a new instance
47                 $filterInstance = new RulesAcceptedFilter();
48
49                 // Return the instance
50                 return $filterInstance;
51         }
52
53         /**
54          * Executes the filter with given request and response objects
55          *
56          * @param       $requestInstance        An instance of a class with an Requestable interface
57          * @param       $responseInstance       An instance of a class with an Responseable interface
58          * @return      void
59          * @throws      FilterChainException    If this filter fails to operate
60          */
61         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
62                 // Get the "rules" value from request
63                 $rules = $requestInstance->getRequestElement('rules');
64
65                 // Was the "rules" value found in form? And is it set?
66                 if (is_null($rules)) {
67                         // Not found in form so stop processing here
68                         $requestInstance->requestIsValid(FALSE);
69
70                         // Add a message to the response
71                         $responseInstance->addFatalMessage('rules_unchecked');
72
73                         // Skip further processing
74                         throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
75                 } // END - if
76         }
77
78 }