Actions
2 years ago
Concerns
2 years ago
Contracts
3 years ago
Exceptions
2 years ago
Facades
4 years ago
LegacyNodes
3 years ago
Properties
2 years ago
ValueObjects
2 years ago
Amount.php
2 years ago
Authentication.php
2 years ago
BillingAddress.php
2 years ago
Checkbox.php
2 years ago
Consent.php
2 years ago
Date.php
2 years ago
DonationAmount.php
2 years ago
DonationForm.php
2 years ago
DonationSummary.php
2 years ago
Element.php
3 years ago
Email.php
2 years ago
Factory.php
4 years ago
Field.php
2 years ago
File.php
2 years ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
3 years ago
Html.php
3 years ago
MultiSelect.php
2 years ago
Name.php
2 years ago
Option.php
2 years ago
Paragraph.php
2 years ago
Password.php
2 years ago
PaymentGateways.php
2 years ago
Phone.php
2 years ago
Radio.php
2 years ago
Section.php
2 years ago
Select.php
2 years ago
Text.php
2 years ago
Textarea.php
2 years ago
Types.php
2 years ago
Url.php
2 years ago
Option.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | use JsonSerializable; |
| 6 | |
| 7 | /** |
| 8 | * Class Option |
| 9 | * |
| 10 | * @since 2.12.0 |
| 11 | */ |
| 12 | class Option implements JsonSerializable |
| 13 | { |
| 14 | |
| 15 | use Concerns\HasLabel; |
| 16 | |
| 17 | /** @var string */ |
| 18 | protected $value; |
| 19 | |
| 20 | /** |
| 21 | * @since 2.23.1 Make constructor final to avoid unsafe usage of `new static()`. |
| 22 | * |
| 23 | * @param string $value |
| 24 | * @param ?string $label |
| 25 | */ |
| 26 | final public function __construct($value, $label = null) |
| 27 | { |
| 28 | $this->value = $value; |
| 29 | $this->label = $label; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Create a new option. |
| 34 | * |
| 35 | * @since 2.12.0 |
| 36 | * |
| 37 | * @return static |
| 38 | */ |
| 39 | public static function make(...$args) |
| 40 | { |
| 41 | return new static(...$args); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Access the value |
| 46 | * |
| 47 | * @since 2.12.0 |
| 48 | * |
| 49 | * @return string |
| 50 | */ |
| 51 | public function getValue() |
| 52 | { |
| 53 | return $this->value; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * {@inheritdoc} |
| 58 | */ |
| 59 | #[\ReturnTypeWillChange] |
| 60 | public function jsonSerialize() |
| 61 | { |
| 62 | return [ |
| 63 | 'value' => $this->getValue(), |
| 64 | 'label' => $this->getLabel(), |
| 65 | ]; |
| 66 | } |
| 67 | } |
| 68 |