- Timestamp:
- 2013/08/26 12:42:34 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/Calendar/Validator.php
r20119 r23125 1 1 <?php 2 2 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 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 // 3 22 4 /** 23 * @package Calendar 24 * @version $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ 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 25 37 */ 26 38 … … 38 50 * Used to validate any given Calendar date object. Instances of this class 39 51 * can be obtained from any data object using the getValidator method 40 * @see Calendar::getValidator() 41 * @package Calendar 42 * @access public 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 43 61 */ 44 62 class Calendar_Validator … … 67 85 /** 68 86 * Constructs Calendar_Validator 69 * @param object subclass of Calendar 70 * @access public 71 */ 72 function Calendar_Validator(& $calendar) 87 * 88 * @param object &$calendar subclass of Calendar 89 * 90 * @access public 91 */ 92 function Calendar_Validator(&$calendar) 73 93 { 74 94 $this->calendar = & $calendar; 75 $this->cE = & $calendar->getEngine();95 $this->cE = & $calendar->getEngine(); 76 96 } 77 97 78 98 /** 79 99 * Calls all the other isValidXXX() methods in the validator 100 * 80 101 * @return boolean 81 102 * @access public … … 85 106 $checks = array('isValidYear', 'isValidMonth', 'isValidDay', 86 107 'isValidHour', 'isValidMinute', 'isValidSecond'); 87 $valid = true;108 $valid = true; 88 109 foreach ($checks as $check) { 89 110 if (!$this->{$check}()) { … … 96 117 /** 97 118 * Check whether this is a valid year 119 * 98 120 * @return boolean 99 121 * @access public … … 101 123 function isValidYear() 102 124 { 103 $y = $this->calendar->thisYear();125 $y = $this->calendar->thisYear(); 104 126 $min = $this->cE->getMinYears(); 105 127 if ($min > $y) { 106 $this->errors[] = new Calendar_Validation_Error(128 $this->errors[] = new Calendar_Validation_Error( 107 129 'Year', $y, CALENDAR_VALUE_TOOSMALL.$min); 108 130 return false; … … 119 141 /** 120 142 * Check whether this is a valid month 143 * 121 144 * @return boolean 122 145 * @access public … … 124 147 function isValidMonth() 125 148 { 126 $m = $this->calendar->thisMonth();149 $m = $this->calendar->thisMonth(); 127 150 $min = 1; 128 151 if ($min > $m) { … … 142 165 /** 143 166 * Check whether this is a valid day 167 * 144 168 * @return boolean 145 169 * @access public … … 147 171 function isValidDay() 148 172 { 149 $d = $this->calendar->thisDay();173 $d = $this->calendar->thisDay(); 150 174 $min = 1; 151 175 if ($min > $d) { … … 155 179 } 156 180 $max = $this->cE->getDaysInMonth( 157 $this->calendar->thisYear(), $this->calendar->thisMonth()); 181 $this->calendar->thisYear(), 182 $this->calendar->thisMonth() 183 ); 158 184 if ($d > $max) { 159 185 $this->errors[] = new Calendar_Validation_Error( … … 166 192 /** 167 193 * Check whether this is a valid hour 194 * 168 195 * @return boolean 169 196 * @access public … … 171 198 function isValidHour() 172 199 { 173 $h = $this->calendar->thisHour();200 $h = $this->calendar->thisHour(); 174 201 $min = 0; 175 202 if ($min > $h) { … … 189 216 /** 190 217 * Check whether this is a valid minute 218 * 191 219 * @return boolean 192 220 * @access public … … 194 222 function isValidMinute() 195 223 { 196 $i = $this->calendar->thisMinute();224 $i = $this->calendar->thisMinute(); 197 225 $min = 0; 198 226 if ($min > $i) { … … 212 240 /** 213 241 * Check whether this is a valid second 242 * 214 243 * @return boolean 215 244 * @access public … … 217 246 function isValidSecond() 218 247 { 219 $s = $this->calendar->thisSecond();248 $s = $this->calendar->thisSecond(); 220 249 $min = 0; 221 250 if ($min > $s) { … … 235 264 /** 236 265 * Iterates over any validation errors 266 * 237 267 * @return mixed either Calendar_Validation_Error or false 238 268 * @access public … … 240 270 function fetch() 241 271 { 242 $error = each 272 $error = each($this->errors); 243 273 if ($error) { 244 274 return $error['value']; … … 252 282 /** 253 283 * For Validation Error messages 254 * @see Calendar::fetch() 255 * @package Calendar 256 * @access public 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 257 293 */ 258 294 class Calendar_Validation_Error … … 281 317 /** 282 318 * Constructs Calendar_Validation_Error 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 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 * 286 324 * @access protected 287 325 */ 288 function Calendar_Validation_Error($unit, $value,$message)326 function Calendar_Validation_Error($unit, $value, $message) 289 327 { 290 328 $this->unit = $unit; … … 295 333 /** 296 334 * Returns the Date unit 335 * 297 336 * @return string 298 337 * @access public … … 305 344 /** 306 345 * Returns the value of the unit 346 * 307 347 * @return int 308 348 * @access public … … 315 355 /** 316 356 * Returns the validation error message 357 * 317 358 * @return string 318 359 * @access public … … 325 366 /** 326 367 * Returns a string containing the unit, value and error message 368 * 327 369 * @return string 328 370 * @access public
Note: See TracChangeset
for help on using the changeset viewer.