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