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: namespace Jyxo\Input\Validator;
15:
16: /**
17: * Validator for numbers; checks if its value is less than...
18: *
19: * @category Jyxo
20: * @package Jyxo\Input
21: * @subpackage Validator
22: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
23: * @license https://github.com/jyxo/php/blob/master/license.txt
24: * @author Jan Pěček
25: */
26: class LessThan extends \Jyxo\Input\Validator\AbstractValidator
27: {
28: /**
29: * Desired maximum value
30: *
31: * @var integer
32: */
33: protected $max = 0;
34:
35: /**
36: * Constructor.
37: *
38: * Sets maximum value.
39: *
40: * @param integer $max Maximum value (value must be less)
41: */
42: public function __construct($max)
43: {
44: $this->setMax($max);
45: }
46:
47: /**
48: * Sets the maximum value.
49: *
50: * @param integer $max New maximum value
51: * @return \Jyxo\Input\Validator\StringLengthLessThan
52: */
53: public function setMax($max)
54: {
55: $this->max = (int) $max;
56:
57: return $this;
58: }
59:
60: /**
61: * Returns the maximum value.
62: *
63: * @return integer
64: */
65: public function getMax()
66: {
67: return $this->max;
68: }
69:
70: /**
71: * Validates a value.
72: *
73: * @param mixed $value Input value
74: * @return boolean
75: */
76: public function isValid($value)
77: {
78: return (int) $value < $this->getMax();
79: }
80: }
81: