Skip to content

Commit e552b58

Browse files
committed
Utilize ipl\Stdlib\Option where applicable
The attribute setters are kept for now, to ensure backwards compatibility with code relying on them.
1 parent 1bec189 commit e552b58

8 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/FormElement/BaseFormElement.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ abstract class BaseFormElement extends BaseHtmlElement implements FormElement, V
2020
use Translation;
2121

2222
/** @var string Description of the element */
23+
#[Option]
2324
protected $description;
2425

2526
/** @var string Label of the element */
27+
#[Option]
2628
protected $label;
2729

2830
/** @var string Name of the element */
31+
#[Option]
2932
protected $name;
3033

3134
/** @var bool Whether the element is ignored */
@@ -41,6 +44,7 @@ abstract class BaseFormElement extends BaseHtmlElement implements FormElement, V
4144
protected $validators;
4245

4346
/** @var mixed Value of the element */
47+
#[Option]
4448
protected $value;
4549

4650
/** @var array<int, mixed> Value candidates of the element */
@@ -139,6 +143,7 @@ public function isIgnored()
139143
*
140144
* @return $this
141145
*/
146+
#[Option]
142147
public function setIgnored($ignored = true)
143148
{
144149
$this->ignored = (bool) $ignored;
@@ -158,6 +163,7 @@ public function isRequired()
158163
*
159164
* @return $this
160165
*/
166+
#[Option]
161167
public function setRequired($required = true)
162168
{
163169
$this->required = (bool) $required;
@@ -197,6 +203,7 @@ public function getValidators()
197203
*
198204
* @return $this
199205
*/
206+
#[Option]
200207
public function setValidators($validators)
201208
{
202209
$this

src/FormElement/CheckboxElement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
namespace ipl\Html\FormElement;
44

55
use ipl\Html\Attributes;
6+
use ipl\Stdlib\Option;
67

78
class CheckboxElement extends InputElement
89
{
910
/** @var bool Whether the checkbox is checked */
1011
protected $checked = false;
1112

1213
/** @var string Value of the checkbox when it is checked */
14+
#[Option]
1315
protected $checkedValue = 'y';
1416

1517
/** @var string Value of the checkbox when it is not checked */
18+
#[Option]
1619
protected $uncheckedValue = 'n';
1720

1821
protected $type = 'checkbox';
@@ -34,6 +37,7 @@ public function isChecked()
3437
*
3538
* @return $this
3639
*/
40+
#[Option]
3741
public function setChecked($checked)
3842
{
3943
$this->checked = (bool) $checked;

src/FormElement/FileElement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ipl\Html\HtmlElement;
1111
use ipl\Html\Text;
1212
use ipl\I18n\Translation;
13+
use ipl\Stdlib\Option;
1314
use ipl\Validator\FileValidator;
1415
use ipl\Validator\ValidatorChain;
1516
use Psr\Http\Message\UploadedFileInterface;
@@ -40,6 +41,7 @@ class FileElement extends InputElement
4041
protected $filesToRemove = [];
4142

4243
/** @var ?string Path to store files to preserve them across requests */
44+
#[Option]
4345
protected $destination;
4446

4547
/** @var int The default maximum file size */

src/FormElement/InputElement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace ipl\Html\FormElement;
44

5-
use ipl\Html\Attribute;
65
use ipl\Html\Attributes;
6+
use ipl\Stdlib\Option;
77

88
class InputElement extends BaseFormElement
99
{
@@ -29,6 +29,7 @@ public function getType()
2929
*
3030
* @return $this
3131
*/
32+
#[Option]
3233
public function setType($type)
3334
{
3435
$this->type = (string) $type;

src/FormElement/RadioElement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use ipl\Html\HtmlElement;
99
use ipl\Html\Text;
1010
use ipl\I18n\Translation;
11+
use ipl\Stdlib\Option;
1112
use ipl\Validator\DeferredInArrayValidator;
1213
use ipl\Validator\ValidatorChain;
1314

@@ -31,6 +32,7 @@ class RadioElement extends BaseFormElement
3132
*
3233
* @return $this
3334
*/
35+
#[Option]
3436
public function setOptions(array $options): self
3537
{
3638
$this->options = [];
@@ -74,6 +76,7 @@ public function getOption($value): RadioOption
7476
*
7577
* @return $this
7678
*/
79+
#[Option]
7780
public function setDisabledOptions(array $disabledOptions): self
7881
{
7982
if (! empty($this->options)) {

src/FormElement/SelectElement.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace ipl\Html\FormElement;
44

5-
use InvalidArgumentException;
65
use ipl\Html\Attributes;
76
use ipl\Html\Common\MultipleAttribute;
87
use ipl\Html\Html;
98
use ipl\Html\HtmlElement;
9+
use ipl\Stdlib\Option;
1010
use ipl\Validator\DeferredInArrayValidator;
1111
use ipl\Validator\ValidatorChain;
1212
use UnexpectedValueException;
@@ -48,6 +48,7 @@ public function getOption($value): ?SelectOption
4848
*
4949
* @return $this
5050
*/
51+
#[Option(name: ['options', 'multiOptions'])]
5152
public function setOptions(array $options): self
5253
{
5354
$this->options = [];
@@ -66,6 +67,7 @@ public function setOptions(array $options): self
6667
*
6768
* @return $this
6869
*/
70+
#[Option]
6971
public function setDisabledOptions(array $disabledOptions): self
7072
{
7173
if (! empty($this->options)) {

src/FormElement/SubmitButtonElement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use ipl\Html\Attributes;
66
use ipl\Html\Contract\FormSubmitElement;
7+
use ipl\Stdlib\Option;
78

89
class SubmitButtonElement extends ButtonElement implements FormSubmitElement
910
{
@@ -29,6 +30,7 @@ public function getSubmitValue(): string
2930
*
3031
* @return $this
3132
*/
33+
#[Option(name: 'value')]
3234
public function setSubmitValue(string $value): self
3335
{
3436
$this->submitValue = $value;

src/FormElement/TextElement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace ipl\Html\FormElement;
44

55
use ipl\Html\Attributes;
6+
use ipl\Stdlib\Option;
67

78
class TextElement extends InputElement
89
{
910
protected $type = 'text';
1011

1112
/** @var ?string Placeholder text for the input */
13+
#[Option]
1214
protected ?string $placeholder = null;
1315

1416
/**

0 commit comments

Comments
 (0)