本文整理汇总了PHP中Formatter::getNumber方法的典型用法代码示例。如果您正苦于以下问题:PHP Formatter::getNumber方法的具体用法?PHP Formatter::getNumber怎么用?PHP Formatter::getNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formatter
的用法示例。
在下文中一共展示了Formatter::getNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doValidate
public function doValidate($ctx)
{
$formattedValue = $ctx->getRequest()->getString($this->getName(), null);
// Validate only if there is a value
if ($formattedValue === null || $formattedValue === '') {
return true;
}
$format = new Formatter($ctx->getUser()->getTimezone(), $ctx->getUser()->getLocale());
$value = $format->getNumber($formattedValue);
if ($value === false) {
$msg = sprintf(Application::getTranslator()->_('The field %1$s must be a valid number'), $this->getLabel());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
if ($this->minValue) {
if ($this->minValue->isExclusive()) {
if ($value <= $this->minValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater than %2$s'), $this->getLabel(), $this->minValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
} else {
if ($value < $this->minValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater or equal to %2$s'), $this->getLabel(), $this->minValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
}
}
if ($this->maxValue) {
if ($this->maxValue->isExclusive()) {
if ($value >= $this->maxValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller than %2$s'), $this->getLabel(), $this->maxValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
} else {
if ($value > $this->maxValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller or equal to %2$s'), $this->getLabel(), $this->maxValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
}
}
return true;
}
示例2: testGetNumberException
/**
* @covers Formatter::getNumber
*/
public function testGetNumberException()
{
$actual = $this->formatter->getNumber("Nan", 1);
$this->assertFalse($actual);
}