mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Better exceptions
This commit is contained in:
parent
0491cd885f
commit
85f4843df7
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Respect\Validation\Date;
|
|
||||||
|
|
||||||
class AbstractDateException extends \OutOfBoundsException
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Respect\Validation\Date;
|
namespace Respect\Validation\Date;
|
||||||
|
|
||||||
class OutOfBoundsException extends AbstractDateException
|
class OutOfBoundsException extends \OutOfBoundsException
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Respect\Validation\String;
|
||||||
|
|
||||||
|
class EmptyStringException extends \LengthException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -7,6 +7,11 @@ use Respect\Validation\AbstractRule;
|
||||||
|
|
||||||
class NotEmpty extends AbstractRule implements Validatable
|
class NotEmpty extends AbstractRule implements Validatable
|
||||||
{
|
{
|
||||||
|
const MSG_EMPTY_STRING = 'String_NotEmpty_1';
|
||||||
|
|
||||||
|
protected $messages = array(
|
||||||
|
self::MSG_EMPTY_STRING => 'You provided an empty string'
|
||||||
|
);
|
||||||
|
|
||||||
public function validate($input)
|
public function validate($input)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +22,9 @@ class NotEmpty extends AbstractRule implements Validatable
|
||||||
public function assert($input)
|
public function assert($input)
|
||||||
{
|
{
|
||||||
if (!$this->validate($input))
|
if (!$this->validate($input))
|
||||||
throw new Exception();
|
throw new EmptyStringException(
|
||||||
|
$this->getMessage(self::MSG_EMPTY_STRING)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue