mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
Currently, we convert the properties of a rule into parameters and pass them to the exceptions. That complicates things for a few reasons: 1. The exception knows too much: there's a lot of information in an object, and the exception would only need a few parameters to work correctly. 2. Any variable change becomes a backward compatibility break: if we change the name of the variable type in a rule, even if it's a private one, we may need to change the template, which is a backward compatibility break. 3. The factory is bloated because of introspection tricks: it reads the properties from the class, even from the parent, and then passes it to the exception. Of course, that means we introduce another method to `Validatable`, but in most cases, extending `AbstractRule` is enough to create a new rule. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
41 lines
910 B
PHP
41 lines
910 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation;
|
|
|
|
use Respect\Validation\Exceptions\ValidationException;
|
|
|
|
interface Validatable
|
|
{
|
|
public const TEMPLATE_STANDARD = 'standard';
|
|
|
|
public function assert(mixed $input): void;
|
|
|
|
public function check(mixed $input): void;
|
|
|
|
public function getName(): ?string;
|
|
|
|
/**
|
|
* @param mixed[] $extraParameters
|
|
*/
|
|
public function reportError(mixed $input, array $extraParameters = []): ValidationException;
|
|
|
|
public function setName(string $name): Validatable;
|
|
|
|
public function setTemplate(string $template): Validatable;
|
|
|
|
public function getTemplate(mixed $input): string;
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function getParams(): array;
|
|
|
|
public function validate(mixed $input): bool;
|
|
}
|