- Timestamp:
- 2013/08/28 13:55:43 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13_0/data/module/Calendar/Validator.php
r23126 r23143 1 1 <?php 2 2 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 3 3 // 4 // +----------------------------------------------------------------------+ 5 // | PHP Version 4 | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 1997-2002 The PHP Group | 8 // +----------------------------------------------------------------------+ 9 // | This source file is subject to version 2.02 of the PHP license, | 10 // | that is bundled with this package in the file LICENSE, and is | 11 // | available at through the world-wide-web at | 12 // | http://www.php.net/license/3_0.txt. | 13 // | If you did not receive a copy of the PHP license and are unable to | 14 // | obtain it through the world-wide-web, please send a note to | 15 // | license@php.net so we can mail you a copy immediately. | 16 // +----------------------------------------------------------------------+ 17 // | Authors: Harry Fuecks <hfuecks@phppatterns.com> | 18 // +----------------------------------------------------------------------+ 19 // 20 // $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ 21 // 4 22 /** 5 * Contains the Calendar_Validator class 6 * 7 * PHP versions 4 and 5 8 * 9 * LICENSE: Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * @category Date and Time 31 * @package Calendar 32 * @author Harry Fuecks <hfuecks@phppatterns.com> 33 * @copyright 2003-2007 Harry Fuecks 34 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 35 * @version CVS: $Id: Validator.php 247251 2007-11-28 19:42:33Z quipo $ 36 * @link http://pear.php.net/package/Calendar 23 * @package Calendar 24 * @version $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ 37 25 */ 38 26 … … 50 38 * Used to validate any given Calendar date object. Instances of this class 51 39 * can be obtained from any data object using the getValidator method 52 * 53 * @category Date and Time 54 * @package Calendar 55 * @author Harry Fuecks <hfuecks@phppatterns.com> 56 * @copyright 2003-2007 Harry Fuecks 57 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 58 * @link http://pear.php.net/package/Calendar 59 * @see Calendar::getValidator() 60 * @access public 40 * @see Calendar::getValidator() 41 * @package Calendar 42 * @access public 61 43 */ 62 44 class Calendar_Validator … … 85 67 /** 86 68 * Constructs Calendar_Validator 87 * 88 * @param object &$calendar subclass of Calendar 89 * 90 * @access public 91 */ 92 function Calendar_Validator(&$calendar) 69 * @param object subclass of Calendar 70 * @access public 71 */ 72 function Calendar_Validator(& $calendar) 93 73 { 94 74 $this->calendar = & $calendar; 95 $this->cE 75 $this->cE = & $calendar->getEngine(); 96 76 } 97 77 98 78 /** 99 79 * Calls all the other isValidXXX() methods in the validator 100 *101 80 * @return boolean 102 81 * @access public … … 106 85 $checks = array('isValidYear', 'isValidMonth', 'isValidDay', 107 86 'isValidHour', 'isValidMinute', 'isValidSecond'); 108 $valid 87 $valid = true; 109 88 foreach ($checks as $check) { 110 89 if (!$this->{$check}()) { … … 117 96 /** 118 97 * Check whether this is a valid year 119 *120 98 * @return boolean 121 99 * @access public … … 123 101 function isValidYear() 124 102 { 125 $y 103 $y = $this->calendar->thisYear(); 126 104 $min = $this->cE->getMinYears(); 127 105 if ($min > $y) { 128 106 $this->errors[] = new Calendar_Validation_Error( 129 107 'Year', $y, CALENDAR_VALUE_TOOSMALL.$min); 130 108 return false; … … 141 119 /** 142 120 * Check whether this is a valid month 143 *144 121 * @return boolean 145 122 * @access public … … 147 124 function isValidMonth() 148 125 { 149 $m 126 $m = $this->calendar->thisMonth(); 150 127 $min = 1; 151 128 if ($min > $m) { … … 165 142 /** 166 143 * Check whether this is a valid day 167 *168 144 * @return boolean 169 145 * @access public … … 171 147 function isValidDay() 172 148 { 173 $d 149 $d = $this->calendar->thisDay(); 174 150 $min = 1; 175 151 if ($min > $d) { … … 179 155 } 180 156 $max = $this->cE->getDaysInMonth( 181 $this->calendar->thisYear(), 182 $this->calendar->thisMonth() 183 ); 157 $this->calendar->thisYear(), $this->calendar->thisMonth()); 184 158 if ($d > $max) { 185 159 $this->errors[] = new Calendar_Validation_Error( … … 192 166 /** 193 167 * Check whether this is a valid hour 194 *195 168 * @return boolean 196 169 * @access public … … 198 171 function isValidHour() 199 172 { 200 $h 173 $h = $this->calendar->thisHour(); 201 174 $min = 0; 202 175 if ($min > $h) { … … 216 189 /** 217 190 * Check whether this is a valid minute 218 *219 191 * @return boolean 220 192 * @access public … … 222 194 function isValidMinute() 223 195 { 224 $i 196 $i = $this->calendar->thisMinute(); 225 197 $min = 0; 226 198 if ($min > $i) { … … 240 212 /** 241 213 * Check whether this is a valid second 242 *243 214 * @return boolean 244 215 * @access public … … 246 217 function isValidSecond() 247 218 { 248 $s 219 $s = $this->calendar->thisSecond(); 249 220 $min = 0; 250 221 if ($min > $s) { … … 264 235 /** 265 236 * Iterates over any validation errors 266 *267 237 * @return mixed either Calendar_Validation_Error or false 268 238 * @access public … … 270 240 function fetch() 271 241 { 272 $error = each ($this->errors);242 $error = each ($this->errors); 273 243 if ($error) { 274 244 return $error['value']; … … 282 252 /** 283 253 * For Validation Error messages 284 * 285 * @category Date and Time 286 * @package Calendar 287 * @author Harry Fuecks <hfuecks@phppatterns.com> 288 * @copyright 2003-2007 Harry Fuecks 289 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 290 * @link http://pear.php.net/package/Calendar 291 * @see Calendar::fetch() 292 * @access public 254 * @see Calendar::fetch() 255 * @package Calendar 256 * @access public 293 257 */ 294 258 class Calendar_Validation_Error … … 317 281 /** 318 282 * Constructs Calendar_Validation_Error 319 * 320 * @param string $unit Date unit (e.g. month,hour,second) 321 * @param int $value Value of unit which failed test 322 * @param string $message Validation error message 323 * 283 * @param string Date unit (e.g. month,hour,second) 284 * @param int Value of unit which failed test 285 * @param string Validation error message 324 286 * @access protected 325 287 */ 326 function Calendar_Validation_Error($unit, $value,$message)288 function Calendar_Validation_Error($unit,$value,$message) 327 289 { 328 290 $this->unit = $unit; … … 333 295 /** 334 296 * Returns the Date unit 335 *336 297 * @return string 337 298 * @access public … … 344 305 /** 345 306 * Returns the value of the unit 346 *347 307 * @return int 348 308 * @access public … … 355 315 /** 356 316 * Returns the validation error message 357 *358 317 * @return string 359 318 * @access public … … 366 325 /** 367 326 * Returns a string containing the unit, value and error message 368 *369 327 * @return string 370 328 * @access public
Note: See TracChangeset
for help on using the changeset viewer.