mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Small fix
This commit is contained in:
parent
f9b98679b2
commit
b403f67739
|
@ -33,7 +33,7 @@ class HasAttribute extends All
|
|||
{
|
||||
if (!$this->validate($input))
|
||||
throw new AttributeNotPresentException($input, $this->attribute);
|
||||
return parent::validate($input->{$this->attribute});
|
||||
return parent::validate(@$input->{$this->attribute});
|
||||
}
|
||||
|
||||
public function check($input)
|
||||
|
|
|
@ -34,7 +34,7 @@ class HasKey extends All
|
|||
{
|
||||
if (!$this->validate($input))
|
||||
throw new KeyNotPresentException($input, $this->key);
|
||||
return parent::validate($input[$this->key]);
|
||||
return parent::validate(@$input[$this->key]);
|
||||
}
|
||||
|
||||
public function check($input)
|
||||
|
|
|
@ -60,4 +60,29 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($v);
|
||||
}
|
||||
|
||||
public function testSample()
|
||||
{
|
||||
|
||||
$target = new \stdClass;
|
||||
$target->id = 13;
|
||||
$target->created_at = '2009-10-10';
|
||||
$target->name = 'Alexandre';
|
||||
|
||||
$validator = Validator::object()
|
||||
->one(
|
||||
Validator::hasAttribute('screen_name',
|
||||
Validator::alnum('_')->noWhitespace()),
|
||||
Validator::hasAttribute('id', Validator::numeric())
|
||||
)
|
||||
->hasAttribute('created_at', Validator::date())
|
||||
->hasAttribute('name', $v160 = Validator::stringLength(1, 160))
|
||||
->hasOptionalAttribute('description', $v160)
|
||||
->hasOptionalAttribute('location', $v160);
|
||||
try {
|
||||
$validator->assert($target);
|
||||
} catch (InvalidException $e) {
|
||||
echo $e->message();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue