| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Give\Vendors\StellarWP\Validation\Contracts; |
| 6 |
|
| 7 |
use Closure; |
| 8 |
use Give\Vendors\StellarWP\Validation\Commands\ExcludeValue; |
| 9 |
use Give\Vendors\StellarWP\Validation\Commands\SkipValidationRules; |
| 10 |
|
| 11 |
interface ValidationRule |
| 12 |
{ |
| 13 |
/** |
| 14 |
* The unique id of the validation rule. |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
*/ |
| 18 |
public static function id(): string; |
| 19 |
|
| 20 |
/** |
| 21 |
* Creates a new instance of the validation rule from a string form. The string may be something like: |
| 22 |
* "required" or "max:255". |
| 23 |
* |
| 24 |
* If a value is provided after the colon, it will be the options' parameter. |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
public static function fromString(?string $options = null): ValidationRule; |
| 29 |
|
| 30 |
/** |
| 31 |
* The invokable method used to validate the value. If the value is invalid, the fail callback should be invoked |
| 32 |
* with the error message. Use {field} to reference the field name in the error message. |
| 33 |
* |
| 34 |
* @since 1.2.0 add ExcludeValue return option |
| 35 |
* @since 1.0.0 |
| 36 |
* |
| 37 |
* @param mixed $value |
| 38 |
* @param Closure $fail |
| 39 |
* @param string $key |
| 40 |
* @param array<string, mixed> $values |
| 41 |
* |
| 42 |
* @return void|ExcludeValue|SkipValidationRules |
| 43 |
*/ |
| 44 |
public function __invoke($value, Closure $fail, string $key, array $values); |
| 45 |
} |
| 46 |
|