/**
* Checks if the given value is a valid number.
*
* @param mixed $value The value that should be validated
* @return void
* @api
* @todo Currency support should be added when it will be supported by NumberParser
*/
protected function isValid($value)
{
if (!isset($this->options['locale'])) {
$locale = $this->localizationService->getConfiguration()->getDefaultLocale();
} elseif (is_string($this->options['locale'])) {
$locale = new I18n\Locale($this->options['locale']);
} elseif ($this->options['locale'] instanceof I18n\Locale) {
$locale = $this->options['locale'];
} else {
$this->addError('The "locale" option can be only set to string identifier, or Locale object.', 1281286579);
return;
}
$strictMode = $this->options['strictMode'];
$formatLength = $this->options['formatLength'];
NumbersReader::validateFormatLength($formatLength);
$formatType = $this->options['formatType'];
NumbersReader::validateFormatType($formatType);
if ($formatType === NumbersReader::FORMAT_TYPE_PERCENT) {
if ($this->numberParser->parsePercentNumber($value, $locale, $formatLength, $strictMode) === false) {
$this->addError('A valid percent number is expected.', 1281452093);
}
return;
} else {
if ($this->numberParser->parseDecimalNumber($value, $locale, $formatLength, $strictMode) === false) {
$this->addError('A valid decimal number is expected.', 1281452094);
}
}
}