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: * Validates string length to be greater than the given length.
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 StringLengthGreaterThan extends \Jyxo\Input\Validator\AbstractValidator
27: {
28: /**
29: * Minimal string length.
30: *
31: * @var integer
32: */
33: protected $min;
34:
35: /**
36: * Constructor.
37: *
38: * @param integer $min Minimal string length (value length must be greater)
39: */
40: public function __construct($min)
41: {
42: $this->setMin($min);
43: }
44:
45: /**
46: * Sets the minimal string length.
47: *
48: * @param integer $min Minimal string length
49: * @return \Jyxo\Input\Validator\StringLengthGreaterThan
50: * @throws \InvalidArgumentException If the minimal length is negative
51: */
52: public function setMin($min)
53: {
54: $min = (int) $min;
55:
56: if ($min < 0) {
57: throw new \InvalidArgumentException('Length of string must be greater than zero.');
58: }
59:
60: $this->min = $min;
61:
62: return $this;
63: }
64:
65: /**
66: * Returns the minimal string length.
67: *
68: * @return integer
69: */
70: public function getMin()
71: {
72: return $this->min;
73: }
74:
75: /**
76: * Validates a value.
77: *
78: * @param mixed $value Input value
79: * @return boolean
80: */
81: public function isValid($value)
82: {
83: return mb_strlen((string) $value, 'utf-8') > $this->getMin();
84: }
85:
86: }
87: