mirror of
https://github.com/Respect/Validation.git
synced 2024-05-16 21:26:40 +02:00
Compare commits
2 commits
ae369c4791
...
ae7a20f6d3
Author | SHA1 | Date | |
---|---|---|---|
ae7a20f6d3 | |||
66faefd695 |
|
@ -42,7 +42,7 @@ create a validator that validates if a string is equal to "Hello World".
|
|||
### Creating the rule
|
||||
|
||||
The rule itself needs to implement the `Validatable` interface but, it is
|
||||
convenient to just extend the `AbstractRule` class.
|
||||
convenient to just extend the `Simple` or `Standard` class.
|
||||
Doing that, you'll only need to declare one method: `validate($input)`.
|
||||
This method must return `true` or `false`.
|
||||
|
||||
|
@ -62,14 +62,15 @@ declare(strict_types=1);
|
|||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Rules\Core\Simple;
|
||||
|
||||
#[Template(
|
||||
'{{name}} must be a Hello World',
|
||||
'{{name}} must not be a Hello World',
|
||||
)]
|
||||
final class HelloWorld extends AbstractRule
|
||||
final class HelloWorld extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return $input === 'Hello World';
|
||||
}
|
||||
|
|
|
@ -2,25 +2,14 @@
|
|||
// Copyright (c) https://publicsuffix.org
|
||||
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception
|
||||
return [
|
||||
'AEROPORT.FR',
|
||||
'ASSO.FR',
|
||||
'AVOCAT.FR',
|
||||
'AVOUES.FR',
|
||||
'CCI.FR',
|
||||
'CHAMBAGRI.FR',
|
||||
'CHIRURGIENS-DENTISTES.FR',
|
||||
'COM.FR',
|
||||
'EXPERTS-COMPTABLES.FR',
|
||||
'GEOMETRE-EXPERT.FR',
|
||||
'GOUV.FR',
|
||||
'GRETA.FR',
|
||||
'HUISSIER-JUSTICE.FR',
|
||||
'MEDECIN.FR',
|
||||
'NOM.FR',
|
||||
'NOTAIRES.FR',
|
||||
'PHARMACIEN.FR',
|
||||
'PORT.FR',
|
||||
'PRD.FR',
|
||||
'TM.FR',
|
||||
'VETERINAIRE.FR',
|
||||
];
|
||||
|
|
|
@ -42,6 +42,7 @@ return [
|
|||
'LG.UA',
|
||||
'LT.UA',
|
||||
'LUGANSK.UA',
|
||||
'LUHANSK.UA',
|
||||
'LUTSK.UA',
|
||||
'LV.UA',
|
||||
'LVIV.UA',
|
||||
|
@ -67,11 +68,13 @@ return [
|
|||
'TERNOPIL.UA',
|
||||
'UZ.UA',
|
||||
'UZHGOROD.UA',
|
||||
'UZHHOROD.UA',
|
||||
'VINNICA.UA',
|
||||
'VINNYTSIA.UA',
|
||||
'VN.UA',
|
||||
'VOLYN.UA',
|
||||
'YALTA.UA',
|
||||
'ZAKARPATTIA.UA',
|
||||
'ZAPORIZHZHE.UA',
|
||||
'ZAPORIZHZHIA.UA',
|
||||
'ZHITOMIR.UA',
|
||||
|
|
|
@ -93,7 +93,6 @@ return [
|
|||
'K12.CO.US',
|
||||
'K12.CT.US',
|
||||
'K12.DC.US',
|
||||
'K12.DE.US',
|
||||
'K12.FL.US',
|
||||
'K12.GA.US',
|
||||
'K12.GU.US',
|
||||
|
|
|
@ -3,15 +3,81 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-no-copyleft-exception
|
||||
return [
|
||||
'AC.VN',
|
||||
'AI.VN',
|
||||
'ANGIANG.VN',
|
||||
'BACGIANG.VN',
|
||||
'BACKAN.VN',
|
||||
'BACLIEU.VN',
|
||||
'BACNINH.VN',
|
||||
'BARIA-VUNGTAU.VN',
|
||||
'BENTRE.VN',
|
||||
'BINHDINH.VN',
|
||||
'BINHDUONG.VN',
|
||||
'BINHPHUOC.VN',
|
||||
'BINHTHUAN.VN',
|
||||
'BIZ.VN',
|
||||
'CAMAU.VN',
|
||||
'CANTHO.VN',
|
||||
'CAOBANG.VN',
|
||||
'COM.VN',
|
||||
'DAKLAK.VN',
|
||||
'DAKNONG.VN',
|
||||
'DANANG.VN',
|
||||
'DIENBIEN.VN',
|
||||
'DONGNAI.VN',
|
||||
'DONGTHAP.VN',
|
||||
'EDU.VN',
|
||||
'GIALAI.VN',
|
||||
'GOV.VN',
|
||||
'HAGIANG.VN',
|
||||
'HAIDUONG.VN',
|
||||
'HAIPHONG.VN',
|
||||
'HANAM.VN',
|
||||
'HANOI.VN',
|
||||
'HATINH.VN',
|
||||
'HAUGIANG.VN',
|
||||
'HEALTH.VN',
|
||||
'HOABINH.VN',
|
||||
'HUNGYEN.VN',
|
||||
'ID.VN',
|
||||
'INFO.VN',
|
||||
'INT.VN',
|
||||
'IO.VN',
|
||||
'KHANHHOA.VN',
|
||||
'KIENGIANG.VN',
|
||||
'KONTUM.VN',
|
||||
'LAICHAU.VN',
|
||||
'LAMDONG.VN',
|
||||
'LANGSON.VN',
|
||||
'LAOCAI.VN',
|
||||
'LONGAN.VN',
|
||||
'NAMDINH.VN',
|
||||
'NAME.VN',
|
||||
'NET.VN',
|
||||
'NGHEAN.VN',
|
||||
'NINHBINH.VN',
|
||||
'NINHTHUAN.VN',
|
||||
'ORG.VN',
|
||||
'PHUTHO.VN',
|
||||
'PHUYEN.VN',
|
||||
'PRO.VN',
|
||||
'QUANGBINH.VN',
|
||||
'QUANGNAM.VN',
|
||||
'QUANGNGAI.VN',
|
||||
'QUANGNINH.VN',
|
||||
'QUANGTRI.VN',
|
||||
'SOCTRANG.VN',
|
||||
'SONLA.VN',
|
||||
'TAYNINH.VN',
|
||||
'THAIBINH.VN',
|
||||
'THAINGUYEN.VN',
|
||||
'THANHHOA.VN',
|
||||
'THANHPHOHOCHIMINH.VN',
|
||||
'THUATHIENHUE.VN',
|
||||
'TIENGIANG.VN',
|
||||
'TRAVINH.VN',
|
||||
'TUYENQUANG.VN',
|
||||
'VINHLONG.VN',
|
||||
'VINHPHUC.VN',
|
||||
'YENBAI.VN',
|
||||
];
|
||||
|
|
|
@ -3,23 +3,24 @@
|
|||
You can also create and use your own rules. To do this, you will need to create
|
||||
a rule and an exception to go with the rule.
|
||||
|
||||
To create a rule, you need to create a class that extends the AbstractRule class
|
||||
and is within the Rules `namespace`. When the rule is called the logic inside the
|
||||
validate method will be executed. Here's how the class should look:
|
||||
To create a rule, you need to create a class that implements the `Validatable` interface
|
||||
and is within the Rules `namespace`. It is convenient to just extend the `Simple` or
|
||||
`Standard` class. When the rule is called the logic inside the validate method will be
|
||||
executed. Here's how the class should look:
|
||||
|
||||
```php
|
||||
namespace My\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Rules\AbstractRule;
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Rules\Core\Simple;
|
||||
|
||||
#[Template(
|
||||
'{{name}} is something',
|
||||
'{{name}} is not something',
|
||||
)]
|
||||
final class Something extends AbstractRule
|
||||
final class Something extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
// Do something here with the $input and return a boolean value
|
||||
}
|
||||
|
|
|
@ -10,106 +10,26 @@ declare(strict_types=1);
|
|||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Message\TemplateRenderer;
|
||||
|
||||
use function count;
|
||||
use function preg_match;
|
||||
|
||||
class ValidationException extends InvalidArgumentException implements Exception
|
||||
final class ValidationException extends InvalidArgumentException implements Exception
|
||||
{
|
||||
public const MODE_DEFAULT = 'default';
|
||||
public const MODE_NEGATIVE = 'negative';
|
||||
|
||||
private string $mode = self::MODE_DEFAULT;
|
||||
|
||||
/**
|
||||
* @var array<Template>
|
||||
*/
|
||||
private readonly array $templates;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $params
|
||||
* @param array<Template> $templates
|
||||
*/
|
||||
/** @param array<string, mixed> $messages */
|
||||
public function __construct(
|
||||
private readonly mixed $input,
|
||||
private readonly string $id,
|
||||
private array $params,
|
||||
private string $template,
|
||||
array $templates,
|
||||
private readonly TemplateRenderer $formatter
|
||||
string $message,
|
||||
private readonly string $fullMessage,
|
||||
private readonly array $messages,
|
||||
) {
|
||||
if (count($templates) === 0) {
|
||||
$templates = [new Template('{{name}} must be valid', '{{name}} must not be valid')];
|
||||
}
|
||||
$this->templates = $templates;
|
||||
|
||||
parent::__construct($this->createMessage());
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
public function getFullMessage(): string
|
||||
{
|
||||
return $this->id;
|
||||
return $this->fullMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getParams(): array
|
||||
/** @return array<string, mixed> */
|
||||
public function getMessages(): array
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getParam(string $name): mixed
|
||||
{
|
||||
return $this->params[$name] ?? null;
|
||||
}
|
||||
|
||||
public function updateMode(string $mode): void
|
||||
{
|
||||
$this->mode = $mode;
|
||||
$this->message = $this->createMessage();
|
||||
}
|
||||
|
||||
public function updateTemplate(string $template): void
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->message = $this->createMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $params
|
||||
*/
|
||||
public function updateParams(array $params): void
|
||||
{
|
||||
$this->params = $params;
|
||||
$this->message = $this->createMessage();
|
||||
}
|
||||
|
||||
public function hasCustomTemplate(): bool
|
||||
{
|
||||
return preg_match('/__[a-z_]+_/', $this->template) === 0;
|
||||
}
|
||||
|
||||
private function getTemplateString(): string
|
||||
{
|
||||
foreach ($this->templates as $template) {
|
||||
if ($template->id === $this->template) {
|
||||
return $template->{$this->mode};
|
||||
}
|
||||
}
|
||||
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
private function createMessage(): string
|
||||
{
|
||||
return $this->formatter->render($this->getTemplateString(), $this->input, $this->params);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getMessage();
|
||||
return $this->messages;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
final class ValidatorException extends \Exception implements Exception
|
||||
{
|
||||
/** @param array<string, mixed> $messages */
|
||||
public function __construct(
|
||||
string $message,
|
||||
private readonly string $fullMessage,
|
||||
private readonly array $messages,
|
||||
) {
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
public function getFullMessage(): string
|
||||
{
|
||||
return $this->fullMessage;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getMessages(): array
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
}
|
|
@ -11,16 +11,12 @@ namespace Respect\Validation;
|
|||
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionObject;
|
||||
use Respect\Validation\Exceptions\ComponentException;
|
||||
use Respect\Validation\Exceptions\InvalidClassException;
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Message\Parameter\Processor;
|
||||
use Respect\Validation\Message\Parameter\Raw;
|
||||
use Respect\Validation\Message\Parameter\Stringify;
|
||||
use Respect\Validation\Message\Parameter\Trans;
|
||||
use Respect\Validation\Message\TemplateCollector;
|
||||
use Respect\Validation\Message\TemplateRenderer;
|
||||
use Respect\Validation\Transformers\DeprecatedAttribute;
|
||||
use Respect\Validation\Transformers\DeprecatedKey;
|
||||
use Respect\Validation\Transformers\DeprecatedKeyNested;
|
||||
|
@ -33,7 +29,6 @@ use Respect\Validation\Transformers\RuleSpec;
|
|||
use Respect\Validation\Transformers\Transformer;
|
||||
|
||||
use function array_merge;
|
||||
use function lcfirst;
|
||||
use function sprintf;
|
||||
use function trim;
|
||||
use function ucfirst;
|
||||
|
@ -52,8 +47,6 @@ final class Factory
|
|||
|
||||
private Processor $processor;
|
||||
|
||||
private TemplateCollector $templateCollector;
|
||||
|
||||
private Transformer $transformer;
|
||||
|
||||
private static Factory $defaultInstance;
|
||||
|
@ -62,7 +55,6 @@ final class Factory
|
|||
{
|
||||
$this->translator = static fn (string $message) => $message;
|
||||
$this->processor = new Raw(new Trans($this->translator, new Stringify()));
|
||||
$this->templateCollector = new TemplateCollector();
|
||||
$this->transformer = new DeprecatedAttribute(
|
||||
new DeprecatedKey(
|
||||
new DeprecatedKeyValue(
|
||||
|
@ -126,26 +118,6 @@ final class Factory
|
|||
return $this->createRuleSpec($this->transformer->transform(new RuleSpec($ruleName, $arguments)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $extraParams
|
||||
*/
|
||||
public function exception(Validatable $validatable, mixed $input, array $extraParams = []): ValidationException
|
||||
{
|
||||
$reflection = new ReflectionObject($validatable);
|
||||
|
||||
$params = ['input' => $input] + $extraParams + $validatable->getParams();
|
||||
$id = lcfirst($reflection->getShortName());
|
||||
if ($validatable->getName() !== null) {
|
||||
$id = $params['name'] = $validatable->getName();
|
||||
}
|
||||
$standardTemplate = $reflection->getMethod('getStandardTemplate');
|
||||
$template = $validatable->getTemplate() ?? $standardTemplate->invoke($validatable, $input);
|
||||
$templates = $this->templateCollector->extract($validatable);
|
||||
$formatter = new TemplateRenderer($this->translator, $this->processor);
|
||||
|
||||
return new ValidationException($input, $id, $params, $template, $templates, $formatter);
|
||||
}
|
||||
|
||||
public static function setDefaultInstance(self $defaultInstance): void
|
||||
{
|
||||
self::$defaultInstance = $defaultInstance;
|
||||
|
@ -170,12 +142,18 @@ final class Factory
|
|||
try {
|
||||
/** @var class-string<Validatable> $name */
|
||||
$name = $namespace . '\\' . ucfirst($ruleName);
|
||||
/** @var Validatable $rule */
|
||||
$rule = $this
|
||||
->createReflectionClass($name, Validatable::class)
|
||||
->newInstanceArgs($arguments);
|
||||
$reflection = new ReflectionClass($name);
|
||||
if (!$reflection->isSubclassOf(Validatable::class)) {
|
||||
throw new InvalidClassException(
|
||||
sprintf('"%s" must be an instance of "%s"', $name, Validatable::class)
|
||||
);
|
||||
}
|
||||
|
||||
return $rule;
|
||||
if (!$reflection->isInstantiable()) {
|
||||
throw new InvalidClassException(sprintf('"%s" must be instantiable', $name));
|
||||
}
|
||||
|
||||
return $reflection->newInstanceArgs($arguments);
|
||||
} catch (ReflectionException) {
|
||||
continue;
|
||||
}
|
||||
|
@ -183,24 +161,4 @@ final class Factory
|
|||
|
||||
throw new ComponentException(sprintf('"%s" is not a valid rule name', $ruleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $name
|
||||
* @param class-string $parentName
|
||||
*
|
||||
* @return ReflectionClass<ValidationException|Validatable|object>
|
||||
*/
|
||||
private function createReflectionClass(string $name, string $parentName): ReflectionClass
|
||||
{
|
||||
$reflection = new ReflectionClass($name);
|
||||
if (!$reflection->isSubclassOf($parentName) && $parentName !== $name) {
|
||||
throw new InvalidClassException(sprintf('"%s" must be an instance of "%s"', $name, $parentName));
|
||||
}
|
||||
|
||||
if (!$reflection->isInstantiable()) {
|
||||
throw new InvalidClassException(sprintf('"%s" must be instantiable', $name));
|
||||
}
|
||||
|
||||
return $reflection;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,62 +9,31 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Helpers;
|
||||
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Message\Parameter\Stringify;
|
||||
use Respect\Validation\Message\TemplateRenderer;
|
||||
|
||||
use function sprintf;
|
||||
use function trigger_error;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
trait DeprecatedValidatableMethods
|
||||
{
|
||||
/**
|
||||
* @deprecated Calling `validate()` directly is deprecated, please use the `Validator::isValid()` class instead.
|
||||
*/
|
||||
public function validate(mixed $input): bool
|
||||
{
|
||||
$this->triggerDeprecation(__METHOD__);
|
||||
|
||||
return false;
|
||||
return $this->evaluate($input)->isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Calling `assert()` directly is deprecated, please use the `Validator::assert()` instead.
|
||||
*/
|
||||
public function assert(mixed $input): void
|
||||
{
|
||||
$this->triggerDeprecation(__FUNCTION__);
|
||||
Validator::create($this)->assert($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Calling `check()` directly is deprecated, please use the `Validator::assert()` instead.
|
||||
*/
|
||||
public function check(mixed $input): void
|
||||
{
|
||||
$this->triggerDeprecation(__FUNCTION__);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $extraParameters */
|
||||
public function reportError(mixed $input, array $extraParameters = []): ValidationException
|
||||
{
|
||||
$this->triggerDeprecation(__FUNCTION__);
|
||||
|
||||
return new ValidationException(
|
||||
input: $input,
|
||||
id: 'id',
|
||||
params: $extraParameters,
|
||||
template: 'template',
|
||||
templates: [],
|
||||
formatter: new TemplateRenderer(static fn (string $message) => $message, new Stringify()),
|
||||
);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getParams(): array
|
||||
{
|
||||
$this->triggerDeprecation(__FUNCTION__);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function triggerDeprecation(string $function): void
|
||||
{
|
||||
trigger_error(
|
||||
sprintf('The "%s" method is deprecated, please use the "Validator" class instead.', $function),
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
Validator::create($this)->assert($input);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use Respect\Validation\Exceptions\ComponentException;
|
|||
use Respect\Validation\Message\Parameter\Processor;
|
||||
use Respect\Validation\Mode;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Rule;
|
||||
use Respect\Validation\Validatable;
|
||||
use Throwable;
|
||||
|
||||
use function call_user_func;
|
||||
|
@ -71,7 +71,7 @@ final class StandardRenderer implements Renderer
|
|||
}
|
||||
|
||||
/** @return array<Template> */
|
||||
private function extractTemplates(Rule $rule): array
|
||||
private function extractTemplates(Validatable $rule): array
|
||||
{
|
||||
if (!isset($this->templates[$rule::class])) {
|
||||
$reflection = new ReflectionClass($rule);
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Message;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
final class TemplateCollector
|
||||
{
|
||||
/** @var array<string, array<Template>> */
|
||||
private array $templates = [];
|
||||
|
||||
/**
|
||||
* @return array<Template>
|
||||
*/
|
||||
public function extract(object $object): array
|
||||
{
|
||||
if (!isset($this->templates[$object::class])) {
|
||||
$reflection = new ReflectionClass($object);
|
||||
foreach ($reflection->getAttributes(Template::class) as $attribute) {
|
||||
$this->templates[$object::class][] = $attribute->newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->templates[$object::class] ?? [];
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Message;
|
||||
|
||||
use Respect\Validation\Exceptions\ComponentException;
|
||||
use Respect\Validation\Message\Parameter\Processor;
|
||||
use Throwable;
|
||||
|
||||
use function call_user_func;
|
||||
use function preg_replace_callback;
|
||||
use function sprintf;
|
||||
|
||||
final class TemplateRenderer
|
||||
{
|
||||
/** @var callable */
|
||||
private $translator;
|
||||
|
||||
public function __construct(
|
||||
callable $translator,
|
||||
private readonly Processor $processor
|
||||
) {
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $parameters
|
||||
*/
|
||||
public function render(string $template, mixed $input, array $parameters): string
|
||||
{
|
||||
$parameters['name'] ??= $this->processor->process('input', $input);
|
||||
|
||||
return (string) preg_replace_callback(
|
||||
'/{{(\w+)(\|([^}]+))?}}/',
|
||||
function (array $matches) use ($parameters) {
|
||||
if (!isset($parameters[$matches[1]])) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
return $this->processor->process($matches[1], $parameters[$matches[1]], $matches[3] ?? null);
|
||||
},
|
||||
$this->translate($template)
|
||||
);
|
||||
}
|
||||
|
||||
private function translate(mixed $message): string
|
||||
{
|
||||
try {
|
||||
return call_user_func($this->translator, (string) $message);
|
||||
} catch (Throwable $throwable) {
|
||||
throw new ComponentException(sprintf('Failed to translate "%s"', $message), 0, $throwable);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,9 +32,9 @@ final class Result
|
|||
public function __construct(
|
||||
public readonly bool $isValid,
|
||||
public readonly mixed $input,
|
||||
public readonly Rule $rule,
|
||||
public readonly Validatable $rule,
|
||||
public readonly array $parameters = [],
|
||||
string $template = Rule::TEMPLATE_STANDARD,
|
||||
string $template = Validatable::TEMPLATE_STANDARD,
|
||||
public readonly Mode $mode = Mode::DEFAULT,
|
||||
?string $name = null,
|
||||
?string $id = null,
|
||||
|
@ -50,9 +50,9 @@ final class Result
|
|||
/** @param array<string, mixed> $parameters */
|
||||
public static function failed(
|
||||
mixed $input,
|
||||
Rule $rule,
|
||||
Validatable $rule,
|
||||
array $parameters = [],
|
||||
string $template = Rule::TEMPLATE_STANDARD
|
||||
string $template = Validatable::TEMPLATE_STANDARD
|
||||
): self {
|
||||
return new self(false, $input, $rule, $parameters, $template);
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ final class Result
|
|||
/** @param array<string, mixed> $parameters */
|
||||
public static function passed(
|
||||
mixed $input,
|
||||
Rule $rule,
|
||||
Validatable $rule,
|
||||
array $parameters = [],
|
||||
string $template = Rule::TEMPLATE_STANDARD
|
||||
string $template = Validatable::TEMPLATE_STANDARD
|
||||
): self {
|
||||
return new self(true, $input, $rule, $parameters, $template);
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation;
|
||||
|
||||
interface Rule
|
||||
{
|
||||
public const TEMPLATE_STANDARD = '__standard__';
|
||||
|
||||
public function evaluate(mixed $input): Result;
|
||||
|
||||
public function getName(): ?string;
|
||||
|
||||
public function setName(string $name): static;
|
||||
|
||||
public function getTemplate(): ?string;
|
||||
|
||||
public function setTemplate(string $template): static;
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Factory;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Validatable;
|
||||
|
||||
abstract class AbstractRule implements Validatable
|
||||
{
|
||||
protected ?string $template = null;
|
||||
|
||||
private ?string $name = null;
|
||||
|
||||
public function assert(mixed $input): void
|
||||
{
|
||||
if ($this->validate($input)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw $this->reportError($input);
|
||||
}
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
return new Result(
|
||||
$this->validate($input),
|
||||
$input,
|
||||
$this,
|
||||
$this->getParams(),
|
||||
$this->getStandardTemplate($input)
|
||||
);
|
||||
}
|
||||
|
||||
public function check(mixed $input): void
|
||||
{
|
||||
$this->assert($input);
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $extraParameters
|
||||
*/
|
||||
public function reportError(mixed $input, array $extraParameters = []): ValidationException
|
||||
{
|
||||
return Factory::getDefaultInstance()->exception($this, $input, $extraParameters);
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTemplate(string $template): static
|
||||
{
|
||||
$this->template = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTemplate(): ?string
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getParams(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getStandardTemplate(mixed $input): string
|
||||
{
|
||||
return self::TEMPLATE_STANDARD;
|
||||
}
|
||||
|
||||
public function __invoke(mixed $input): bool
|
||||
{
|
||||
return $this->validate($input);
|
||||
}
|
||||
}
|
|
@ -11,8 +11,8 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Rule;
|
||||
use Respect\Validation\Rules\Core\Composite;
|
||||
use Respect\Validation\Validatable;
|
||||
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
|
@ -36,7 +36,7 @@ final class AllOf extends Composite
|
|||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$children = array_map(static fn (Validatable $rule) => $rule->evaluate($input), $this->rules);
|
||||
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry && $result->isValid, true);
|
||||
$failed = array_filter($children, static fn (Result $result): bool => !$result->isValid);
|
||||
$template = self::TEMPLATE_SOME;
|
||||
|
|
|
@ -26,7 +26,7 @@ final class AlwaysInvalid extends Simple
|
|||
{
|
||||
public const TEMPLATE_SIMPLE = '__simple__';
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use Respect\Validation\Rules\Core\Simple;
|
|||
)]
|
||||
final class AlwaysValid extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Rule;
|
||||
use Respect\Validation\Rules\Core\Composite;
|
||||
use Respect\Validation\Validatable;
|
||||
|
||||
use function array_map;
|
||||
use function array_reduce;
|
||||
|
@ -25,7 +25,7 @@ final class AnyOf extends Composite
|
|||
{
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$children = array_map(static fn (Validatable $rule) => $rule->evaluate($input), $this->rules);
|
||||
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry || $result->isValid, false);
|
||||
|
||||
return (new Result($valid, $input, $this))->withChildren(...$children);
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_array;
|
|||
)]
|
||||
final class ArrayType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_array($input);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use function is_array;
|
|||
)]
|
||||
final class ArrayVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_array($input) || $input instanceof ArrayAccess || $input instanceof SimpleXMLElement;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use function preg_match;
|
|||
)]
|
||||
final class Base64 extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_bool;
|
|||
)]
|
||||
final class BoolType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_bool($input);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ use const FILTER_VALIDATE_BOOLEAN;
|
|||
)]
|
||||
final class BoolVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_bool(filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ use function strval;
|
|||
)]
|
||||
final class Bsn extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_callable;
|
|||
)]
|
||||
final class CallableType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_callable($input);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ final class Callback extends Simple
|
|||
$this->arguments = $arguments;
|
||||
}
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return (bool) call_user_func_array($this->callback, $this->getArguments($input));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use function preg_replace;
|
|||
)]
|
||||
final class Cnh extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -25,7 +25,7 @@ use function str_split;
|
|||
)]
|
||||
final class Cnpj extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -13,8 +13,10 @@ use Respect\Validation\Result;
|
|||
|
||||
abstract class Simple extends Standard
|
||||
{
|
||||
abstract protected function isValid(mixed $input): bool;
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
return new Result($this->validate($input), $input, $this);
|
||||
return new Result($this->isValid($input), $input, $this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use function is_array;
|
|||
)]
|
||||
final class Countable extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_array($input) || $input instanceof CountableInterface;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ use function preg_replace;
|
|||
)]
|
||||
final class Cpf extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
// Code ported from jsfromhell.com
|
||||
$c = preg_replace('/\D/', '', $input);
|
||||
|
|
|
@ -23,7 +23,7 @@ use function is_scalar;
|
|||
)]
|
||||
final class Directory extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $input->isDir();
|
||||
|
|
|
@ -37,7 +37,7 @@ final class Email extends Simple
|
|||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -22,7 +22,7 @@ use const FILTER_VALIDATE_INT;
|
|||
)]
|
||||
final class Even extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (filter_var($input, FILTER_VALIDATE_INT) === false) {
|
||||
return false;
|
||||
|
|
|
@ -22,7 +22,7 @@ use function is_scalar;
|
|||
)]
|
||||
final class Executable extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $input->isExecutable();
|
||||
|
|
|
@ -22,7 +22,7 @@ use function is_string;
|
|||
)]
|
||||
final class Exists extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
$input = $input->getPathname();
|
||||
|
|
|
@ -23,7 +23,7 @@ use const FILTER_VALIDATE_BOOLEAN;
|
|||
)]
|
||||
final class FalseVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === false;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_numeric;
|
|||
)]
|
||||
final class Fibonacci extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_numeric($input)) {
|
||||
return false;
|
||||
|
|
|
@ -22,7 +22,7 @@ use function is_string;
|
|||
)]
|
||||
final class File extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $input->isFile();
|
||||
|
|
|
@ -21,7 +21,7 @@ use function is_numeric;
|
|||
)]
|
||||
final class Finite extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_numeric($input) && is_finite((float) $input);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_float;
|
|||
)]
|
||||
final class FloatType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_float($input);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ use const FILTER_VALIDATE_FLOAT;
|
|||
)]
|
||||
final class FloatVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_float(filter_var($input, FILTER_VALIDATE_FLOAT));
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ final class Hetu extends Simple
|
|||
{
|
||||
use CanValidateDateTime;
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -103,7 +103,7 @@ final class Iban extends Simple
|
|||
'VG' => 24,
|
||||
];
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -33,10 +33,10 @@ final class Image extends Simple
|
|||
$this->fileInfo = $fileInfo ?: new finfo(FILEINFO_MIME_TYPE);
|
||||
}
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $this->validate($input->getPathname());
|
||||
return $this->isValid($input->getPathname());
|
||||
}
|
||||
|
||||
if (!is_string($input)) {
|
||||
|
|
|
@ -24,10 +24,7 @@ final class Imei extends Simple
|
|||
{
|
||||
private const IMEI_SIZE = 15;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
|
||||
*/
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
@ -38,6 +35,6 @@ final class Imei extends Simple
|
|||
return false;
|
||||
}
|
||||
|
||||
return (new Luhn())->validate($numbers);
|
||||
return (new Luhn())->isValid($numbers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use function is_numeric;
|
|||
)]
|
||||
final class Infinite extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_numeric($input) && is_infinite((float) $input);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_int;
|
|||
)]
|
||||
final class IntType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_int($input);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use function preg_match;
|
|||
)]
|
||||
final class IntVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (is_int($input)) {
|
||||
return true;
|
||||
|
|
|
@ -32,7 +32,7 @@ final class Isbn extends Simple
|
|||
'(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$',
|
||||
];
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_iterable;
|
|||
)]
|
||||
final class IterableType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_iterable($input);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ final class IterableVal extends Simple
|
|||
{
|
||||
use CanValidateIterable;
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return $this->isIterable($input);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ use const JSON_ERROR_NONE;
|
|||
)]
|
||||
final class Json extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input) || $input === '') {
|
||||
return false;
|
||||
|
|
|
@ -27,14 +27,14 @@ final class LeapDate extends Simple
|
|||
) {
|
||||
}
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof DateTimeInterface) {
|
||||
return $input->format('m-d') === '02-29';
|
||||
}
|
||||
|
||||
if (is_scalar($input)) {
|
||||
return $this->validate(DateTimeImmutable::createFromFormat($this->format, (string) $input));
|
||||
return $this->isValid(DateTimeImmutable::createFromFormat($this->format, (string) $input));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -25,7 +25,7 @@ use function strtotime;
|
|||
)]
|
||||
final class LeapYear extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (is_numeric($input)) {
|
||||
$date = strtotime(sprintf('%d-02-29', (int) $input));
|
||||
|
@ -34,11 +34,11 @@ final class LeapYear extends Simple
|
|||
}
|
||||
|
||||
if (is_scalar($input)) {
|
||||
return $this->validate((int) date('Y', (int) strtotime((string) $input)));
|
||||
return $this->isValid((int) date('Y', (int) strtotime((string) $input)));
|
||||
}
|
||||
|
||||
if ($input instanceof DateTimeInterface) {
|
||||
return $this->validate($input->format('Y'));
|
||||
return $this->isValid($input->format('Y'));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -21,7 +21,7 @@ use function mb_strtolower;
|
|||
)]
|
||||
final class Lowercase extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -25,19 +25,14 @@ use function str_split;
|
|||
)]
|
||||
final class Luhn extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!(new Digit())->evaluate($input)->isValid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isValid((string) $input);
|
||||
}
|
||||
|
||||
private function isValid(string $input): bool
|
||||
{
|
||||
$sum = 0;
|
||||
$digits = array_map('intval', str_split($input));
|
||||
$digits = array_map('intval', str_split((string) $input));
|
||||
$numDigits = count($digits);
|
||||
$parity = $numDigits % 2;
|
||||
for ($i = 0; $i < $numDigits; ++$i) {
|
||||
|
|
|
@ -21,7 +21,7 @@ use function preg_match;
|
|||
)]
|
||||
final class MacAddress extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_numeric;
|
|||
)]
|
||||
final class Negative extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_numeric($input)) {
|
||||
return false;
|
||||
|
|
|
@ -26,7 +26,7 @@ use function str_split;
|
|||
)]
|
||||
final class NfeAccessKey extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (mb_strlen($input) !== 44) {
|
||||
return false;
|
||||
|
|
|
@ -29,7 +29,7 @@ use function str_split;
|
|||
)]
|
||||
final class Nif extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -26,7 +26,7 @@ use function str_split;
|
|||
)]
|
||||
final class Nip extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -22,7 +22,7 @@ use function preg_match;
|
|||
)]
|
||||
final class NoWhitespace extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (is_null($input)) {
|
||||
return true;
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Rule;
|
||||
use Respect\Validation\Rules\Core\Composite;
|
||||
use Respect\Validation\Validatable;
|
||||
|
||||
use function array_map;
|
||||
use function array_reduce;
|
||||
|
@ -25,7 +25,10 @@ final class NoneOf extends Composite
|
|||
{
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input)->withInvertedMode(), $this->rules);
|
||||
$children = array_map(
|
||||
static fn (Validatable $rule) => $rule->evaluate($input)->withInvertedMode(),
|
||||
$this->rules
|
||||
);
|
||||
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry && $result->isValid, true);
|
||||
|
||||
return (new Result($valid, $input, $this))->withChildren(...$children);
|
||||
|
|
|
@ -194,7 +194,7 @@ final class NotEmoji extends Simple
|
|||
'\x{3299}',
|
||||
];
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_null;
|
|||
)]
|
||||
final class NullType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_null($input);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use function is_numeric;
|
|||
)]
|
||||
final class Number extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_numeric($input)) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_numeric;
|
|||
)]
|
||||
final class NumericVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_numeric($input);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_object;
|
|||
)]
|
||||
final class ObjectType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_object($input);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ use const FILTER_VALIDATE_INT;
|
|||
)]
|
||||
final class Odd extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_numeric($input)) {
|
||||
return false;
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Rule;
|
||||
use Respect\Validation\Rules\Core\Composite;
|
||||
use Respect\Validation\Validatable;
|
||||
|
||||
use function array_map;
|
||||
use function array_reduce;
|
||||
|
@ -25,7 +25,7 @@ final class OneOf extends Composite
|
|||
{
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$children = array_map(static fn (Validatable $rule) => $rule->evaluate($input), $this->rules);
|
||||
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry xor $result->isValid, false);
|
||||
|
||||
return (new Result($valid, $input, $this))->withChildren(...$children);
|
||||
|
|
|
@ -22,7 +22,7 @@ use function sqrt;
|
|||
)]
|
||||
final class PerfectSquare extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_numeric($input) && floor(sqrt((float) $input)) == sqrt((float) $input);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use function preg_match;
|
|||
)]
|
||||
final class Pesel extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -21,7 +21,7 @@ use function preg_match;
|
|||
)]
|
||||
final class PhpLabel extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_string($input) && preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $input);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ use function preg_replace;
|
|||
)]
|
||||
final class Pis extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -30,7 +30,7 @@ final class PolishIdCard extends Simple
|
|||
private const ASCII_CODE_9 = 57;
|
||||
private const ASCII_CODE_A = 65;
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -31,7 +31,7 @@ use function strlen;
|
|||
)]
|
||||
final class PortugueseNif extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
// Validate format and length
|
||||
if (!is_string($input)) {
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_numeric;
|
|||
)]
|
||||
final class Positive extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_numeric($input)) {
|
||||
return false;
|
||||
|
|
|
@ -22,7 +22,7 @@ use function sqrt;
|
|||
)]
|
||||
final class PrimeNumber extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_numeric($input) || $input <= 1) {
|
||||
return false;
|
||||
|
|
|
@ -28,7 +28,7 @@ final class PublicDomainSuffix extends Simple
|
|||
{
|
||||
use CanValidateUndefined;
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -23,7 +23,7 @@ use function is_string;
|
|||
)]
|
||||
final class Readable extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $input->isReadable();
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_resource;
|
|||
)]
|
||||
final class ResourceType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_resource($input);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_scalar;
|
|||
)]
|
||||
final class ScalarVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_scalar($input);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use function preg_match;
|
|||
)]
|
||||
final class Slug extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input) || mb_strstr($input, '--')) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ use function is_string;
|
|||
)]
|
||||
final class StringType extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_string($input);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use function method_exists;
|
|||
)]
|
||||
final class StringVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return is_scalar($input) || (is_object($input) && method_exists($input, '__toString'));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use function is_string;
|
|||
)]
|
||||
final class SymbolicLink extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $input->isLink();
|
||||
|
|
|
@ -22,7 +22,9 @@ use function mb_strtoupper;
|
|||
)]
|
||||
final class Tld extends Simple
|
||||
{
|
||||
// List extracted from https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
||||
/**
|
||||
* List extracted from https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
||||
*/
|
||||
private const TLD_LIST = [
|
||||
'AAA', 'AARP', 'ABB', 'ABBOTT', 'ABBVIE', 'ABC', 'ABLE', 'ABOGADO',
|
||||
'ABUDHABI', 'AC', 'ACADEMY', 'ACCENTURE', 'ACCOUNTANT', 'ACCOUNTANTS',
|
||||
|
@ -37,34 +39,33 @@ final class Tld extends Simple
|
|||
'ASSOCIATES', 'AT', 'ATHLETA', 'ATTORNEY', 'AU', 'AUCTION', 'AUDI',
|
||||
'AUDIBLE', 'AUDIO', 'AUSPOST', 'AUTHOR', 'AUTO', 'AUTOS', 'AVIANCA',
|
||||
'AW', 'AWS', 'AX', 'AXA', 'AZ', 'AZURE', 'BA', 'BABY', 'BAIDU',
|
||||
'BANAMEX', 'BANANAREPUBLIC', 'BAND', 'BANK', 'BAR', 'BARCELONA',
|
||||
'BARCLAYCARD', 'BARCLAYS', 'BAREFOOT', 'BARGAINS', 'BASEBALL',
|
||||
'BASKETBALL', 'BAUHAUS', 'BAYERN', 'BB', 'BBC', 'BBT', 'BBVA', 'BCG',
|
||||
'BCN', 'BD', 'BE', 'BEATS', 'BEAUTY', 'BEER', 'BENTLEY', 'BERLIN',
|
||||
'BEST', 'BESTBUY', 'BET', 'BF', 'BG', 'BH', 'BHARTI', 'BI', 'BIBLE',
|
||||
'BID', 'BIKE', 'BING', 'BINGO', 'BIO', 'BIZ', 'BJ', 'BLACK',
|
||||
'BLACKFRIDAY', 'BLOCKBUSTER', 'BLOG', 'BLOOMBERG', 'BLUE', 'BM', 'BMS',
|
||||
'BMW', 'BN', 'BNPPARIBAS', 'BO', 'BOATS', 'BOEHRINGER', 'BOFA', 'BOM',
|
||||
'BOND', 'BOO', 'BOOK', 'BOOKING', 'BOSCH', 'BOSTIK', 'BOSTON', 'BOT',
|
||||
'BANAMEX', 'BAND', 'BANK', 'BAR', 'BARCELONA', 'BARCLAYCARD',
|
||||
'BARCLAYS', 'BAREFOOT', 'BARGAINS', 'BASEBALL', 'BASKETBALL',
|
||||
'BAUHAUS', 'BAYERN', 'BB', 'BBC', 'BBT', 'BBVA', 'BCG', 'BCN', 'BD',
|
||||
'BE', 'BEATS', 'BEAUTY', 'BEER', 'BENTLEY', 'BERLIN', 'BEST',
|
||||
'BESTBUY', 'BET', 'BF', 'BG', 'BH', 'BHARTI', 'BI', 'BIBLE', 'BID',
|
||||
'BIKE', 'BING', 'BINGO', 'BIO', 'BIZ', 'BJ', 'BLACK', 'BLACKFRIDAY',
|
||||
'BLOCKBUSTER', 'BLOG', 'BLOOMBERG', 'BLUE', 'BM', 'BMS', 'BMW', 'BN',
|
||||
'BNPPARIBAS', 'BO', 'BOATS', 'BOEHRINGER', 'BOFA', 'BOM', 'BOND',
|
||||
'BOO', 'BOOK', 'BOOKING', 'BOSCH', 'BOSTIK', 'BOSTON', 'BOT',
|
||||
'BOUTIQUE', 'BOX', 'BR', 'BRADESCO', 'BRIDGESTONE', 'BROADWAY',
|
||||
'BROKER', 'BROTHER', 'BRUSSELS', 'BS', 'BT', 'BUILD', 'BUILDERS',
|
||||
'BUSINESS', 'BUY', 'BUZZ', 'BV', 'BW', 'BY', 'BZ', 'BZH', 'CA', 'CAB',
|
||||
'CAFE', 'CAL', 'CALL', 'CALVINKLEIN', 'CAM', 'CAMERA', 'CAMP', 'CANON',
|
||||
'CAPETOWN', 'CAPITAL', 'CAPITALONE', 'CAR', 'CARAVAN', 'CARDS', 'CARE',
|
||||
'CAREER', 'CAREERS', 'CARS', 'CASA', 'CASE', 'CASH', 'CASINO', 'CAT',
|
||||
'CATERING', 'CATHOLIC', 'CBA', 'CBN', 'CBRE', 'CBS', 'CC', 'CD',
|
||||
'CENTER', 'CEO', 'CERN', 'CF', 'CFA', 'CFD', 'CG', 'CH', 'CHANEL',
|
||||
'CHANNEL', 'CHARITY', 'CHASE', 'CHAT', 'CHEAP', 'CHINTAI', 'CHRISTMAS',
|
||||
'CHROME', 'CHURCH', 'CI', 'CIPRIANI', 'CIRCLE', 'CISCO', 'CITADEL',
|
||||
'CITI', 'CITIC', 'CITY', 'CITYEATS', 'CK', 'CL', 'CLAIMS', 'CLEANING',
|
||||
'CLICK', 'CLINIC', 'CLINIQUE', 'CLOTHING', 'CLOUD', 'CLUB', 'CLUBMED',
|
||||
'CM', 'CN', 'CO', 'COACH', 'CODES', 'COFFEE', 'COLLEGE', 'COLOGNE',
|
||||
'COM', 'COMCAST', 'COMMBANK', 'COMMUNITY', 'COMPANY', 'COMPARE',
|
||||
'COMPUTER', 'COMSEC', 'CONDOS', 'CONSTRUCTION', 'CONSULTING',
|
||||
'CONTACT', 'CONTRACTORS', 'COOKING', 'COOKINGCHANNEL', 'COOL', 'COOP',
|
||||
'CORSICA', 'COUNTRY', 'COUPON', 'COUPONS', 'COURSES', 'CPA', 'CR',
|
||||
'CREDIT', 'CREDITCARD', 'CREDITUNION', 'CRICKET', 'CROWN', 'CRS',
|
||||
'CRUISE', 'CRUISES', 'CU', 'CUISINELLA', 'CV', 'CW', 'CX', 'CY',
|
||||
'CATERING', 'CATHOLIC', 'CBA', 'CBN', 'CBRE', 'CC', 'CD', 'CENTER',
|
||||
'CEO', 'CERN', 'CF', 'CFA', 'CFD', 'CG', 'CH', 'CHANEL', 'CHANNEL',
|
||||
'CHARITY', 'CHASE', 'CHAT', 'CHEAP', 'CHINTAI', 'CHRISTMAS', 'CHROME',
|
||||
'CHURCH', 'CI', 'CIPRIANI', 'CIRCLE', 'CISCO', 'CITADEL', 'CITI',
|
||||
'CITIC', 'CITY', 'CK', 'CL', 'CLAIMS', 'CLEANING', 'CLICK', 'CLINIC',
|
||||
'CLINIQUE', 'CLOTHING', 'CLOUD', 'CLUB', 'CLUBMED', 'CM', 'CN', 'CO',
|
||||
'COACH', 'CODES', 'COFFEE', 'COLLEGE', 'COLOGNE', 'COM', 'COMMBANK',
|
||||
'COMMUNITY', 'COMPANY', 'COMPARE', 'COMPUTER', 'COMSEC', 'CONDOS',
|
||||
'CONSTRUCTION', 'CONSULTING', 'CONTACT', 'CONTRACTORS', 'COOKING',
|
||||
'COOL', 'COOP', 'CORSICA', 'COUNTRY', 'COUPON', 'COUPONS', 'COURSES',
|
||||
'CPA', 'CR', 'CREDIT', 'CREDITCARD', 'CREDITUNION', 'CRICKET', 'CROWN',
|
||||
'CRS', 'CRUISE', 'CRUISES', 'CU', 'CUISINELLA', 'CV', 'CW', 'CX', 'CY',
|
||||
'CYMRU', 'CYOU', 'CZ', 'DABUR', 'DAD', 'DANCE', 'DATA', 'DATE',
|
||||
'DATING', 'DATSUN', 'DAY', 'DCLK', 'DDS', 'DE', 'DEAL', 'DEALER',
|
||||
'DEALS', 'DEGREE', 'DELIVERY', 'DELL', 'DELOITTE', 'DELTA', 'DEMOCRAT',
|
||||
|
@ -75,31 +76,30 @@ final class Tld extends Simple
|
|||
'DUPONT', 'DURBAN', 'DVAG', 'DVR', 'DZ', 'EARTH', 'EAT', 'EC', 'ECO',
|
||||
'EDEKA', 'EDU', 'EDUCATION', 'EE', 'EG', 'EMAIL', 'EMERCK', 'ENERGY',
|
||||
'ENGINEER', 'ENGINEERING', 'ENTERPRISES', 'EPSON', 'EQUIPMENT', 'ER',
|
||||
'ERICSSON', 'ERNI', 'ES', 'ESQ', 'ESTATE', 'ET', 'ETISALAT', 'EU',
|
||||
'EUROVISION', 'EUS', 'EVENTS', 'EXCHANGE', 'EXPERT', 'EXPOSED',
|
||||
'EXPRESS', 'EXTRASPACE', 'FAGE', 'FAIL', 'FAIRWINDS', 'FAITH',
|
||||
'FAMILY', 'FAN', 'FANS', 'FARM', 'FARMERS', 'FASHION', 'FAST', 'FEDEX',
|
||||
'FEEDBACK', 'FERRARI', 'FERRERO', 'FI', 'FIDELITY', 'FIDO', 'FILM',
|
||||
'FINAL', 'FINANCE', 'FINANCIAL', 'FIRE', 'FIRESTONE', 'FIRMDALE',
|
||||
'FISH', 'FISHING', 'FIT', 'FITNESS', 'FJ', 'FK', 'FLICKR', 'FLIGHTS',
|
||||
'FLIR', 'FLORIST', 'FLOWERS', 'FLY', 'FM', 'FO', 'FOO', 'FOOD',
|
||||
'FOODNETWORK', 'FOOTBALL', 'FORD', 'FOREX', 'FORSALE', 'FORUM',
|
||||
'FOUNDATION', 'FOX', 'FR', 'FREE', 'FRESENIUS', 'FRL', 'FROGANS',
|
||||
'FRONTDOOR', 'FRONTIER', 'FTR', 'FUJITSU', 'FUN', 'FUND', 'FURNITURE',
|
||||
'FUTBOL', 'FYI', 'GA', 'GAL', 'GALLERY', 'GALLO', 'GALLUP', 'GAME',
|
||||
'GAMES', 'GAP', 'GARDEN', 'GAY', 'GB', 'GBIZ', 'GD', 'GDN', 'GE',
|
||||
'GEA', 'GENT', 'GENTING', 'GEORGE', 'GF', 'GG', 'GGEE', 'GH', 'GI',
|
||||
'GIFT', 'GIFTS', 'GIVES', 'GIVING', 'GL', 'GLASS', 'GLE', 'GLOBAL',
|
||||
'GLOBO', 'GM', 'GMAIL', 'GMBH', 'GMO', 'GMX', 'GN', 'GODADDY', 'GOLD',
|
||||
'GOLDPOINT', 'GOLF', 'GOO', 'GOODYEAR', 'GOOG', 'GOOGLE', 'GOP', 'GOT',
|
||||
'GOV', 'GP', 'GQ', 'GR', 'GRAINGER', 'GRAPHICS', 'GRATIS', 'GREEN',
|
||||
'GRIPE', 'GROCERY', 'GROUP', 'GS', 'GT', 'GU', 'GUARDIAN', 'GUCCI',
|
||||
'GUGE', 'GUIDE', 'GUITARS', 'GURU', 'GW', 'GY', 'HAIR', 'HAMBURG',
|
||||
'HANGOUT', 'HAUS', 'HBO', 'HDFC', 'HDFCBANK', 'HEALTH', 'HEALTHCARE',
|
||||
'HELP', 'HELSINKI', 'HERE', 'HERMES', 'HGTV', 'HIPHOP', 'HISAMITSU',
|
||||
'HITACHI', 'HIV', 'HK', 'HKT', 'HM', 'HN', 'HOCKEY', 'HOLDINGS',
|
||||
'HOLIDAY', 'HOMEDEPOT', 'HOMEGOODS', 'HOMES', 'HOMESENSE', 'HONDA',
|
||||
'HORSE', 'HOSPITAL', 'HOST', 'HOSTING', 'HOT', 'HOTELES', 'HOTELS',
|
||||
'ERICSSON', 'ERNI', 'ES', 'ESQ', 'ESTATE', 'ET', 'EU', 'EUROVISION',
|
||||
'EUS', 'EVENTS', 'EXCHANGE', 'EXPERT', 'EXPOSED', 'EXPRESS',
|
||||
'EXTRASPACE', 'FAGE', 'FAIL', 'FAIRWINDS', 'FAITH', 'FAMILY', 'FAN',
|
||||
'FANS', 'FARM', 'FARMERS', 'FASHION', 'FAST', 'FEDEX', 'FEEDBACK',
|
||||
'FERRARI', 'FERRERO', 'FI', 'FIDELITY', 'FIDO', 'FILM', 'FINAL',
|
||||
'FINANCE', 'FINANCIAL', 'FIRE', 'FIRESTONE', 'FIRMDALE', 'FISH',
|
||||
'FISHING', 'FIT', 'FITNESS', 'FJ', 'FK', 'FLICKR', 'FLIGHTS', 'FLIR',
|
||||
'FLORIST', 'FLOWERS', 'FLY', 'FM', 'FO', 'FOO', 'FOOD', 'FOOTBALL',
|
||||
'FORD', 'FOREX', 'FORSALE', 'FORUM', 'FOUNDATION', 'FOX', 'FR', 'FREE',
|
||||
'FRESENIUS', 'FRL', 'FROGANS', 'FRONTIER', 'FTR', 'FUJITSU', 'FUN',
|
||||
'FUND', 'FURNITURE', 'FUTBOL', 'FYI', 'GA', 'GAL', 'GALLERY', 'GALLO',
|
||||
'GALLUP', 'GAME', 'GAMES', 'GAP', 'GARDEN', 'GAY', 'GB', 'GBIZ', 'GD',
|
||||
'GDN', 'GE', 'GEA', 'GENT', 'GENTING', 'GEORGE', 'GF', 'GG', 'GGEE',
|
||||
'GH', 'GI', 'GIFT', 'GIFTS', 'GIVES', 'GIVING', 'GL', 'GLASS', 'GLE',
|
||||
'GLOBAL', 'GLOBO', 'GM', 'GMAIL', 'GMBH', 'GMO', 'GMX', 'GN',
|
||||
'GODADDY', 'GOLD', 'GOLDPOINT', 'GOLF', 'GOO', 'GOODYEAR', 'GOOG',
|
||||
'GOOGLE', 'GOP', 'GOT', 'GOV', 'GP', 'GQ', 'GR', 'GRAINGER',
|
||||
'GRAPHICS', 'GRATIS', 'GREEN', 'GRIPE', 'GROCERY', 'GROUP', 'GS', 'GT',
|
||||
'GU', 'GUCCI', 'GUGE', 'GUIDE', 'GUITARS', 'GURU', 'GW', 'GY', 'HAIR',
|
||||
'HAMBURG', 'HANGOUT', 'HAUS', 'HBO', 'HDFC', 'HDFCBANK', 'HEALTH',
|
||||
'HEALTHCARE', 'HELP', 'HELSINKI', 'HERE', 'HERMES', 'HIPHOP',
|
||||
'HISAMITSU', 'HITACHI', 'HIV', 'HK', 'HKT', 'HM', 'HN', 'HOCKEY',
|
||||
'HOLDINGS', 'HOLIDAY', 'HOMEDEPOT', 'HOMEGOODS', 'HOMES', 'HOMESENSE',
|
||||
'HONDA', 'HORSE', 'HOSPITAL', 'HOST', 'HOSTING', 'HOT', 'HOTELS',
|
||||
'HOTMAIL', 'HOUSE', 'HOW', 'HR', 'HSBC', 'HT', 'HU', 'HUGHES', 'HYATT',
|
||||
'HYUNDAI', 'IBM', 'ICBC', 'ICE', 'ICU', 'ID', 'IE', 'IEEE', 'IFM',
|
||||
'IKANO', 'IL', 'IM', 'IMAMAT', 'IMDB', 'IMMO', 'IMMOBILIEN', 'IN',
|
||||
|
@ -111,39 +111,38 @@ final class Tld extends Simple
|
|||
'JOBURG', 'JOT', 'JOY', 'JP', 'JPMORGAN', 'JPRS', 'JUEGOS', 'JUNIPER',
|
||||
'KAUFEN', 'KDDI', 'KE', 'KERRYHOTELS', 'KERRYLOGISTICS',
|
||||
'KERRYPROPERTIES', 'KFH', 'KG', 'KH', 'KI', 'KIA', 'KIDS', 'KIM',
|
||||
'KINDER', 'KINDLE', 'KITCHEN', 'KIWI', 'KM', 'KN', 'KOELN', 'KOMATSU',
|
||||
'KOSHER', 'KP', 'KPMG', 'KPN', 'KR', 'KRD', 'KRED', 'KUOKGROUP', 'KW',
|
||||
'KY', 'KYOTO', 'KZ', 'LA', 'LACAIXA', 'LAMBORGHINI', 'LAMER',
|
||||
'LANCASTER', 'LAND', 'LANDROVER', 'LANXESS', 'LASALLE', 'LAT',
|
||||
'LATINO', 'LATROBE', 'LAW', 'LAWYER', 'LB', 'LC', 'LDS', 'LEASE',
|
||||
'LECLERC', 'LEFRAK', 'LEGAL', 'LEGO', 'LEXUS', 'LGBT', 'LI', 'LIDL',
|
||||
'LIFE', 'LIFEINSURANCE', 'LIFESTYLE', 'LIGHTING', 'LIKE', 'LILLY',
|
||||
'LIMITED', 'LIMO', 'LINCOLN', 'LINK', 'LIPSY', 'LIVE', 'LIVING', 'LK',
|
||||
'LLC', 'LLP', 'LOAN', 'LOANS', 'LOCKER', 'LOCUS', 'LOL', 'LONDON',
|
||||
'LOTTE', 'LOTTO', 'LOVE', 'LPL', 'LPLFINANCIAL', 'LR', 'LS', 'LT',
|
||||
'LTD', 'LTDA', 'LU', 'LUNDBECK', 'LUXE', 'LUXURY', 'LV', 'LY', 'MA',
|
||||
'MADRID', 'MAIF', 'MAISON', 'MAKEUP', 'MAN', 'MANAGEMENT', 'MANGO',
|
||||
'MAP', 'MARKET', 'MARKETING', 'MARKETS', 'MARRIOTT', 'MARSHALLS',
|
||||
'MATTEL', 'MBA', 'MC', 'MCKINSEY', 'MD', 'ME', 'MED', 'MEDIA', 'MEET',
|
||||
'KINDLE', 'KITCHEN', 'KIWI', 'KM', 'KN', 'KOELN', 'KOMATSU', 'KOSHER',
|
||||
'KP', 'KPMG', 'KPN', 'KR', 'KRD', 'KRED', 'KUOKGROUP', 'KW', 'KY',
|
||||
'KYOTO', 'KZ', 'LA', 'LACAIXA', 'LAMBORGHINI', 'LAMER', 'LANCASTER',
|
||||
'LAND', 'LANDROVER', 'LANXESS', 'LASALLE', 'LAT', 'LATINO', 'LATROBE',
|
||||
'LAW', 'LAWYER', 'LB', 'LC', 'LDS', 'LEASE', 'LECLERC', 'LEFRAK',
|
||||
'LEGAL', 'LEGO', 'LEXUS', 'LGBT', 'LI', 'LIDL', 'LIFE',
|
||||
'LIFEINSURANCE', 'LIFESTYLE', 'LIGHTING', 'LIKE', 'LILLY', 'LIMITED',
|
||||
'LIMO', 'LINCOLN', 'LINK', 'LIPSY', 'LIVE', 'LIVING', 'LK', 'LLC',
|
||||
'LLP', 'LOAN', 'LOANS', 'LOCKER', 'LOCUS', 'LOL', 'LONDON', 'LOTTE',
|
||||
'LOTTO', 'LOVE', 'LPL', 'LPLFINANCIAL', 'LR', 'LS', 'LT', 'LTD',
|
||||
'LTDA', 'LU', 'LUNDBECK', 'LUXE', 'LUXURY', 'LV', 'LY', 'MA', 'MADRID',
|
||||
'MAIF', 'MAISON', 'MAKEUP', 'MAN', 'MANAGEMENT', 'MANGO', 'MAP',
|
||||
'MARKET', 'MARKETING', 'MARKETS', 'MARRIOTT', 'MARSHALLS', 'MATTEL',
|
||||
'MBA', 'MC', 'MCKINSEY', 'MD', 'ME', 'MED', 'MEDIA', 'MEET',
|
||||
'MELBOURNE', 'MEME', 'MEMORIAL', 'MEN', 'MENU', 'MERCKMSD', 'MG', 'MH',
|
||||
'MIAMI', 'MICROSOFT', 'MIL', 'MINI', 'MINT', 'MIT', 'MITSUBISHI', 'MK',
|
||||
'ML', 'MLB', 'MLS', 'MM', 'MMA', 'MN', 'MO', 'MOBI', 'MOBILE', 'MODA',
|
||||
'MOE', 'MOI', 'MOM', 'MONASH', 'MONEY', 'MONSTER', 'MORMON',
|
||||
'MORTGAGE', 'MOSCOW', 'MOTO', 'MOTORCYCLES', 'MOV', 'MOVIE', 'MP',
|
||||
'MQ', 'MR', 'MS', 'MSD', 'MT', 'MTN', 'MTR', 'MU', 'MUSEUM', 'MUSIC',
|
||||
'MUTUAL', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NAB', 'NAGOYA', 'NAME',
|
||||
'NATURA', 'NAVY', 'NBA', 'NC', 'NE', 'NEC', 'NET', 'NETBANK',
|
||||
'NETFLIX', 'NETWORK', 'NEUSTAR', 'NEW', 'NEWS', 'NEXT', 'NEXTDIRECT',
|
||||
'NEXUS', 'NF', 'NFL', 'NG', 'NGO', 'NHK', 'NI', 'NICO', 'NIKE',
|
||||
'NIKON', 'NINJA', 'NISSAN', 'NISSAY', 'NL', 'NO', 'NOKIA',
|
||||
'NORTHWESTERNMUTUAL', 'NORTON', 'NOW', 'NOWRUZ', 'NOWTV', 'NP', 'NR',
|
||||
'NRA', 'NRW', 'NTT', 'NU', 'NYC', 'NZ', 'OBI', 'OBSERVER', 'OFFICE',
|
||||
'OKINAWA', 'OLAYAN', 'OLAYANGROUP', 'OLDNAVY', 'OLLO', 'OM', 'OMEGA',
|
||||
'ONE', 'ONG', 'ONL', 'ONLINE', 'OOO', 'OPEN', 'ORACLE', 'ORANGE',
|
||||
'ORG', 'ORGANIC', 'ORIGINS', 'OSAKA', 'OTSUKA', 'OTT', 'OVH', 'PA',
|
||||
'PAGE', 'PANASONIC', 'PARIS', 'PARS', 'PARTNERS', 'PARTS', 'PARTY',
|
||||
'PASSAGENS', 'PAY', 'PCCW', 'PE', 'PET', 'PF', 'PFIZER', 'PG', 'PH',
|
||||
'PHARMACY', 'PHD', 'PHILIPS', 'PHONE', 'PHOTO', 'PHOTOGRAPHY',
|
||||
'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NAB', 'NAGOYA', 'NAME', 'NATURA',
|
||||
'NAVY', 'NBA', 'NC', 'NE', 'NEC', 'NET', 'NETBANK', 'NETFLIX',
|
||||
'NETWORK', 'NEUSTAR', 'NEW', 'NEWS', 'NEXT', 'NEXTDIRECT', 'NEXUS',
|
||||
'NF', 'NFL', 'NG', 'NGO', 'NHK', 'NI', 'NICO', 'NIKE', 'NIKON',
|
||||
'NINJA', 'NISSAN', 'NISSAY', 'NL', 'NO', 'NOKIA', 'NORTON', 'NOW',
|
||||
'NOWRUZ', 'NOWTV', 'NP', 'NR', 'NRA', 'NRW', 'NTT', 'NU', 'NYC', 'NZ',
|
||||
'OBI', 'OBSERVER', 'OFFICE', 'OKINAWA', 'OLAYAN', 'OLAYANGROUP',
|
||||
'OLLO', 'OM', 'OMEGA', 'ONE', 'ONG', 'ONL', 'ONLINE', 'OOO', 'OPEN',
|
||||
'ORACLE', 'ORANGE', 'ORG', 'ORGANIC', 'ORIGINS', 'OSAKA', 'OTSUKA',
|
||||
'OTT', 'OVH', 'PA', 'PAGE', 'PANASONIC', 'PARIS', 'PARS', 'PARTNERS',
|
||||
'PARTS', 'PARTY', 'PAY', 'PCCW', 'PE', 'PET', 'PF', 'PFIZER', 'PG',
|
||||
'PH', 'PHARMACY', 'PHD', 'PHILIPS', 'PHONE', 'PHOTO', 'PHOTOGRAPHY',
|
||||
'PHOTOS', 'PHYSIO', 'PICS', 'PICTET', 'PICTURES', 'PID', 'PIN', 'PING',
|
||||
'PINK', 'PIONEER', 'PIZZA', 'PK', 'PL', 'PLACE', 'PLAY', 'PLAYSTATION',
|
||||
'PLUMBING', 'PLUS', 'PM', 'PN', 'PNC', 'POHL', 'POKER', 'POLITIE',
|
||||
|
@ -155,91 +154,88 @@ final class Tld extends Simple
|
|||
'REDSTONE', 'REDUMBRELLA', 'REHAB', 'REISE', 'REISEN', 'REIT',
|
||||
'RELIANCE', 'REN', 'RENT', 'RENTALS', 'REPAIR', 'REPORT', 'REPUBLICAN',
|
||||
'REST', 'RESTAURANT', 'REVIEW', 'REVIEWS', 'REXROTH', 'RICH',
|
||||
'RICHARDLI', 'RICOH', 'RIL', 'RIO', 'RIP', 'RO', 'ROCHER', 'ROCKS',
|
||||
'RODEO', 'ROGERS', 'ROOM', 'RS', 'RSVP', 'RU', 'RUGBY', 'RUHR', 'RUN',
|
||||
'RW', 'RWE', 'RYUKYU', 'SA', 'SAARLAND', 'SAFE', 'SAFETY', 'SAKURA',
|
||||
'SALE', 'SALON', 'SAMSCLUB', 'SAMSUNG', 'SANDVIK', 'SANDVIKCOROMANT',
|
||||
'SANOFI', 'SAP', 'SARL', 'SAS', 'SAVE', 'SAXO', 'SB', 'SBI', 'SBS',
|
||||
'SC', 'SCA', 'SCB', 'SCHAEFFLER', 'SCHMIDT', 'SCHOLARSHIPS', 'SCHOOL',
|
||||
'SCHULE', 'SCHWARZ', 'SCIENCE', 'SCOT', 'SD', 'SE', 'SEARCH', 'SEAT',
|
||||
'SECURE', 'SECURITY', 'SEEK', 'SELECT', 'SENER', 'SERVICES', 'SEVEN',
|
||||
'SEW', 'SEX', 'SEXY', 'SFR', 'SG', 'SH', 'SHANGRILA', 'SHARP', 'SHAW',
|
||||
'SHELL', 'SHIA', 'SHIKSHA', 'SHOES', 'SHOP', 'SHOPPING', 'SHOUJI',
|
||||
'SHOW', 'SHOWTIME', 'SI', 'SILK', 'SINA', 'SINGLES', 'SITE', 'SJ',
|
||||
'SK', 'SKI', 'SKIN', 'SKY', 'SKYPE', 'SL', 'SLING', 'SM', 'SMART',
|
||||
'SMILE', 'SN', 'SNCF', 'SO', 'SOCCER', 'SOCIAL', 'SOFTBANK',
|
||||
'SOFTWARE', 'SOHU', 'SOLAR', 'SOLUTIONS', 'SONG', 'SONY', 'SOY', 'SPA',
|
||||
'SPACE', 'SPORT', 'SPOT', 'SR', 'SRL', 'SS', 'ST', 'STADA', 'STAPLES',
|
||||
'STAR', 'STATEBANK', 'STATEFARM', 'STC', 'STCGROUP', 'STOCKHOLM',
|
||||
'STORAGE', 'STORE', 'STREAM', 'STUDIO', 'STUDY', 'STYLE', 'SU',
|
||||
'SUCKS', 'SUPPLIES', 'SUPPLY', 'SUPPORT', 'SURF', 'SURGERY', 'SUZUKI',
|
||||
'SV', 'SWATCH', 'SWISS', 'SX', 'SY', 'SYDNEY', 'SYSTEMS', 'SZ', 'TAB',
|
||||
'TAIPEI', 'TALK', 'TAOBAO', 'TARGET', 'TATAMOTORS', 'TATAR', 'TATTOO',
|
||||
'TAX', 'TAXI', 'TC', 'TCI', 'TD', 'TDK', 'TEAM', 'TECH', 'TECHNOLOGY',
|
||||
'TEL', 'TEMASEK', 'TENNIS', 'TEVA', 'TF', 'TG', 'TH', 'THD', 'THEATER',
|
||||
'THEATRE', 'TIAA', 'TICKETS', 'TIENDA', 'TIFFANY', 'TIPS', 'TIRES',
|
||||
'TIROL', 'TJ', 'TJMAXX', 'TJX', 'TK', 'TKMAXX', 'TL', 'TM', 'TMALL',
|
||||
'TN', 'TO', 'TODAY', 'TOKYO', 'TOOLS', 'TOP', 'TORAY', 'TOSHIBA',
|
||||
'TOTAL', 'TOURS', 'TOWN', 'TOYOTA', 'TOYS', 'TR', 'TRADE', 'TRADING',
|
||||
'TRAINING', 'TRAVEL', 'TRAVELCHANNEL', 'TRAVELERS',
|
||||
'RICHARDLI', 'RICOH', 'RIL', 'RIO', 'RIP', 'RO', 'ROCKS', 'RODEO',
|
||||
'ROGERS', 'ROOM', 'RS', 'RSVP', 'RU', 'RUGBY', 'RUHR', 'RUN', 'RW',
|
||||
'RWE', 'RYUKYU', 'SA', 'SAARLAND', 'SAFE', 'SAFETY', 'SAKURA', 'SALE',
|
||||
'SALON', 'SAMSCLUB', 'SAMSUNG', 'SANDVIK', 'SANDVIKCOROMANT', 'SANOFI',
|
||||
'SAP', 'SARL', 'SAS', 'SAVE', 'SAXO', 'SB', 'SBI', 'SBS', 'SC', 'SCB',
|
||||
'SCHAEFFLER', 'SCHMIDT', 'SCHOLARSHIPS', 'SCHOOL', 'SCHULE', 'SCHWARZ',
|
||||
'SCIENCE', 'SCOT', 'SD', 'SE', 'SEARCH', 'SEAT', 'SECURE', 'SECURITY',
|
||||
'SEEK', 'SELECT', 'SENER', 'SERVICES', 'SEVEN', 'SEW', 'SEX', 'SEXY',
|
||||
'SFR', 'SG', 'SH', 'SHANGRILA', 'SHARP', 'SHAW', 'SHELL', 'SHIA',
|
||||
'SHIKSHA', 'SHOES', 'SHOP', 'SHOPPING', 'SHOUJI', 'SHOW', 'SI', 'SILK',
|
||||
'SINA', 'SINGLES', 'SITE', 'SJ', 'SK', 'SKI', 'SKIN', 'SKY', 'SKYPE',
|
||||
'SL', 'SLING', 'SM', 'SMART', 'SMILE', 'SN', 'SNCF', 'SO', 'SOCCER',
|
||||
'SOCIAL', 'SOFTBANK', 'SOFTWARE', 'SOHU', 'SOLAR', 'SOLUTIONS', 'SONG',
|
||||
'SONY', 'SOY', 'SPA', 'SPACE', 'SPORT', 'SPOT', 'SR', 'SRL', 'SS',
|
||||
'ST', 'STADA', 'STAPLES', 'STAR', 'STATEBANK', 'STATEFARM', 'STC',
|
||||
'STCGROUP', 'STOCKHOLM', 'STORAGE', 'STORE', 'STREAM', 'STUDIO',
|
||||
'STUDY', 'STYLE', 'SU', 'SUCKS', 'SUPPLIES', 'SUPPLY', 'SUPPORT',
|
||||
'SURF', 'SURGERY', 'SUZUKI', 'SV', 'SWATCH', 'SWISS', 'SX', 'SY',
|
||||
'SYDNEY', 'SYSTEMS', 'SZ', 'TAB', 'TAIPEI', 'TALK', 'TAOBAO', 'TARGET',
|
||||
'TATAMOTORS', 'TATAR', 'TATTOO', 'TAX', 'TAXI', 'TC', 'TCI', 'TD',
|
||||
'TDK', 'TEAM', 'TECH', 'TECHNOLOGY', 'TEL', 'TEMASEK', 'TENNIS',
|
||||
'TEVA', 'TF', 'TG', 'TH', 'THD', 'THEATER', 'THEATRE', 'TIAA',
|
||||
'TICKETS', 'TIENDA', 'TIPS', 'TIRES', 'TIROL', 'TJ', 'TJMAXX', 'TJX',
|
||||
'TK', 'TKMAXX', 'TL', 'TM', 'TMALL', 'TN', 'TO', 'TODAY', 'TOKYO',
|
||||
'TOOLS', 'TOP', 'TORAY', 'TOSHIBA', 'TOTAL', 'TOURS', 'TOWN', 'TOYOTA',
|
||||
'TOYS', 'TR', 'TRADE', 'TRADING', 'TRAINING', 'TRAVEL', 'TRAVELERS',
|
||||
'TRAVELERSINSURANCE', 'TRUST', 'TRV', 'TT', 'TUBE', 'TUI', 'TUNES',
|
||||
'TUSHU', 'TV', 'TVS', 'TW', 'TZ', 'UA', 'UBANK', 'UBS', 'UG', 'UK',
|
||||
'UNICOM', 'UNIVERSITY', 'UNO', 'UOL', 'UPS', 'US', 'UY', 'UZ', 'VA',
|
||||
'VACATIONS', 'VANA', 'VANGUARD', 'VC', 'VE', 'VEGAS', 'VENTURES',
|
||||
'VERISIGN', 'VERSICHERUNG', 'VET', 'VG', 'VI', 'VIAJES', 'VIDEO',
|
||||
'VIG', 'VIKING', 'VILLAS', 'VIN', 'VIP', 'VIRGIN', 'VISA', 'VISION',
|
||||
'VIVA', 'VIVO', 'VLAANDEREN', 'VN', 'VODKA', 'VOLKSWAGEN', 'VOLVO',
|
||||
'VOTE', 'VOTING', 'VOTO', 'VOYAGE', 'VU', 'VUELOS', 'WALES', 'WALMART',
|
||||
'WALTER', 'WANG', 'WANGGOU', 'WATCH', 'WATCHES', 'WEATHER',
|
||||
'WEATHERCHANNEL', 'WEBCAM', 'WEBER', 'WEBSITE', 'WED', 'WEDDING',
|
||||
'WEIBO', 'WEIR', 'WF', 'WHOSWHO', 'WIEN', 'WIKI', 'WILLIAMHILL', 'WIN',
|
||||
'WINDOWS', 'WINE', 'WINNERS', 'WME', 'WOLTERSKLUWER', 'WOODSIDE',
|
||||
'WORK', 'WORKS', 'WORLD', 'WOW', 'WS', 'WTC', 'WTF', 'XBOX', 'XEROX',
|
||||
'XFINITY', 'XIHUAN', 'XIN', 'XN--11B4C3D', 'XN--1CK2E1B',
|
||||
'XN--1QQW23A', 'XN--2SCRJ9C', 'XN--30RR7Y', 'XN--3BST00M',
|
||||
'XN--3DS443G', 'XN--3E0B707E', 'XN--3HCRJ9C', 'XN--3PXU8K',
|
||||
'XN--42C2D9A', 'XN--45BR5CYL', 'XN--45BRJ9C', 'XN--45Q11C',
|
||||
'XN--4DBRK0CE', 'XN--4GBRIM', 'XN--54B7FTA0CC', 'XN--55QW42G',
|
||||
'XN--55QX5D', 'XN--5SU34J936BGSG', 'XN--5TZM5G', 'XN--6FRZ82G',
|
||||
'XN--6QQ986B3XL', 'XN--80ADXHKS', 'XN--80AO21A', 'XN--80AQECDR1A',
|
||||
'XN--80ASEHDB', 'XN--80ASWG', 'XN--8Y0A063A', 'XN--90A3AC', 'XN--90AE',
|
||||
'XN--90AIS', 'XN--9DBQ2A', 'XN--9ET52U', 'XN--9KRT00A',
|
||||
'XN--B4W605FERD', 'XN--BCK1B9A5DRE4C', 'XN--C1AVG', 'XN--C2BR7G',
|
||||
'XN--CCK2B3B', 'XN--CCKWCXETD', 'XN--CG4BKI', 'XN--CLCHC0EA0B2G2A9GCD',
|
||||
'XN--CZR694B', 'XN--CZRS0T', 'XN--CZRU2D', 'XN--D1ACJ3B', 'XN--D1ALF',
|
||||
'XN--E1A4C', 'XN--ECKVDTC9D', 'XN--EFVY88H', 'XN--FCT429K',
|
||||
'XN--FHBEI', 'XN--FIQ228C5HS', 'XN--FIQ64B', 'XN--FIQS8S',
|
||||
'XN--FIQZ9S', 'XN--FJQ720A', 'XN--FLW351E', 'XN--FPCRJ9C3D',
|
||||
'XN--FZC2C9E2C', 'XN--FZYS8D69UVGM', 'XN--G2XX48C', 'XN--GCKR3F0F',
|
||||
'XN--GECRJ9C', 'XN--GK3AT1E', 'XN--H2BREG3EVE', 'XN--H2BRJ9C',
|
||||
'XN--H2BRJ9C8C', 'XN--HXT814E', 'XN--I1B6B1A6A2E', 'XN--IMR513N',
|
||||
'XN--IO0A7I', 'XN--J1AEF', 'XN--J1AMH', 'XN--J6W193G',
|
||||
'VIVA', 'VIVO', 'VLAANDEREN', 'VN', 'VODKA', 'VOLVO', 'VOTE', 'VOTING',
|
||||
'VOTO', 'VOYAGE', 'VU', 'WALES', 'WALMART', 'WALTER', 'WANG',
|
||||
'WANGGOU', 'WATCH', 'WATCHES', 'WEATHER', 'WEATHERCHANNEL', 'WEBCAM',
|
||||
'WEBER', 'WEBSITE', 'WED', 'WEDDING', 'WEIBO', 'WEIR', 'WF', 'WHOSWHO',
|
||||
'WIEN', 'WIKI', 'WILLIAMHILL', 'WIN', 'WINDOWS', 'WINE', 'WINNERS',
|
||||
'WME', 'WOLTERSKLUWER', 'WOODSIDE', 'WORK', 'WORKS', 'WORLD', 'WOW',
|
||||
'WS', 'WTC', 'WTF', 'XBOX', 'XEROX', 'XIHUAN', 'XIN', 'XN--11B4C3D',
|
||||
'XN--1CK2E1B', 'XN--1QQW23A', 'XN--2SCRJ9C', 'XN--30RR7Y',
|
||||
'XN--3BST00M', 'XN--3DS443G', 'XN--3E0B707E', 'XN--3HCRJ9C',
|
||||
'XN--3PXU8K', 'XN--42C2D9A', 'XN--45BR5CYL', 'XN--45BRJ9C',
|
||||
'XN--45Q11C', 'XN--4DBRK0CE', 'XN--4GBRIM', 'XN--54B7FTA0CC',
|
||||
'XN--55QW42G', 'XN--55QX5D', 'XN--5SU34J936BGSG', 'XN--5TZM5G',
|
||||
'XN--6FRZ82G', 'XN--6QQ986B3XL', 'XN--80ADXHKS', 'XN--80AO21A',
|
||||
'XN--80AQECDR1A', 'XN--80ASEHDB', 'XN--80ASWG', 'XN--8Y0A063A',
|
||||
'XN--90A3AC', 'XN--90AE', 'XN--90AIS', 'XN--9DBQ2A', 'XN--9ET52U',
|
||||
'XN--9KRT00A', 'XN--B4W605FERD', 'XN--BCK1B9A5DRE4C', 'XN--C1AVG',
|
||||
'XN--C2BR7G', 'XN--CCK2B3B', 'XN--CCKWCXETD', 'XN--CG4BKI',
|
||||
'XN--CLCHC0EA0B2G2A9GCD', 'XN--CZR694B', 'XN--CZRS0T', 'XN--CZRU2D',
|
||||
'XN--D1ACJ3B', 'XN--D1ALF', 'XN--E1A4C', 'XN--ECKVDTC9D',
|
||||
'XN--EFVY88H', 'XN--FCT429K', 'XN--FHBEI', 'XN--FIQ228C5HS',
|
||||
'XN--FIQ64B', 'XN--FIQS8S', 'XN--FIQZ9S', 'XN--FJQ720A', 'XN--FLW351E',
|
||||
'XN--FPCRJ9C3D', 'XN--FZC2C9E2C', 'XN--FZYS8D69UVGM', 'XN--G2XX48C',
|
||||
'XN--GCKR3F0F', 'XN--GECRJ9C', 'XN--GK3AT1E', 'XN--H2BREG3EVE',
|
||||
'XN--H2BRJ9C', 'XN--H2BRJ9C8C', 'XN--HXT814E', 'XN--I1B6B1A6A2E',
|
||||
'XN--IMR513N', 'XN--IO0A7I', 'XN--J1AEF', 'XN--J1AMH', 'XN--J6W193G',
|
||||
'XN--JLQ480N2RG', 'XN--JVR189M', 'XN--KCRX77D1X4A', 'XN--KPRW13D',
|
||||
'XN--KPRY57D', 'XN--KPUT3I', 'XN--L1ACC', 'XN--LGBBAT1AD8J',
|
||||
'XN--MGB9AWBF', 'XN--MGBA3A3EJT', 'XN--MGBA3A4F16A',
|
||||
'XN--MGBA7C0BBN0A', 'XN--MGBAAKC7DVF', 'XN--MGBAAM7A8H',
|
||||
'XN--MGBAB2BD', 'XN--MGBAH1A3HJKRD', 'XN--MGBAI9AZGQP6J',
|
||||
'XN--MGBAYH7GPA', 'XN--MGBBH1A', 'XN--MGBBH1A71E', 'XN--MGBC0A9AZCG',
|
||||
'XN--MGBCA7DZDO', 'XN--MGBCPQ6GPA1A', 'XN--MGBERP4A5D4AR',
|
||||
'XN--MGBGU82A', 'XN--MGBI4ECEXP', 'XN--MGBPL2FH', 'XN--MGBT3DHD',
|
||||
'XN--MGBTX2B', 'XN--MGBX4CD0AB', 'XN--MIX891F', 'XN--MK1BU44C',
|
||||
'XN--MXTQ1M', 'XN--NGBC5AZD', 'XN--NGBE9E0A', 'XN--NGBRX', 'XN--NODE',
|
||||
'XN--NQV7F', 'XN--NQV7FS00EMA', 'XN--NYQY26A', 'XN--O3CW4H',
|
||||
'XN--OGBPF8FL', 'XN--OTU796D', 'XN--P1ACF', 'XN--P1AI', 'XN--PGBS0DH',
|
||||
'XN--PSSY2U', 'XN--Q7CE6A', 'XN--Q9JYB4C', 'XN--QCKA1PMC', 'XN--QXA6A',
|
||||
'XN--QXAM', 'XN--RHQV96G', 'XN--ROVU88B', 'XN--RVC1E0AM3E',
|
||||
'XN--S9BRJ9C', 'XN--SES554G', 'XN--T60B56A', 'XN--TCKWE',
|
||||
'XN--TIQ49XQYJ', 'XN--UNUP4Y', 'XN--VERMGENSBERATER-CTB',
|
||||
'XN--VERMGENSBERATUNG-PWB', 'XN--VHQUV', 'XN--VUQ861B',
|
||||
'XN--W4R85EL8FHU5DNRA', 'XN--W4RS40L', 'XN--WGBH1C', 'XN--WGBL6A',
|
||||
'XN--XHQ521B', 'XN--XKC2AL3HYE2A', 'XN--XKC2DL3A5EE0H', 'XN--Y9A3AQ',
|
||||
'XN--YFRO4I67O', 'XN--YGBI2AMMX', 'XN--ZFR164B', 'XXX', 'XYZ',
|
||||
'YACHTS', 'YAHOO', 'YAMAXUN', 'YANDEX', 'YE', 'YODOBASHI', 'YOGA',
|
||||
'YOKOHAMA', 'YOU', 'YOUTUBE', 'YT', 'YUN', 'ZA', 'ZAPPOS', 'ZARA',
|
||||
'ZERO', 'ZIP', 'ZM', 'ZONE', 'ZUERICH', 'ZW',
|
||||
'XN--MGBA7C0BBN0A', 'XN--MGBAAM7A8H', 'XN--MGBAB2BD',
|
||||
'XN--MGBAH1A3HJKRD', 'XN--MGBAI9AZGQP6J', 'XN--MGBAYH7GPA',
|
||||
'XN--MGBBH1A', 'XN--MGBBH1A71E', 'XN--MGBC0A9AZCG', 'XN--MGBCA7DZDO',
|
||||
'XN--MGBCPQ6GPA1A', 'XN--MGBERP4A5D4AR', 'XN--MGBGU82A',
|
||||
'XN--MGBI4ECEXP', 'XN--MGBPL2FH', 'XN--MGBT3DHD', 'XN--MGBTX2B',
|
||||
'XN--MGBX4CD0AB', 'XN--MIX891F', 'XN--MK1BU44C', 'XN--MXTQ1M',
|
||||
'XN--NGBC5AZD', 'XN--NGBE9E0A', 'XN--NGBRX', 'XN--NODE', 'XN--NQV7F',
|
||||
'XN--NQV7FS00EMA', 'XN--NYQY26A', 'XN--O3CW4H', 'XN--OGBPF8FL',
|
||||
'XN--OTU796D', 'XN--P1ACF', 'XN--P1AI', 'XN--PGBS0DH', 'XN--PSSY2U',
|
||||
'XN--Q7CE6A', 'XN--Q9JYB4C', 'XN--QCKA1PMC', 'XN--QXA6A', 'XN--QXAM',
|
||||
'XN--RHQV96G', 'XN--ROVU88B', 'XN--RVC1E0AM3E', 'XN--S9BRJ9C',
|
||||
'XN--SES554G', 'XN--T60B56A', 'XN--TCKWE', 'XN--TIQ49XQYJ',
|
||||
'XN--UNUP4Y', 'XN--VERMGENSBERATER-CTB', 'XN--VERMGENSBERATUNG-PWB',
|
||||
'XN--VHQUV', 'XN--VUQ861B', 'XN--W4R85EL8FHU5DNRA', 'XN--W4RS40L',
|
||||
'XN--WGBH1C', 'XN--WGBL6A', 'XN--XHQ521B', 'XN--XKC2AL3HYE2A',
|
||||
'XN--XKC2DL3A5EE0H', 'XN--Y9A3AQ', 'XN--YFRO4I67O', 'XN--YGBI2AMMX',
|
||||
'XN--ZFR164B', 'XXX', 'XYZ', 'YACHTS', 'YAHOO', 'YAMAXUN', 'YANDEX',
|
||||
'YE', 'YODOBASHI', 'YOGA', 'YOKOHAMA', 'YOU', 'YOUTUBE', 'YT', 'YUN',
|
||||
'ZA', 'ZAPPOS', 'ZARA', 'ZERO', 'ZIP', 'ZM', 'ZONE', 'ZUERICH', 'ZW',
|
||||
];
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_scalar($input)) {
|
||||
return false;
|
||||
|
|
|
@ -23,7 +23,7 @@ use const FILTER_VALIDATE_BOOLEAN;
|
|||
)]
|
||||
final class TrueVal extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
return filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === true;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ use const SORT_REGULAR;
|
|||
)]
|
||||
final class Unique extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_array($input)) {
|
||||
return false;
|
||||
|
|
|
@ -23,10 +23,10 @@ use function is_uploaded_file;
|
|||
)]
|
||||
final class Uploaded extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $this->validate($input->getPathname());
|
||||
return $this->isValid($input->getPathname());
|
||||
}
|
||||
|
||||
if ($input instanceof UploadedFileInterface) {
|
||||
|
|
|
@ -21,7 +21,7 @@ use function mb_strtoupper;
|
|||
)]
|
||||
final class Uppercase extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -24,7 +24,7 @@ use function preg_match;
|
|||
)]
|
||||
final class Version extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -23,7 +23,7 @@ use function is_writable;
|
|||
)]
|
||||
final class Writable extends Simple
|
||||
{
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if ($input instanceof SplFileInfo) {
|
||||
return $input->isWritable();
|
||||
|
|
|
@ -29,7 +29,7 @@ final class Yes extends Simple
|
|||
) {
|
||||
}
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
protected function isValid(mixed $input): bool
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
|
|
|
@ -9,25 +9,17 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation;
|
||||
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
|
||||
interface Validatable extends Rule
|
||||
interface Validatable
|
||||
{
|
||||
public function assert(mixed $input): void;
|
||||
public const TEMPLATE_STANDARD = '__standard__';
|
||||
|
||||
public function check(mixed $input): void;
|
||||
public function evaluate(mixed $input): Result;
|
||||
|
||||
/**
|
||||
* @param mixed[] $extraParameters
|
||||
*/
|
||||
public function reportError(mixed $input, array $extraParameters = []): ValidationException;
|
||||
public function getName(): ?string;
|
||||
|
||||
public function setName(string $name): static;
|
||||
|
||||
public function getTemplate(): ?string;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getParams(): array;
|
||||
|
||||
public function validate(mixed $input): bool;
|
||||
public function setTemplate(string $template): static;
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation;
|
||||
|
||||
use Respect\Validation\Exceptions\ValidatorException;
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Helpers\CanBindEvaluateRule;
|
||||
use Respect\Validation\Message\Formatter;
|
||||
use Respect\Validation\Message\StandardFormatter;
|
||||
use Respect\Validation\Message\StandardRenderer;
|
||||
use Respect\Validation\Mixins\StaticValidator;
|
||||
use Respect\Validation\Rules\AbstractRule;
|
||||
use Respect\Validation\Rules\AllOf;
|
||||
use Respect\Validation\Rules\Core\Standard;
|
||||
|
||||
use function count;
|
||||
use function current;
|
||||
|
@ -24,7 +24,7 @@ use function current;
|
|||
/**
|
||||
* @mixin StaticValidator
|
||||
*/
|
||||
final class Validator extends AbstractRule
|
||||
final class Validator extends Standard
|
||||
{
|
||||
use CanBindEvaluateRule;
|
||||
|
||||
|
@ -61,7 +61,7 @@ final class Validator extends AbstractRule
|
|||
return $this->bindEvaluate($this->rule(), $this, $input);
|
||||
}
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
public function isValid(mixed $input): bool
|
||||
{
|
||||
return $this->evaluate($input)->isValid;
|
||||
}
|
||||
|
@ -74,11 +74,11 @@ final class Validator extends AbstractRule
|
|||
}
|
||||
|
||||
$templates = $this->templates;
|
||||
if (count($templates) === 0 && $this->template != null) {
|
||||
$templates = ['__self__' => $this->template];
|
||||
if (count($templates) === 0 && $this->getTemplate() != null) {
|
||||
$templates = ['__self__' => $this->getTemplate()];
|
||||
}
|
||||
|
||||
throw new ValidatorException(
|
||||
throw new ValidationException(
|
||||
$this->formatter->main($result, $templates),
|
||||
$this->formatter->full($result, $templates),
|
||||
$this->formatter->array($result, $templates),
|
||||
|
@ -99,6 +99,22 @@ final class Validator extends AbstractRule
|
|||
return $this->rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@see isValid()} instead.
|
||||
*/
|
||||
public function validate(mixed $input): bool
|
||||
{
|
||||
return $this->evaluate($input)->isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@see assert()} instead.
|
||||
*/
|
||||
public function check(mixed $input): void
|
||||
{
|
||||
$this->assert($input);
|
||||
}
|
||||
|
||||
private function rule(): Validatable
|
||||
{
|
||||
if (count($this->rules) === 1) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Respect\Validation\Exceptions\ValidatorException;
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Validatable;
|
||||
use Symfony\Component\VarExporter\VarExporter;
|
||||
|
||||
|
@ -18,7 +18,7 @@ function exceptionMessage(callable $callable, string $fallbackMessage = 'No exce
|
|||
try {
|
||||
$callable();
|
||||
echo $fallbackMessage . PHP_EOL;
|
||||
} catch (ValidatorException $exception) {
|
||||
} catch (ValidationException $exception) {
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ function exceptionMessages(callable $callable, string $fallbackMessage = 'No exc
|
|||
try {
|
||||
$callable();
|
||||
echo $fallbackMessage . PHP_EOL;
|
||||
} catch (ValidatorException $exception) {
|
||||
} catch (ValidationException $exception) {
|
||||
echo VarExporter::export($exception->getMessages()) . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ function exceptionFullMessage(callable $callable, string $fallbackMessage = 'No
|
|||
try {
|
||||
$callable();
|
||||
echo $fallbackMessage . PHP_EOL;
|
||||
} catch (ValidatorException $exception) {
|
||||
} catch (ValidationException $exception) {
|
||||
echo $exception->getFullMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue