| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Html\Contract; |
| 4 |
|
| 5 |
use ipl\Html\Attributes; |
| 6 |
use ipl\Html\Form; |
| 7 |
|
| 8 |
/** |
| 9 |
* Representation of form elements |
| 10 |
* |
| 11 |
* @phpstan-import-type AttributesType from Attributes |
| 12 |
*/ |
| 13 |
interface FormElement extends Wrappable |
| 14 |
{ |
| 15 |
/** |
| 16 |
* Get the attributes or options of the element |
| 17 |
* |
| 18 |
* @return Attributes |
| 19 |
*/ |
| 20 |
public function getAttributes(); |
| 21 |
|
| 22 |
/** |
| 23 |
* Add attributes or options to the form element |
| 24 |
* |
| 25 |
* @param Attributes|AttributesType $attributes |
| 26 |
* |
| 27 |
* @return $this |
| 28 |
*/ |
| 29 |
public function addAttributes($attributes); |
| 30 |
|
| 31 |
/** |
| 32 |
* Get the description for the element, if any |
| 33 |
* |
| 34 |
* @return string|null |
| 35 |
*/ |
| 36 |
public function getDescription(); |
| 37 |
|
| 38 |
/** |
| 39 |
* Get the label for the element, if any |
| 40 |
* |
| 41 |
* @return string|null |
| 42 |
*/ |
| 43 |
public function getLabel(); |
| 44 |
|
| 45 |
/** |
| 46 |
* Get the validation error messages |
| 47 |
* |
| 48 |
* @return array |
| 49 |
*/ |
| 50 |
public function getMessages(); |
| 51 |
|
| 52 |
/** |
| 53 |
* Add a validation error message |
| 54 |
* |
| 55 |
* @param string $message |
| 56 |
* |
| 57 |
* @return $this |
| 58 |
*/ |
| 59 |
public function addMessage(string $message): static; |
| 60 |
|
| 61 |
/** |
| 62 |
* Get the name of the element |
| 63 |
* |
| 64 |
* @return string |
| 65 |
*/ |
| 66 |
public function getName(); |
| 67 |
|
| 68 |
/** |
| 69 |
* Get whether the element has a value |
| 70 |
* |
| 71 |
* @return bool False if the element's value is null, the empty string or the empty array; true otherwise |
| 72 |
*/ |
| 73 |
public function hasValue(); |
| 74 |
|
| 75 |
/** |
| 76 |
* Get the value of the element |
| 77 |
* |
| 78 |
* @return mixed |
| 79 |
*/ |
| 80 |
public function getValue(); |
| 81 |
|
| 82 |
/** |
| 83 |
* Set the value of the element |
| 84 |
* |
| 85 |
* @param mixed $value |
| 86 |
* |
| 87 |
* @return $this |
| 88 |
*/ |
| 89 |
public function setValue($value); |
| 90 |
|
| 91 |
/** |
| 92 |
* Get whether the element has been validated |
| 93 |
* |
| 94 |
* @return bool |
| 95 |
*/ |
| 96 |
public function hasBeenValidated(); |
| 97 |
|
| 98 |
/** |
| 99 |
* Get whether the element is ignored |
| 100 |
* |
| 101 |
* @return bool |
| 102 |
*/ |
| 103 |
public function isIgnored(); |
| 104 |
|
| 105 |
/** |
| 106 |
* Get whether the element is required |
| 107 |
* |
| 108 |
* @return bool |
| 109 |
*/ |
| 110 |
public function isRequired(); |
| 111 |
|
| 112 |
/** |
| 113 |
* Get whether the element is valid |
| 114 |
* |
| 115 |
* @return bool |
| 116 |
*/ |
| 117 |
public function isValid(); |
| 118 |
|
| 119 |
/** |
| 120 |
* Validate the element |
| 121 |
* |
| 122 |
* @return $this |
| 123 |
*/ |
| 124 |
public function validate(); |
| 125 |
|
| 126 |
/** |
| 127 |
* Handler which is called after this element has been registered |
| 128 |
* |
| 129 |
* @param Form $form |
| 130 |
* |
| 131 |
* @return void |
| 132 |
*/ |
| 133 |
public function onRegistered(Form $form); |
| 134 |
} |