Generic
2 days ago
Options
2 days ago
ArrayMapper.php
2 days ago
Option.php
2 days ago
OptionGroup.php
2 days ago
Options.php
2 days ago
Paginated.php
2 days ago
Response.php
2 days ago
OptionGroup.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Helper\Select; |
| 6 | |
| 7 | final class OptionGroup |
| 8 | { |
| 9 | private string $label; |
| 10 | |
| 11 | /** |
| 12 | * @var Option[] |
| 13 | */ |
| 14 | private array $options = []; |
| 15 | |
| 16 | /** |
| 17 | * @param string $label |
| 18 | * @param Option[] $options |
| 19 | */ |
| 20 | public function __construct(string $label, array $options = []) |
| 21 | { |
| 22 | $this->label = $label; |
| 23 | |
| 24 | foreach ($options as $option) { |
| 25 | $this->add_option($option); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public function get_label(): string |
| 30 | { |
| 31 | return $this->label; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @return Option[] |
| 36 | */ |
| 37 | public function get_options(): array |
| 38 | { |
| 39 | return $this->options; |
| 40 | } |
| 41 | |
| 42 | protected function add_option(Option $option): self |
| 43 | { |
| 44 | $this->options[] = $option; |
| 45 | |
| 46 | return $this; |
| 47 | } |
| 48 | |
| 49 | } |
| 50 |