1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file license.txt.
10: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: /**
15: * Validator for numbers; checks if its value is less than...
16: *
17: * @category Jyxo
18: * @package Jyxo_Input
19: * @subpackage Validator
20: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
21: * @license https://github.com/jyxo/php/blob/master/license.txt
22: * @author Jan Pěček
23: */
24: class Jyxo_Input_Validator_LessThan extends Jyxo_Input_Validator_AbstractValidator
25: {
26: /**
27: * Desired maximum value
28: *
29: * @var integer
30: */
31: protected $max = 0;
32:
33: /**
34: * Constructor.
35: *
36: * Sets maximum value.
37: *
38: * @param integer $max Maximum value (value must be less)
39: */
40: public function __construct($max)
41: {
42: $this->setMax($max);
43: }
44:
45: /**
46: * Sets the maximum value.
47: *
48: * @param integer $max New maximum value
49: * @return Jyxo_Input_Validator_StringLengthLessThan
50: */
51: public function setMax($max)
52: {
53: $this->max = (int) $max;
54:
55: return $this;
56: }
57:
58: /**
59: * Returns the maximum value.
60: *
61: * @return integer
62: */
63: public function getMax()
64: {
65: return $this->max;
66: }
67:
68: /**
69: * Validates a value.
70: *
71: * @param mixed $value Input value
72: * @return boolean
73: */
74: public function isValid($value)
75: {
76: return (int) $value < $this->getMax();
77: }
78: }
79: