Label.php
28 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\ListScreenRepository\Sort; |
| 6 | |
| 7 | use AC\ListScreenCollection; |
| 8 | use AC\ListScreenRepository\Sort; |
| 9 | |
| 10 | class Label implements Sort |
| 11 | { |
| 12 | public function sort(ListScreenCollection $list_screens): ListScreenCollection |
| 13 | { |
| 14 | $labels = []; |
| 15 | |
| 16 | foreach ($list_screens as $list_screen) { |
| 17 | $labels[$list_screen->get_label()][] = $list_screen; |
| 18 | } |
| 19 | |
| 20 | ksort($labels); |
| 21 | |
| 22 | $labels = array_values($labels); |
| 23 | |
| 24 | return new ListScreenCollection(array_merge([], ...$labels)); |
| 25 | } |
| 26 | |
| 27 | } |
| 28 |