Some updates:
[core.git] / framework / main / classes / filter / verifier / class_BirthdayVerifierFilter.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Filter\Verifier\User;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filter\BaseFilter;
7 use Org\Mxchange\CoreFramework\Filter\Filterable;
8 use Org\Mxchange\CoreFramework\Request\Requestable;
9 use Org\Mxchange\CoreFramework\Response\Responseable;
10
11 /**
12  * A verifier filter for birthday data
13  *
14  * @author              Roland Haeder <webmaster@shipsimu.org>
15  * @version             0.0.0
16 <<<<<<< HEAD:framework/main/classes/filter/verifier/class_BirthdayVerifierFilter.php
17  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
18 =======
19  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
20 >>>>>>> Some updates::inc/main/classes/filter/verifier/class_BirthdayVerifierFilter.php
21  * @license             GNU GPL 3.0 or any newer version
22  * @link                http://www.shipsimu.org
23  *
24  * This program is free software: you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation, either version 3 of the License, or
27  * (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  *
34  * You should have received a copy of the GNU General Public License
35  * along with this program. If not, see <http://www.gnu.org/licenses/>.
36  */
37 class BirthdayVerifierFilter extends BaseFilter implements Filterable {
38         /**
39          * Protected constructor
40          *
41          * @return      void
42          */
43         protected function __construct () {
44                 // Call parent constructor
45                 parent::__construct(__CLASS__);
46         }
47
48         /**
49          * Creates an instance of this filter class
50          *
51          * @return      $filterInstance                 An instance of this filter class
52          */
53         public static final function createBirthdayVerifierFilter () {
54                 // Get a new instance
55                 $filterInstance = new BirthdayVerifierFilter();
56
57                 // Return the instance
58                 return $filterInstance;
59         }
60
61         /**
62          * Executes the filter with given request and response objects
63          *
64          * @param       $requestInstance        An instance of a class with an Requestable interface
65          * @param       $responseInstance       An instance of a class with an Responseable interface
66          * @return      void
67          */
68         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
69                 // Day of birth set?
70                 if (!$requestInstance->isRequestElementSet('birth_day')) {
71                         // Day of birth isn't set
72                         $requestInstance->requestIsValid(false);
73
74                         // Add a message to the response
75                         $responseInstance->addFatalMessage('day_of_birth_unset');
76                 } // END - if
77
78                 // Month of birth set?
79                 if (!$requestInstance->isRequestElementSet('birth_month')) {
80                         // Month of birth isn't set
81                         $requestInstance->requestIsValid(false);
82
83                         // Add a message to the response
84                         $responseInstance->addFatalMessage('month_of_birth_unset');
85                 } // END - if
86
87                 // Year of birth set?
88                 if (!$requestInstance->isRequestElementSet('birth_year')) {
89                         // Year of birth isn't set
90                         $requestInstance->requestIsValid(false);
91
92                         // Add a message to the response
93                         $responseInstance->addFatalMessage('year_of_birth_unset');
94                 } // END - if
95
96                 // Is the request still valid?
97                 if (!$requestInstance->isRequestValid()) {
98                         // Abort here
99                         throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
100                 } // END - if
101
102                 // Now comes the final check
103                 $birthCheck = mktime(
104                         0,
105                         0,
106                         0,
107                         (int) $requestInstance->getRequestElement('birth_day'),
108                         (int) $requestInstance->getRequestElement('birth_month'),
109                         (int) $requestInstance->getRequestElement('birth_year')
110                 );
111
112                 // Is there a number or such? (we don't care about the value itself here)
113                 if (empty($birthCheck)) {
114                         // Validation has failed
115                         $requestInstance->requestIsValid(false);
116
117                         // Add a message to the response
118                         $responseInstance->addFatalMessage('birthday_invalid');
119
120                         // Abort here
121                         throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
122                 } // END - if
123         }
124
125 }