first commit

This commit is contained in:
Claudecio Martins
2026-06-16 10:04:10 -03:00
commit a951944997
4463 changed files with 419677 additions and 0 deletions
+375
View File
@@ -0,0 +1,375 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation;
use finfo;
interface ChainedValidator extends Validatable
{
public function allOf(Validatable ...$rule): ChainedValidator;
public function alnum(string ...$additionalChars): ChainedValidator;
public function alpha(string ...$additionalChars): ChainedValidator;
public function alwaysInvalid(): ChainedValidator;
public function alwaysValid(): ChainedValidator;
public function anyOf(Validatable ...$rule): ChainedValidator;
public function arrayType(): ChainedValidator;
public function arrayVal(): ChainedValidator;
public function attribute(
string $reference,
?Validatable $validator = null,
bool $mandatory = true
): ChainedValidator;
public function base(int $base, ?string $chars = null): ChainedValidator;
public function base64(): ChainedValidator;
/**
* @param mixed $minimum
* @param mixed $maximum
*/
public function between($minimum, $maximum): ChainedValidator;
public function boolType(): ChainedValidator;
public function boolVal(): ChainedValidator;
public function bsn(): ChainedValidator;
public function call(callable $callable, Validatable $rule): ChainedValidator;
public function callableType(): ChainedValidator;
public function callback(callable $callback): ChainedValidator;
public function charset(string ...$charset): ChainedValidator;
public function cnh(): ChainedValidator;
public function cnpj(): ChainedValidator;
public function control(string ...$additionalChars): ChainedValidator;
public function consonant(string ...$additionalChars): ChainedValidator;
/**
* @param mixed $containsValue
*/
public function contains($containsValue, bool $identical = false): ChainedValidator;
/**
* @param mixed[] $needles
*/
public function containsAny(array $needles, bool $strictCompareArray = false): ChainedValidator;
public function countable(): ChainedValidator;
public function countryCode(?string $set = null): ChainedValidator;
public function currencyCode(): ChainedValidator;
public function cpf(): ChainedValidator;
public function creditCard(?string $brand = null): ChainedValidator;
public function date(string $format = 'Y-m-d'): ChainedValidator;
public function dateTime(?string $format = null): ChainedValidator;
public function decimal(int $decimals): ChainedValidator;
public function digit(string ...$additionalChars): ChainedValidator;
public function directory(): ChainedValidator;
public function domain(bool $tldCheck = true): ChainedValidator;
public function each(Validatable $rule): ChainedValidator;
public function email(): ChainedValidator;
/**
* @param mixed $endValue
*/
public function endsWith($endValue, bool $identical = false): ChainedValidator;
/**
* @param mixed $compareTo
*/
public function equals($compareTo): ChainedValidator;
/**
* @param mixed $compareTo
*/
public function equivalent($compareTo): ChainedValidator;
public function even(): ChainedValidator;
public function executable(): ChainedValidator;
public function exists(): ChainedValidator;
public function extension(string $extension): ChainedValidator;
public function factor(int $dividend): ChainedValidator;
public function falseVal(): ChainedValidator;
public function fibonacci(): ChainedValidator;
public function file(): ChainedValidator;
/**
* @param mixed[]|int $options
*/
public function filterVar(int $filter, $options = null): ChainedValidator;
public function finite(): ChainedValidator;
public function floatVal(): ChainedValidator;
public function floatType(): ChainedValidator;
public function graph(string ...$additionalChars): ChainedValidator;
/**
* @param mixed $compareTo
*/
public function greaterThan($compareTo): ChainedValidator;
public function hexRgbColor(): ChainedValidator;
public function iban(): ChainedValidator;
/**
* @param mixed $compareTo
*/
public function identical($compareTo): ChainedValidator;
public function image(?finfo $fileInfo = null): ChainedValidator;
public function imei(): ChainedValidator;
/**
* @param mixed[]|mixed $haystack
*/
public function in($haystack, bool $compareIdentical = false): ChainedValidator;
public function infinite(): ChainedValidator;
public function instance(string $instanceName): ChainedValidator;
public function intVal(): ChainedValidator;
public function intType(): ChainedValidator;
public function ip(string $range = '*', ?int $options = null): ChainedValidator;
public function isbn(): ChainedValidator;
public function iterableType(): ChainedValidator;
public function json(): ChainedValidator;
public function key(
string $reference,
?Validatable $referenceValidator = null,
bool $mandatory = true
): ChainedValidator;
public function keyNested(
string $reference,
?Validatable $referenceValidator = null,
bool $mandatory = true
): ChainedValidator;
public function keySet(Validatable ...$rule): ChainedValidator;
public function keyValue(string $comparedKey, string $ruleName, string $baseKey): ChainedValidator;
public function languageCode(?string $set = null): ChainedValidator;
public function leapDate(string $format): ChainedValidator;
public function leapYear(): ChainedValidator;
public function length(?int $min = null, ?int $max = null, bool $inclusive = true): ChainedValidator;
public function lowercase(): ChainedValidator;
/**
* @param mixed $compareTo
*/
public function lessThan($compareTo): ChainedValidator;
public function luhn(): ChainedValidator;
public function macAddress(): ChainedValidator;
/**
* @param mixed $compareTo
*/
public function max($compareTo): ChainedValidator;
public function maxAge(int $age, ?string $format = null): ChainedValidator;
public function mimetype(string $mimetype): ChainedValidator;
/**
* @param mixed $compareTo
*/
public function min($compareTo): ChainedValidator;
public function minAge(int $age, ?string $format = null): ChainedValidator;
public function multiple(int $multipleOf): ChainedValidator;
public function negative(): ChainedValidator;
public function nfeAccessKey(): ChainedValidator;
public function nif(): ChainedValidator;
public function nip(): ChainedValidator;
public function no(bool $useLocale = false): ChainedValidator;
public function noneOf(Validatable ...$rule): ChainedValidator;
public function not(Validatable $rule): ChainedValidator;
public function notBlank(): ChainedValidator;
public function notEmoji(): ChainedValidator;
public function notEmpty(): ChainedValidator;
public function notOptional(): ChainedValidator;
public function noWhitespace(): ChainedValidator;
public function nullable(Validatable $rule): ChainedValidator;
public function nullType(): ChainedValidator;
public function number(): ChainedValidator;
public function numericVal(): ChainedValidator;
public function objectType(): ChainedValidator;
public function odd(): ChainedValidator;
public function oneOf(Validatable ...$rule): ChainedValidator;
public function optional(Validatable $rule): ChainedValidator;
public function perfectSquare(): ChainedValidator;
public function pesel(): ChainedValidator;
public function phone(): ChainedValidator;
public function phpLabel(): ChainedValidator;
public function pis(): ChainedValidator;
public function polishIdCard(): ChainedValidator;
public function portugueseNif(): ChainedValidator;
public function positive(): ChainedValidator;
public function postalCode(string $countryCode): ChainedValidator;
public function primeNumber(): ChainedValidator;
public function printable(string ...$additionalChars): ChainedValidator;
public function publicDomainSuffix(): ChainedValidator;
public function punct(string ...$additionalChars): ChainedValidator;
public function readable(): ChainedValidator;
public function regex(string $regex): ChainedValidator;
public function resourceType(): ChainedValidator;
public function roman(): ChainedValidator;
public function scalarVal(): ChainedValidator;
public function size(?string $minSize = null, ?string $maxSize = null): ChainedValidator;
public function slug(): ChainedValidator;
public function sorted(string $direction): ChainedValidator;
public function space(string ...$additionalChars): ChainedValidator;
/**
* @param mixed $startValue
*/
public function startsWith($startValue, bool $identical = false): ChainedValidator;
public function stringType(): ChainedValidator;
public function stringVal(): ChainedValidator;
public function subdivisionCode(string $countryCode): ChainedValidator;
/**
* @param mixed[] $superset
*/
public function subset(array $superset): ChainedValidator;
public function symbolicLink(): ChainedValidator;
public function time(string $format = 'H:i:s'): ChainedValidator;
public function tld(): ChainedValidator;
public function trueVal(): ChainedValidator;
public function type(string $type): ChainedValidator;
public function unique(): ChainedValidator;
public function uploaded(): ChainedValidator;
public function uppercase(): ChainedValidator;
public function url(): ChainedValidator;
public function uuid(?int $version = null): ChainedValidator;
public function version(): ChainedValidator;
public function videoUrl(?string $service = null): ChainedValidator;
public function vowel(string ...$additionalChars): ChainedValidator;
public function when(Validatable $if, Validatable $then, ?Validatable $else = null): ChainedValidator;
public function writable(): ChainedValidator;
public function xdigit(string ...$additionalChars): ChainedValidator;
public function yes(bool $useLocale = false): ChainedValidator;
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see NestedValidationException} instead.
*/
class AllOfException extends GroupedValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::NONE => 'All of the required rules must pass for {{name}}',
self::SOME => 'These rules must pass for {{name}}',
],
self::MODE_NEGATIVE => [
self::NONE => 'None of these rules must pass for {{name}}',
self::SOME => 'These rules must not pass for {{name}}',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class AlnumException extends FilteredValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only letters (a-z) and digits (0-9)',
self::EXTRA => '{{name}} must contain only letters (a-z), digits (0-9) and {{additionalChars}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain letters (a-z) or digits (0-9)',
self::EXTRA => '{{name}} must not contain letters (a-z), digits (0-9) or {{additionalChars}}',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class AlphaException extends FilteredValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only letters (a-z)',
self::EXTRA => '{{name}} must contain only letters (a-z) and {{additionalChars}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain letters (a-z)',
self::EXTRA => '{{name}} must not contain letters (a-z) or {{additionalChars}}',
],
];
}
@@ -0,0 +1,35 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class AlwaysInvalidException extends ValidationException
{
public const SIMPLE = 'simple';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} is always invalid',
self::SIMPLE => '{{name}} is not valid',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} is always valid',
self::SIMPLE => '{{name}} is valid',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class AlwaysValidException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} is always valid',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} is always invalid',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class AnyOfException extends NestedValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'At least one of these rules must pass for {{name}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => 'At least one of these rules must not pass for {{name}}',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author João Torquato <joao.otl@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ArrayTypeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be of type array',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be of type array',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ArrayValException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an array value',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an array value',
],
];
}
@@ -0,0 +1,46 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exceptions to be thrown by the Attribute Rule.
*
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class AttributeException extends NestedValidationException implements NonOmissibleException
{
public const NOT_PRESENT = 'not_present';
public const INVALID = 'invalid';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::NOT_PRESENT => 'Attribute {{name}} must be present',
self::INVALID => 'Attribute {{name}} must be valid',
],
self::MODE_NEGATIVE => [
self::NOT_PRESENT => 'Attribute {{name}} must not be present',
self::INVALID => 'Attribute {{name}} must not validate',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
return $this->getParam('hasReference') ? self::INVALID : self::NOT_PRESENT;
}
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jens Segers <segers.jens@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class Base64Exception extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be Base64-encoded',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be Base64-encoded',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Carlos André Ferrari <caferrari@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class BaseException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a number in the base {{base}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a number in the base {{base}}',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class BetweenException extends NestedValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be between {{minValue}} and {{maxValue}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be between {{minValue}} and {{maxValue}}',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exception class for BoolType rule.
*
* @author Devin Torres <devin@devintorres.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class BoolTypeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be of type boolean',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be of type boolean',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class BoolValException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a boolean value',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a boolean value',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Ronald Drenth <ronalddrenth@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class BsnException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a BSN',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a BSN',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CallException extends NestedValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{input}} must be valid when executed with {{callable}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{input}} must not be valid when executed with {{callable}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exception class for CallableType rule.
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CallableTypeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be callable',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be callable',
],
];
}
@@ -0,0 +1,20 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CallbackException extends NestedValidationException
{
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CharsetException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be in the {{charset}} charset',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be in the {{charset}} charset',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Kinn Coelho Julião <kinncj@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CnhException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid CNH number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid CNH number',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Leonn Leite <leonnleite@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CnpjException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid CNPJ number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid CNPJ number',
],
];
}
@@ -0,0 +1,21 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use Exception;
use Throwable;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
class ComponentException extends Exception implements Throwable
{
}
@@ -0,0 +1,33 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Kleber Hamada Sato <kleberhs007@yahoo.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ConsonantException extends FilteredValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only consonants',
self::EXTRA => '{{name}} must contain only consonants and {{additionalChars}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain consonants',
self::EXTRA => '{{name}} must not contain consonants or {{additionalChars}}',
],
];
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Kirill Dlussky <kirill@dlussky.ru>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ContainsAnyException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain at least one of the values {{needles}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain any of the values {{needles}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ContainsException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain the value {{containsValue}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain the value {{containsValue}}',
],
];
}
@@ -0,0 +1,33 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Andre Ramaciotti <andre@ramaciotti.com>
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ControlException extends FilteredValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only control characters',
self::EXTRA => '{{name}} must contain only control characters and {{additionalChars}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain control characters',
self::EXTRA => '{{name}} must not contain control characters or {{additionalChars}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author João Torquato <joao.otl@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CountableException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be countable',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be countable',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CountryCodeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid country',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid country',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jair Henrique <jair.henrique@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CpfException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid CPF number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid CPF number',
],
];
}
@@ -0,0 +1,49 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use Respect\Validation\Rules\CreditCard;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jean Pimentel <jeanfap@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CreditCardException extends ValidationException
{
public const BRANDED = 'branded';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid Credit Card number',
self::BRANDED => '{{name}} must be a valid {{brand}} Credit Card number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid Credit Card number',
self::BRANDED => '{{name}} must not be a valid {{brand}} Credit Card number',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
if ($this->getParam('brand') === CreditCard::ANY) {
return self::STANDARD;
}
return self::BRANDED;
}
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Justin Hook <justinhook88@yahoo.co.uk>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class CurrencyCodeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid currency',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid currency',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Bruno Luiz da Silva <contato@brunoluiz.net>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class DateException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid date in the format {{sample}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid date in the format {{sample}}',
],
];
}
@@ -0,0 +1,42 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class DateTimeException extends ValidationException
{
public const FORMAT = 'format';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid date/time',
self::FORMAT => '{{name}} must be a valid date/time in the format {{sample}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid date/time',
self::FORMAT => '{{name}} must not be a valid date/time in the format {{sample}}',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
return $this->getParam('format') ? self::FORMAT : self::STANDARD;
}
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class DecimalException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must have {{decimals}} decimals',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not have {{decimals}} decimals',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class DigitException extends FilteredValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only digits (0-9)',
self::EXTRA => '{{name}} must contain only digits (0-9) and {{additionalChars}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain digits (0-9)',
self::EXTRA => '{{name}} must not contain digits (0-9) and {{additionalChars}}',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class DirectoryException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a directory',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a directory',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class DomainException extends NestedValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid domain',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid domain',
],
];
}
@@ -0,0 +1,53 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class EachException extends NestedValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'Each item in {{name}} must be valid',
],
self::MODE_NEGATIVE => [
self::STANDARD => 'Each item in {{name}} must not validate',
],
];
/**
* {@inheritDoc}
*
* @todo This method shares too much with the parent implementation
*/
public function getMessages(array $templates = []): array
{
$messages = [];
$count = -1;
foreach ($this->getChildren() as $exception) {
$count++;
$id = $exception->getId();
$messages[$id . '.' . $count] = $this->renderMessage(
$exception,
$this->findTemplates($templates, $this->getId())
);
}
return $messages;
}
}
@@ -0,0 +1,35 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exceptions thrown by email rule.
*
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Andrey Kolyshkin <a.kolyshkin@semrush.com>
* @author Eduardo Gulias Davis <me@egulias.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Paul Karikari <paulkarikari1@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class EmailException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be valid email',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an email',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class EndsWithException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must end with {{endValue}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not end with {{endValue}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Ian Nisbet <ian@glutenite.co.uk>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class EqualsException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must equal {{compareTo}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not equal {{compareTo}}',
],
];
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class EquivalentException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be equivalent to {{compareTo}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be equivalent to {{compareTo}}',
],
];
}
@@ -0,0 +1,33 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exceptions to be thrown by the Even Rule.
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jean Pimentel <jeanfap@gmail.com>
* @author Paul Karikari <paulkarikari1@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class EvenException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an even number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an even number',
],
];
}
@@ -0,0 +1,20 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use Throwable;
/**
* @author Andy Wendt <andy@awendt.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
interface Exception extends Throwable
{
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ExecutableException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an executable file',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an executable file',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ExistsException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must exist',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not exist',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exception class for Extension rule.
*
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ExtensionException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must have {{extension}} extension',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not have {{extension}} extension',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author David Meister <thedavidmeister@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FactorException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a factor of {{dividend}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a factor of {{dividend}}',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FalseValException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must evaluate to `false`',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not evaluate to `false`',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Samuel Heinzmann <samuel.heinzmann@swisscom.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FibonacciException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid Fibonacci number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid Fibonacci number',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FileException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a file',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a file',
],
];
}
@@ -0,0 +1,18 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FilterVarException extends ValidationException
{
}
@@ -0,0 +1,26 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
*/
class FilteredValidationException extends ValidationException
{
public const EXTRA = 'extra';
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
return $this->getParam('additionalChars') ? self::EXTRA : self::STANDARD;
}
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FiniteException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a finite number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a finite number',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exception class for FloatType rule.
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Reginaldo Junior <76regi@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FloatTypeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be of type float',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be of type float',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class FloatValException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a float number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a float number',
],
];
}
@@ -0,0 +1,33 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Andre Ramaciotti <andre@ramaciotti.com>
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class GraphException extends FilteredValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only graphical characters',
self::EXTRA => '{{name}} must contain only graphical characters and {{additionalChars}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain graphical characters',
self::EXTRA => '{{name}} must not contain graphical characters or {{additionalChars}}',
],
];
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class GreaterThanException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be greater than {{compareTo}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be greater than {{compareTo}}',
],
];
}
@@ -0,0 +1,47 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use function count;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
class GroupedValidationException extends NestedValidationException
{
public const NONE = 'none';
public const SOME = 'some';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::NONE => 'All of the required rules must pass for {{name}}',
self::SOME => 'These rules must pass for {{name}}',
],
self::MODE_NEGATIVE => [
self::NONE => 'None of there rules must pass for {{name}}',
self::SOME => 'These rules must not pass for {{name}}',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
$numRules = $this->getParam('passed');
$numFailed = count($this->getChildren());
return $numRules === $numFailed ? self::NONE : self::SOME;
}
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Davide Pastore <pasdavide@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class HexRgbColorException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a hex RGB color',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a hex RGB color',
],
];
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Mazen Touati <mazen_touati@hotmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class IbanException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid IBAN',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid IBAN',
],
];
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class IdenticalException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be identical as {{compareTo}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be identical as {{compareTo}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Guilherme Siani <guilherme@siani.com.br>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ImageException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid image',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid image',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Diego Oliveira <contato@diegoholiveira.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class ImeiException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid IMEI',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid IMEI',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class InException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be in {{haystack}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be in {{haystack}}',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class InfiniteException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an infinite number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an infinite number',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class InstanceException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an instance of {{instanceName}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an instance of {{instanceName}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exception class for IntType rule.
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class IntTypeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be of type integer',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be of type integer',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class IntValException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an integer number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an integer number',
],
];
}
@@ -0,0 +1,22 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exception for invalid classes.
*
* @since 2.0.0
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class InvalidClassException extends ComponentException
{
}
@@ -0,0 +1,48 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class IpException extends ValidationException
{
public const NETWORK_RANGE = 'network_range';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an IP address',
self::NETWORK_RANGE => '{{name}} must be an IP address in the {{range}} range',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be an IP address',
self::NETWORK_RANGE => '{{name}} must not be an IP address in the {{range}} range',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
if (!$this->getParam('range')) {
return self::STANDARD;
}
return self::NETWORK_RANGE;
}
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Moritz Fromm <moritzgitfromm@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class IsbnException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a ISBN',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a ISBN',
],
];
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class IterableTypeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be iterable',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be iterable',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class JsonException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid JSON string',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid JSON string',
],
];
}
@@ -0,0 +1,46 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exceptions to be thrown by the Attribute Rule.
*
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class KeyException extends NestedValidationException implements NonOmissibleException
{
public const NOT_PRESENT = 'not_present';
public const INVALID = 'invalid';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::NOT_PRESENT => '{{name}} must be present',
self::INVALID => '{{name}} must be valid',
],
self::MODE_NEGATIVE => [
self::NOT_PRESENT => '{{name}} must not be present',
self::INVALID => '{{name}} must not be valid',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
return $this->getParam('hasReference') ? self::INVALID : self::NOT_PRESENT;
}
}
@@ -0,0 +1,46 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exceptions to be thrown by the Attribute Rule.
*
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Ivan Zinovyev <vanyazin@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class KeyNestedException extends NestedValidationException implements NonOmissibleException
{
public const NOT_PRESENT = 'not_present';
public const INVALID = 'invalid';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::NOT_PRESENT => 'No items were found for key chain {{name}}',
self::INVALID => 'Key chain {{name}} is not valid',
],
self::MODE_NEGATIVE => [
self::NOT_PRESENT => 'Items for key chain {{name}} must not be present',
self::INVALID => 'Key chain {{name}} must not be valid',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
return $this->getParam('hasReference') ? self::INVALID : self::NOT_PRESENT;
}
}
@@ -0,0 +1,50 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use function count;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class KeySetException extends GroupedValidationException implements NonOmissibleException
{
public const STRUCTURE = 'structure';
public const STRUCTURE_EXTRA = 'structure_extra';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::NONE => 'All of the required rules must pass for {{name}}',
self::SOME => 'These rules must pass for {{name}}',
self::STRUCTURE => 'Must have keys {{keys}}',
self::STRUCTURE_EXTRA => 'Must not have keys {{extraKeys}}',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
if (count($this->getParam('extraKeys'))) {
return self::STRUCTURE_EXTRA;
}
if (count($this->getChildren()) === 0) {
return self::STRUCTURE;
}
return parent::chooseTemplate();
}
}
@@ -0,0 +1,38 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class KeyValueException extends ValidationException
{
public const COMPONENT = 'component';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'Key {{name}} must be present',
self::COMPONENT => '{{baseKey}} must be valid to validate {{comparedKey}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => 'Key {{name}} must not be present',
self::COMPONENT => '{{baseKey}} must not be valid to validate {{comparedKey}}',
],
];
protected function chooseTemplate(): string
{
return $this->getParam('component') ? self::COMPONENT : self::STANDARD;
}
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class LanguageCodeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid ISO 639 {{set}} language code',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid ISO 639 {{set}} language code',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class LeapDateException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be leap date',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be leap date',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class LeapYearException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a leap year',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a leap year',
],
];
}
@@ -0,0 +1,71 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Mazen Touati <mazen_touati@hotmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class LengthException extends ValidationException
{
public const BOTH = 'both';
public const LOWER = 'lower';
public const LOWER_INCLUSIVE = 'lower_inclusive';
public const GREATER = 'greater';
public const GREATER_INCLUSIVE = 'greater_inclusive';
public const EXACT = 'exact';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}',
self::LOWER => '{{name}} must have a length greater than {{minValue}}',
self::LOWER_INCLUSIVE => '{{name}} must have a length greater than or equal to {{minValue}}',
self::GREATER => '{{name}} must have a length lower than {{maxValue}}',
self::GREATER_INCLUSIVE => '{{name}} must have a length lower than or equal to {{maxValue}}',
self::EXACT => '{{name}} must have a length of {{maxValue}}',
],
self::MODE_NEGATIVE => [
self::BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}',
self::LOWER => '{{name}} must not have a length greater than {{minValue}}',
self::LOWER_INCLUSIVE => '{{name}} must not have a length greater than or equal to {{minValue}}',
self::GREATER => '{{name}} must not have a length lower than {{maxValue}}',
self::GREATER_INCLUSIVE => '{{name}} must not have a length lower than or equal to {{maxValue}}',
self::EXACT => '{{name}} must not have a length of {{maxValue}}',
],
];
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
{
$isInclusive = $this->getParam('inclusive');
if (!$this->getParam('minValue')) {
return $isInclusive === true ? self::GREATER_INCLUSIVE : self::GREATER;
}
if (!$this->getParam('maxValue')) {
return $isInclusive === true ? self::LOWER_INCLUSIVE : self::LOWER;
}
if ($this->getParam('minValue') == $this->getParam('maxValue')) {
return self::EXACT;
}
return self::BOTH;
}
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class LessThanException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be less than {{compareTo}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be less than {{compareTo}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jean Pimentel <jeanfap@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class LowercaseException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be lowercase',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be lowercase',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexander Gorshkov <mazanax@yandex.ru>
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class LuhnException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid Luhn number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid Luhn number',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Fábio da Silva Ribeiro <fabiorphp@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class MacAddressException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid MAC address',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid MAC address',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class MaxAgeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be {{age}} years or less',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be {{age}} years or less',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Andrew Peters <amp343@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class MaxException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be less than or equal to {{compareTo}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be less than or equal to {{compareTo}}',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* Exception class for Mimetype rule.
*
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class MimetypeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must have {{mimetype}} MIME type',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not have {{mimetype}} MIME type',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jean Pimentel <jeanfap@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class MinAgeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be {{age}} years or more',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be {{age}} years or more',
],
];
}
@@ -0,0 +1,32 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class MinException extends ValidationException
{
public const INCLUSIVE = 'inclusive';
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be greater than or equal to {{compareTo}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be greater than or equal to {{compareTo}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jean Pimentel <jeanfap@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class MultipleException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be multiple of {{multipleOf}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be multiple of {{multipleOf}}',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Ismael Elias <ismael.esq@hotmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class NegativeException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be negative',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be negative',
],
];
}
@@ -0,0 +1,258 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use IteratorAggregate;
use RecursiveIteratorIterator;
use SplObjectStorage;
use function array_shift;
use function count;
use function current;
use function implode;
use function is_array;
use function is_string;
use function spl_object_hash;
use function sprintf;
use function str_repeat;
use const PHP_EOL;
/**
* Exception for nested validations.
*
* This exception allows to have exceptions inside itself and providers methods
* to handle them and to retrieve nested messages based on itself and its
* children.
*
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jonathan Stewmon <jstewmon@rmn.com>
* @author Wojciech Frącz <fraczwojciech@gmail.com>
*
* @implements IteratorAggregate<ValidationException>
*/
class NestedValidationException extends ValidationException implements IteratorAggregate
{
/**
* @var ValidationException[]
*/
private $exceptions = [];
/**
* Returns the exceptions that are children of the exception.
*
* @return ValidationException[]
*/
public function getChildren(): array
{
return $this->exceptions;
}
/**
* Adds a child to the exception.
*/
public function addChild(ValidationException $exception): self
{
$this->exceptions[spl_object_hash($exception)] = $exception;
return $this;
}
/**
* Adds children to the exception.
*
* @param ValidationException[] $exceptions
*/
public function addChildren(array $exceptions): self
{
foreach ($exceptions as $exception) {
$this->addChild($exception);
}
return $this;
}
/**
* @return SplObjectStorage<ValidationException, int>
*/
public function getIterator(): SplObjectStorage
{
/** @var SplObjectStorage<ValidationException, int> */
$childrenExceptions = new SplObjectStorage();
$recursiveIteratorIterator = $this->getRecursiveIterator();
$lastDepth = 0;
$lastDepthOriginal = 0;
$knownDepths = [];
foreach ($recursiveIteratorIterator as $childException) {
if ($this->isOmissible($childException)) {
continue;
}
$currentDepth = $lastDepth;
$currentDepthOriginal = $recursiveIteratorIterator->getDepth() + 1;
if (isset($knownDepths[$currentDepthOriginal])) {
$currentDepth = $knownDepths[$currentDepthOriginal];
} elseif ($currentDepthOriginal > $lastDepthOriginal) {
++$currentDepth;
}
if (!isset($knownDepths[$currentDepthOriginal])) {
$knownDepths[$currentDepthOriginal] = $currentDepth;
}
$lastDepth = $currentDepth;
$lastDepthOriginal = $currentDepthOriginal;
$childrenExceptions->offsetSet($childException, $currentDepth);
}
return $childrenExceptions;
}
/**
* Returns a key->value array with all the messages of the exception.
*
* In this array the "keys" are the ids of the exceptions (defined name or
* name of the rule) and the values are the message.
*
* Once templates are passed it overwrites the templates of the given
* messages.
*
* @param string[]|string[][] $templates
*
* @return string[]
*/
public function getMessages(array $templates = []): array
{
$messages = [$this->getId() => $this->renderMessage($this, $templates)];
foreach ($this->getChildren() as $exception) {
$id = $exception->getId();
if (!$exception instanceof self) {
$messages[$id] = $this->renderMessage(
$exception,
$this->findTemplates($templates, $this->getId())
);
continue;
}
$messages[$id] = $exception->getMessages($this->findTemplates($templates, $id, $this->getId()));
if (count($messages[$id]) > 1) {
continue;
}
$messages[$id] = current($messages[$exception->getId()]);
}
if (count($messages) > 1) {
unset($messages[$this->getId()]);
}
return $messages;
}
/**
* Returns a string with all the messages of the exception.
*/
public function getFullMessage(): string
{
$messages = [];
$leveler = 1;
if (!$this->isOmissible($this)) {
$leveler = 0;
$messages[] = sprintf('- %s', $this->getMessage());
}
$exceptions = $this->getIterator();
/** @var ValidationException $exception */
foreach ($exceptions as $exception) {
$messages[] = sprintf(
'%s- %s',
str_repeat(' ', (int) ($exceptions[$exception] - $leveler) * 2),
$exception->getMessage()
);
}
return implode(PHP_EOL, $messages);
}
/**
* @param string[]|string[][] $templates
*/
protected function renderMessage(ValidationException $exception, array $templates): string
{
if (isset($templates[$exception->getId()]) && is_string($templates[$exception->getId()])) {
$exception->updateTemplate($templates[$exception->getId()]);
}
return $exception->getMessage();
}
/**
* @param string[]|string[][] $templates
* @param mixed ...$ids
*
* @return string[]|string[][]
*/
protected function findTemplates(array $templates, ...$ids): array
{
while (count($ids) > 0) {
$id = array_shift($ids);
if (!isset($templates[$id])) {
continue;
}
if (!is_array($templates[$id])) {
continue;
}
$templates = $templates[$id];
}
return $templates;
}
/**
* @return RecursiveIteratorIterator<RecursiveExceptionIterator>
*/
private function getRecursiveIterator(): RecursiveIteratorIterator
{
return new RecursiveIteratorIterator(
new RecursiveExceptionIterator($this),
RecursiveIteratorIterator::SELF_FIRST
);
}
private function isOmissible(Exception $exception): bool
{
if (!$exception instanceof self) {
return false;
}
if (count($exception->getChildren()) !== 1) {
return false;
}
/** @var ValidationException $childException */
$childException = current($exception->getChildren());
if ($childException->getMessage() === $exception->getMessage()) {
return true;
}
if ($exception->hasCustomTemplate()) {
return $childException->hasCustomTemplate();
}
return !$childException instanceof NonOmissibleException;
}
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Andrey Knupp Vital <andreykvital@gmail.com>
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class NfeAccessKeyException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid NFe access key',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid NFe access key',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Julián Gutiérrez <juliangut@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class NifException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a NIF',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a NIF',
],
];
}
@@ -0,0 +1,30 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Tomasz Regdos <tomek@regdos.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class NipException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid Polish VAT identification number',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid Polish VAT identification number',
],
];
}
@@ -0,0 +1,29 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class NoException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be similar to "No"',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be similar to "No"',
],
];
}
@@ -0,0 +1,31 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @deprecated Using rule exceptions directly is deprecated, and will be removed in the next major version. Please use {@see ValidationException} instead.
*/
final class NoWhitespaceException extends ValidationException
{
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must not contain whitespace',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must contain whitespace',
],
];
}

Some files were not shown because too many files have changed in this diff Show More