3 namespace Org\Mxchange\CoreFramework\Filter\Verifier\User;
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;
12 * A verifier filter for birthday data
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 <<<<<<< HEAD:framework/main/classes/filter/verifier/class_BirthdayVerifierFilter.php
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
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
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.
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.
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/>.
37 class BirthdayVerifierFilter extends BaseFilter implements Filterable {
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this filter class
51 * @return $filterInstance An instance of this filter class
53 public static final function createBirthdayVerifierFilter () {
55 $filterInstance = new BirthdayVerifierFilter();
57 // Return the instance
58 return $filterInstance;
62 * Executes the filter with given request and response objects
64 * @param $requestInstance An instance of a class with an Requestable interface
65 * @param $responseInstance An instance of a class with an Responseable interface
68 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
70 if (!$requestInstance->isRequestElementSet('birth_day')) {
71 // Day of birth isn't set
72 $requestInstance->requestIsValid(false);
74 // Add a message to the response
75 $responseInstance->addFatalMessage('day_of_birth_unset');
78 // Month of birth set?
79 if (!$requestInstance->isRequestElementSet('birth_month')) {
80 // Month of birth isn't set
81 $requestInstance->requestIsValid(false);
83 // Add a message to the response
84 $responseInstance->addFatalMessage('month_of_birth_unset');
88 if (!$requestInstance->isRequestElementSet('birth_year')) {
89 // Year of birth isn't set
90 $requestInstance->requestIsValid(false);
92 // Add a message to the response
93 $responseInstance->addFatalMessage('year_of_birth_unset');
96 // Is the request still valid?
97 if (!$requestInstance->isRequestValid()) {
99 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
102 // Now comes the final check
103 $birthCheck = mktime(
107 (int) $requestInstance->getRequestElement('birth_day'),
108 (int) $requestInstance->getRequestElement('birth_month'),
109 (int) $requestInstance->getRequestElement('birth_year')
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);
117 // Add a message to the response
118 $responseInstance->addFatalMessage('birthday_invalid');
121 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);