1 | <?php |
||
9 | class EnumRule implements Rule |
||
10 | { |
||
11 | private $enumClass = ''; |
||
12 | |||
13 | /** |
||
14 | * @var bool true if the the key of the enum should be used to validate against, otherwise the value is used. |
||
15 | */ |
||
16 | private $useKey = false; |
||
17 | |||
18 | /** |
||
19 | * Create a new rule instance. |
||
20 | * |
||
21 | * @param string $enumClass The enum class to create the the rule for |
||
22 | * @param bool $useKey true if the enum key should be used to validate against, otherwise the value is used. |
||
23 | * |
||
24 | * @return void |
||
|
|||
25 | */ |
||
26 | 39 | public function __construct(string $enumClass, bool $useKey = false) |
|
35 | |||
36 | /** |
||
37 | * Determine if the validation rule passes. |
||
38 | * |
||
39 | * @param string $attribute |
||
40 | * @param mixed $value |
||
41 | * @return bool |
||
42 | */ |
||
43 | 33 | public function passes($attribute, $value): bool |
|
47 | |||
48 | /** |
||
49 | * Get the validation error message. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function message() |
||
59 | } |
||
60 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.