mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 06:42:22 +02:00
Remove "ValidationExceptionInterface"
This commit is contained in:
parent
67e072ebd3
commit
474afaa2ec
|
@ -72,6 +72,7 @@ All notable changes of the Respect\Validation releases are documented in this fi
|
|||
- Remove `addOr()` shortcut (#444)
|
||||
- Remove `NestedValidationExceptionInterface` interface (#591)
|
||||
- Remove `not()` shortcut (#444)
|
||||
- Remove `ValidationExceptionInterface` interface (#591)
|
||||
- Remove identical checking from "Equals" rule (#442)
|
||||
- Removed Deprecated Rules (#277)
|
||||
- Validation rules do not accept an empty string by default (#422)
|
||||
|
|
|
@ -98,11 +98,17 @@ $usernameValidator->validate('#$%'); //false
|
|||
|
||||
* `Repect\Validation\Exceptions\ExceptionInterface`:
|
||||
* All exceptions implement this interface;
|
||||
* `Respect\Validation\Exceptions\ValidationExceptionInterface`:
|
||||
* Extends the `Repect\Validation\Exceptions\ExceptionInterface` interface
|
||||
* Use when calling `check()`
|
||||
* All validation exceptions implement this interface
|
||||
* Interface has one method: `getMainMessage()`
|
||||
* `Respect\Validation\Exceptions\ValidationException`:
|
||||
* Implements the `Repect\Validation\Exceptions\ExceptionInterface` interface
|
||||
* Thrown when the `check()` fails
|
||||
* All validation exceptions extend this class
|
||||
* Available methods:
|
||||
* `getMainMessage()`;
|
||||
* `setMode($mode)`;
|
||||
* `setName($name)`;
|
||||
* `setParam($name, $value)`;
|
||||
* `setTemplate($template)`;
|
||||
* more...
|
||||
* `Respect\Validation\Exceptions\NestedValidationException`:
|
||||
* Extends the `Respect\Validation\Exceptions\ValidationException` class
|
||||
* Usually thrown when the `assert()` fails
|
||||
|
@ -279,11 +285,11 @@ validation report. There is also a `check()` method that returns an Exception
|
|||
only with the first error found:
|
||||
|
||||
```php
|
||||
use Respect\Validation\Exceptions\ValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
|
||||
try {
|
||||
$usernameValidator->check('really messed up screen#name');
|
||||
} catch(ValidationExceptionInterface $exception) {
|
||||
} catch(ValidationException $exception) {
|
||||
echo $exception->getMainMessage();
|
||||
}
|
||||
```
|
||||
|
|
|
@ -16,7 +16,7 @@ use Exception;
|
|||
use InvalidArgumentException;
|
||||
use Traversable;
|
||||
|
||||
class ValidationException extends InvalidArgumentException implements ValidationExceptionInterface
|
||||
class ValidationException extends InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
const MODE_DEFAULT = 1;
|
||||
const MODE_NEGATIVE = 2;
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Respect/Validation.
|
||||
*
|
||||
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
*
|
||||
* For the full copyright and license information, please view the "LICENSE.md"
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
interface ValidationExceptionInterface extends ExceptionInterface
|
||||
{
|
||||
public function getMainMessage();
|
||||
}
|
|
@ -5,7 +5,7 @@ Do not rely on nested validation exception interface for check
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Exceptions\ValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
$usernameValidator = Validator::alnum('_')->length(1, 15)->noWhitespace();
|
||||
|
@ -13,7 +13,7 @@ try {
|
|||
$usernameValidator->check('really messed up screen#name');
|
||||
} catch (NestedValidationException $e) {
|
||||
echo 'Check used NestedValidationException';
|
||||
} catch (ValidationExceptionInterface $e) {
|
||||
} catch (ValidationException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,7 +4,7 @@ not() with recursion should update mode from related rules
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\ValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
try {
|
||||
|
@ -12,7 +12,7 @@ try {
|
|||
Validator::intVal()->positive()
|
||||
);
|
||||
$validator->check(2);
|
||||
} catch (ValidationExceptionInterface $exception) {
|
||||
} catch (ValidationException $exception) {
|
||||
echo $exception->getMainMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\ValidationExceptionInterface;
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
function translatorCallback($message)
|
||||
|
@ -16,7 +16,7 @@ function translatorCallback($message)
|
|||
|
||||
try {
|
||||
Validator::stringType()->length(2, 15)->check(0);
|
||||
} catch (ValidationExceptionInterface $exception) {
|
||||
} catch (ValidationException $exception) {
|
||||
$exception->setParam('translator', 'translatorCallback');
|
||||
|
||||
echo $exception->getMainMessage();
|
||||
|
|
|
@ -66,9 +66,9 @@ class CheckExceptionsTest extends \PHPUnit_Framework_TestCase
|
|||
'Every exception should extend an Exception class.'
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
'Respect\Validation\Exceptions\ValidationExceptionInterface',
|
||||
'Respect\Validation\Exceptions\ValidationException',
|
||||
$exceptionObject,
|
||||
'Every Respect/Validation exception must implement out interface.'
|
||||
'Every Respect/Validation exception must extend ValidationException.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ use stdClass;
|
|||
|
||||
class ValidationExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testItImplementsValidationExceptionInterface()
|
||||
public function testItImplementsExceptionInterface()
|
||||
{
|
||||
$validationException = new ValidationException();
|
||||
$this->assertInstanceOf('Respect\Validation\Exceptions\ValidationExceptionInterface', $validationException);
|
||||
$this->assertInstanceOf('Respect\Validation\Exceptions\ExceptionInterface', $validationException);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue