TYPO3 CMS  TYPO3_6-2
NumberRangeValidator.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $supportedOptions = array(
28  'minimum' => array(0, 'The minimum value to accept', 'integer'),
29  'maximum' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer'),
30  'startRange' => array(0, 'The minimum value to accept', 'integer'),
31  'endRange' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer')
32  );
33 
41  public function isValid($value) {
42  if (!is_numeric($value)) {
43  $this->addError(
44  $this->translateErrorMessage(
45  'validator.numberrange.notvalid',
46  'extbase'
47  ), 1221563685);
48  return;
49  }
50 
55  if (isset($this->options['minimum']) && isset($this->options['startRange'])) {
56  if ($this->options['minimum'] !== 0) {
57  $minimum = $this->options['minimum'];
58  } elseif ($this->options['startRange'] !== 0) {
59  $minimum = $this->options['startRange'];
60  } else {
61  $minimum = 0;
62  }
63  } elseif (isset($this->options['minimum'])) {
64  $minimum = $this->options['minimum'];
65  } elseif (isset($this->options['startRange'])) {
66  $minimum = $this->options['startRange'];
67  } else {
68  $minimum = 0;
69  }
70 
71  if (isset($this->options['maximum']) && isset($this->options['endRange'])) {
72  if ($this->options['maximum'] !== PHP_INT_MAX) {
73  $maximum = $this->options['maximum'];
74  } elseif ($this->options['endRange'] !== PHP_INT_MAX) {
75  $maximum = $this->options['endRange'];
76  } else {
77  $maximum = PHP_INT_MAX;
78  }
79  } elseif (isset($this->options['maximum'])) {
80  $maximum = $this->options['maximum'];
81  } elseif (isset($this->options['endRange'])) {
82  $maximum = $this->options['endRange'];
83  } else {
84  $maximum = PHP_INT_MAX;
85  }
86 
87  if ($minimum > $maximum) {
88  $x = $minimum;
89  $minimum = $maximum;
90  $maximum = $x;
91  }
92  if ($value < $minimum || $value > $maximum) {
93  $this->addError($this->translateErrorMessage(
94  'validator.numberrange.range',
95  'extbase',
96  array(
97  $minimum,
98  $maximum
99  )
100  ), 1221561046, array($minimum, $maximum));
101  }
102  }
103 }
addError($message, $code, array $arguments=array(), $title='')
translateErrorMessage($translateKey, $extensionName, $arguments=array())