Made the BC Math extension optional

This commit is contained in:
Vance Lucas 2014-07-07 09:00:28 -05:00
parent c984bc100e
commit f52df87b56
2 changed files with 18 additions and 2 deletions

View File

@ -301,7 +301,11 @@ class Validator
*/
protected function validateMin($field, $value, $params)
{
return !(bccomp($params[0], $value, 14) == 1);
if (function_exists('bccomp')) {
return !(bccomp($params[0], $value, 14) == 1);
} else {
return $params[0] <= $value;
}
}
/**
@ -315,7 +319,11 @@ class Validator
*/
protected function validateMax($field, $value, $params)
{
return !(bccomp($value, $params[0], 14) == 1);
if (function_exists('bccomp')) {
return !(bccomp($value, $params[0], 14) == 1);
} else {
return $params[0] >= $value;
}
}
/**

View File

@ -188,6 +188,10 @@ class ValidateTest extends BaseTestCase
public function testMinValidFloat()
{
if (!function_exists('bccomp')) {
$this->markTestSkipped("Floating point comparison requires the BC Math extension to be installed");
}
$v = new Validator(array('num' => 0.9));
$v->rule('min', 'num', 0.5);
$this->assertTrue($v->validate());
@ -224,6 +228,10 @@ class ValidateTest extends BaseTestCase
public function testMaxValidFloat()
{
if (!function_exists('bccomp')) {
$this->markTestSkipped("Accurate floating point comparison requires the BC Math extension to be installed");
}
$v = new Validator(array('num' => 0.4));
$v->rule('max', 'num', 0.5);
$this->assertTrue($v->validate());