| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace UserAccessManager\Form; |
| 6 |
|
| 7 |
use Exception; |
| 8 |
use UserAccessManager\Form\Element\Input; |
| 9 |
use UserAccessManager\Form\Element\MultipleFormElementValue; |
| 10 |
use UserAccessManager\Form\Element\Radio; |
| 11 |
use UserAccessManager\Form\Element\Select; |
| 12 |
use UserAccessManager\Form\Element\Textarea; |
| 13 |
use UserAccessManager\Form\Element\ValueSetFormElementValue; |
| 14 |
|
| 15 |
class FormFactory |
| 16 |
{ |
| 17 |
public function createForm(): Form |
| 18 |
{ |
| 19 |
return new Form(); |
| 20 |
} |
| 21 |
|
| 22 |
public function createValueSetFormElementValue(mixed $value, string $label): ValueSetFormElementValue |
| 23 |
{ |
| 24 |
return new ValueSetFormElementValue($value, $label); |
| 25 |
} |
| 26 |
|
| 27 |
public function createMultipleFormElementValue(mixed $value, string $label): MultipleFormElementValue |
| 28 |
{ |
| 29 |
return new MultipleFormElementValue($value, $label); |
| 30 |
} |
| 31 |
|
| 32 |
public function createInput( |
| 33 |
string $id, |
| 34 |
mixed $value = null, |
| 35 |
?string $label = null, |
| 36 |
?string $description = null |
| 37 |
): Input { |
| 38 |
return new Input($id, $value, $label, $description); |
| 39 |
} |
| 40 |
|
| 41 |
public function createTextarea( |
| 42 |
string $id, |
| 43 |
mixed $value = null, |
| 44 |
?string $label = null, |
| 45 |
?string $description = null |
| 46 |
): Textarea { |
| 47 |
return new Textarea($id, $value, $label, $description); |
| 48 |
} |
| 49 |
|
| 50 |
public function createSelect( |
| 51 |
string $id, |
| 52 |
array $possibleValues, |
| 53 |
mixed $value = null, |
| 54 |
?string $label = null, |
| 55 |
?string $description = null |
| 56 |
): Select { |
| 57 |
return new Select($id, $possibleValues, $value, $label, $description); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* @throws Exception |
| 62 |
*/ |
| 63 |
public function createRadio( |
| 64 |
string $id, |
| 65 |
array $possibleValues, |
| 66 |
mixed $value = null, |
| 67 |
?string $label = null, |
| 68 |
?string $description = null |
| 69 |
): Radio { |
| 70 |
return new Radio($id, $possibleValues, $value, $label, $description); |
| 71 |
} |
| 72 |
} |
| 73 |
|