mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Merge pull request #85 from Typeform/master
Add instanceOf to rules in readme.md
This commit is contained in:
commit
6d36b12f76
@ -114,6 +114,7 @@ V::lang('ar');
|
|||||||
* `dateAfter` - Field is a valid date and is after the given date
|
* `dateAfter` - Field is a valid date and is after the given date
|
||||||
* `contains` - Field is a string and contains the given string
|
* `contains` - Field is a string and contains the given string
|
||||||
* `creditCard` - Field is a valid credit card number
|
* `creditCard` - Field is a valid credit card number
|
||||||
|
* `instanceOf` - Field contains an instance of the given class
|
||||||
|
|
||||||
**NOTE**: If you are comparing floating-point numbers with min/max validators, you
|
**NOTE**: If you are comparing floating-point numbers with min/max validators, you
|
||||||
should install the [BCMath](http://us3.php.net/manual/en/book.bc.php)
|
should install the [BCMath](http://us3.php.net/manual/en/book.bc.php)
|
||||||
|
|||||||
@ -29,5 +29,6 @@ return array(
|
|||||||
'lengthBetween' => "must be between %d and %d characters",
|
'lengthBetween' => "must be between %d and %d characters",
|
||||||
'creditCard' => "must be a valid credit card number",
|
'creditCard' => "must be a valid credit card number",
|
||||||
"lengthMin" => "must contain greater than %d characters",
|
"lengthMin" => "must contain greater than %d characters",
|
||||||
"lengthMax" => "must contain less than %d characters"
|
"lengthMax" => "must contain less than %d characters",
|
||||||
|
"instanceOf" => "must be an instance of '%s'"
|
||||||
);
|
);
|
||||||
|
|||||||
@ -736,6 +736,10 @@ class Validator
|
|||||||
}
|
}
|
||||||
if ($param instanceof \DateTime) {
|
if ($param instanceof \DateTime) {
|
||||||
$param = $param->format('Y-m-d');
|
$param = $param->format('Y-m-d');
|
||||||
|
} else {
|
||||||
|
if(is_object($param)) {
|
||||||
|
$param = get_class($param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Use custom label instead of field name if set
|
// Use custom label instead of field name if set
|
||||||
if(is_string($params[0])) {
|
if(is_string($params[0])) {
|
||||||
|
|||||||
@ -833,6 +833,19 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertTrue($v->validate());
|
$this->assertTrue($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInstanceOfErrorMessageShowsInstanceName()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('attributeName' => new Validator(array())));
|
||||||
|
$v->rule('instanceOf', 'attributeName', new stdClass());
|
||||||
|
$v->validate();
|
||||||
|
$expected_error = array(
|
||||||
|
"attributeName" => array(
|
||||||
|
"AttributeName must be an instance of 'stdClass'"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals($expected_error, $v->errors());
|
||||||
|
}
|
||||||
|
|
||||||
public function testInstanceOfInvalidWithString()
|
public function testInstanceOfInvalidWithString()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('attributeName' => new stdClass()));
|
$v = new Validator(array('attributeName' => new stdClass()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user