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
ArrayMapper.php
31 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Helper\Select; |
| 6 | |
| 7 | final class ArrayMapper |
| 8 | { |
| 9 | public static function map(Options $options): array |
| 10 | { |
| 11 | $items = []; |
| 12 | |
| 13 | foreach ($options as $option) { |
| 14 | $item = [ |
| 15 | 'text' => $option->get_label(), |
| 16 | ]; |
| 17 | |
| 18 | if ($option instanceof OptionGroup) { |
| 19 | $item['children'] = self::map(new Options($option->get_options())); |
| 20 | } else { |
| 21 | $item['id'] = $option->get_value(); |
| 22 | } |
| 23 | |
| 24 | $items[] = $item; |
| 25 | } |
| 26 | |
| 27 | return $items; |
| 28 | } |
| 29 | |
| 30 | } |
| 31 |