Concerns
4 years ago
Contracts
4 years ago
Exceptions
4 years ago
Facades
4 years ago
FormFieldMediator
5 years ago
Checkbox.php
4 years ago
Date.php
4 years ago
Element.php
4 years ago
Email.php
4 years ago
Factory.php
4 years ago
Field.php
4 years ago
File.php
4 years ago
Form.php
4 years ago
Group.php
4 years ago
Hidden.php
4 years ago
Html.php
4 years ago
Option.php
4 years ago
Phone.php
4 years ago
Radio.php
4 years ago
Select.php
4 years ago
Text.php
4 years ago
Textarea.php
4 years ago
Types.php
4 years ago
Url.php
4 years ago
Option.php
60 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 | use Concerns\HasLabel; |
| 15 | |
| 16 | /** @var string */ |
| 17 | protected $value; |
| 18 | |
| 19 | /** |
| 20 | * @param string $value |
| 21 | * @param ?string $label |
| 22 | */ |
| 23 | public function __construct( $value, $label = null ) { |
| 24 | $this->value = $value; |
| 25 | $this->label = $label; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Create a new option. |
| 30 | * |
| 31 | * @since 2.12.0 |
| 32 | * |
| 33 | * @return static |
| 34 | */ |
| 35 | public static function make( ...$args ) { |
| 36 | return new static( ...$args ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Access the value |
| 41 | * |
| 42 | * @since 2.12.0 |
| 43 | * |
| 44 | * @return string |
| 45 | */ |
| 46 | public function getValue() { |
| 47 | return $this->value; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * {@inheritdoc} |
| 52 | */ |
| 53 | public function jsonSerialize() { |
| 54 | return [ |
| 55 | 'value' => $this->getValue(), |
| 56 | 'label' => $this->getLabel(), |
| 57 | ]; |
| 58 | } |
| 59 | } |
| 60 |