| 1 |
<?php |
| 2 |
/** |
| 3 |
* FormFactory.php |
| 4 |
* |
| 5 |
* The FormFactory class file. |
| 6 |
* |
| 7 |
* PHP versions 5 |
| 8 |
* |
| 9 |
* @author Alexander Schneider <alexanderschneider85@gmail.com> |
| 10 |
* @copyright 2008-2017 Alexander Schneider |
| 11 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 12 |
* @version SVN: $id$ |
| 13 |
* @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 14 |
*/ |
| 15 |
|
| 16 |
declare(strict_types=1); |
| 17 |
|
| 18 |
namespace UserAccessManager\Form; |
| 19 |
|
| 20 |
use Exception; |
| 21 |
|
| 22 |
/** |
| 23 |
* Class FormFactory |
| 24 |
* |
| 25 |
* @package UserAccessManager\Form |
| 26 |
*/ |
| 27 |
class FormFactory |
| 28 |
{ |
| 29 |
/** |
| 30 |
* Creates a form object. |
| 31 |
* @return Form |
| 32 |
*/ |
| 33 |
public function createFrom(): Form |
| 34 |
{ |
| 35 |
return new Form(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Creates a ValueSetFormElementValue object. |
| 40 |
* @param mixed $value |
| 41 |
* @param string $label |
| 42 |
* @return ValueSetFormElementValue |
| 43 |
*/ |
| 44 |
public function createValueSetFromElementValue($value, string $label): ValueSetFormElementValue |
| 45 |
{ |
| 46 |
return new ValueSetFormElementValue($value, $label); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Creates a MultipleFormElementValue object. |
| 51 |
* @param mixed $value |
| 52 |
* @param string $label |
| 53 |
* @return MultipleFormElementValue |
| 54 |
*/ |
| 55 |
public function createMultipleFormElementValue($value, string $label): MultipleFormElementValue |
| 56 |
{ |
| 57 |
return new MultipleFormElementValue($value, $label); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Creates a Input object. |
| 62 |
* @param string $id |
| 63 |
* @param null|mixed $value |
| 64 |
* @param null|string $label |
| 65 |
* @param null|string $description |
| 66 |
* @return Input |
| 67 |
*/ |
| 68 |
public function createInput(string $id, $value = null, $label = null, $description = null): Input |
| 69 |
{ |
| 70 |
return new Input($id, $value, $label, $description); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Creates a Textarea object. |
| 75 |
* @param string $id |
| 76 |
* @param null|mixed $value |
| 77 |
* @param null|string $label |
| 78 |
* @param null|string $description |
| 79 |
* @return Textarea |
| 80 |
*/ |
| 81 |
public function createTextarea(string $id, $value = null, $label = null, $description = null): Textarea |
| 82 |
{ |
| 83 |
return new Textarea($id, $value, $label, $description); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Creates a Select object. |
| 88 |
* @param string $id |
| 89 |
* @param ValueSetFormElementValue[] $possibleValues |
| 90 |
* @param null|mixed $value |
| 91 |
* @param null|string $label |
| 92 |
* @param null|string $description |
| 93 |
* @return Select |
| 94 |
*/ |
| 95 |
public function createSelect( |
| 96 |
string $id, |
| 97 |
array $possibleValues, |
| 98 |
$value = null, |
| 99 |
$label = null, |
| 100 |
$description = null |
| 101 |
): Select { |
| 102 |
return new Select($id, $possibleValues, $value, $label, $description); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Creates a Radio object. |
| 107 |
* @param string $id |
| 108 |
* @param MultipleFormElementValue[] $possibleValues |
| 109 |
* @param null|mixed $value |
| 110 |
* @param null|string $label |
| 111 |
* @param null|string $description |
| 112 |
* @return Radio |
| 113 |
* @throws Exception |
| 114 |
*/ |
| 115 |
public function createRadio( |
| 116 |
string $id, |
| 117 |
array $possibleValues, |
| 118 |
$value = null, |
| 119 |
$label = null, |
| 120 |
$description = null |
| 121 |
): Radio { |
| 122 |
return new Radio($id, $possibleValues, $value, $label, $description); |
| 123 |
} |
| 124 |
} |
| 125 |
|