-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathBetween.php
More file actions
67 lines (60 loc) · 1.63 KB
/
Copy pathBetween.php
File metadata and controls
67 lines (60 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Between
*
* @category StrokerForm
* @package StrokerForm\Renderer
* @copyright 2012 Bram Gerritsen
* @version SVN: $Id$
*/
namespace StrokerForm\Renderer\JqueryValidate\Rule;
use Zend\Form\ElementInterface;
use Zend\Validator\ValidatorInterface;
use Zend\Validator\Between as BetweenValidator;
class Between extends AbstractRule
{
/**
* {@inheritDoc}
*/
public function getRules(ValidatorInterface $validator, ElementInterface $element = null)
{
return ['range' => [$this->getMin($validator), $this->getMax($validator)]];
}
/**
* {@inheritDoc}
*/
public function getMessages(ValidatorInterface $validator)
{
return [
'range' => sprintf($validator->getMessageTemplates()[\Zend\Validator\Between::NOT_BETWEEN], $this->getMin($validator), $this->getMax($validator))
];
}
/**
* @param ValidatorInterface $validator
*
* @return mixed
*/
protected function getMin(ValidatorInterface $validator)
{
return $validator->getInclusive() ? $validator->getMin() : $validator->getMin() + 1;
}
/**
* @param ValidatorInterface $validator
*
* @return mixed
*/
protected function getMax(ValidatorInterface $validator)
{
return $validator->getInclusive() ? $validator->getMax() : $validator->getMax() - 1;
}
/**
* Whether this rule supports certain validators
*
* @param ValidatorInterface $validator
* @return mixed
*/
public function canHandle(ValidatorInterface $validator)
{
return $validator instanceof BetweenValidator;
}
}