| 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 |
* @param string $value |
| 22 |
* @param ?string $label |
| 23 |
*/ |
| 24 |
public function __construct($value, $label = null) |
| 25 |
{ |
| 26 |
$this->value = $value; |
| 27 |
$this->label = $label; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Create a new option. |
| 32 |
* |
| 33 |
* @since 2.12.0 |
| 34 |
* |
| 35 |
* @return static |
| 36 |
*/ |
| 37 |
public static function make(...$args) |
| 38 |
{ |
| 39 |
return new static(...$args); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Access the value |
| 44 |
* |
| 45 |
* @since 2.12.0 |
| 46 |
* |
| 47 |
* @return string |
| 48 |
*/ |
| 49 |
public function getValue() |
| 50 |
{ |
| 51 |
return $this->value; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* {@inheritdoc} |
| 56 |
*/ |
| 57 |
public function jsonSerialize() |
| 58 |
{ |
| 59 |
return [ |
| 60 |
'value' => $this->getValue(), |
| 61 |
'label' => $this->getLabel(), |
| 62 |
]; |
| 63 |
} |
| 64 |
} |
| 65 |
|