Better exceptions

This commit is contained in:
Alexandre Gomes Gaigalas 2010-09-25 02:54:10 -03:00
parent 0491cd885f
commit 85f4843df7
4 changed files with 17 additions and 10 deletions

View file

@ -1,8 +0,0 @@
<?php
namespace Respect\Validation\Date;
class AbstractDateException extends \OutOfBoundsException
{
}

View file

@ -2,7 +2,7 @@
namespace Respect\Validation\Date;
class OutOfBoundsException extends AbstractDateException
class OutOfBoundsException extends \OutOfBoundsException
{
}

View file

@ -0,0 +1,8 @@
<?php
namespace Respect\Validation\String;
class EmptyStringException extends \LengthException
{
}

View file

@ -7,6 +7,11 @@ use Respect\Validation\AbstractRule;
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)
{
@ -17,7 +22,9 @@ class NotEmpty extends AbstractRule implements Validatable
public function assert($input)
{
if (!$this->validate($input))
throw new Exception();
throw new EmptyStringException(
$this->getMessage(self::MSG_EMPTY_STRING)
);
}
}