SortByLabel.php
27 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Table\TableScreenRepository; |
| 6 | |
| 7 | use AC\Table\TableScreenCollection; |
| 8 | use AC\TableScreen; |
| 9 | |
| 10 | class SortByLabel implements Sort |
| 11 | { |
| 12 | public function sort(TableScreenCollection $collection): TableScreenCollection |
| 13 | { |
| 14 | $screens = iterator_to_array($collection); |
| 15 | |
| 16 | uasort($screens, [$this, 'sort_by_label']); |
| 17 | |
| 18 | return new TableScreenCollection($screens); |
| 19 | } |
| 20 | |
| 21 | public function sort_by_label(TableScreen $a, TableScreen $b): int |
| 22 | { |
| 23 | return strnatcasecmp((string)$a->get_labels(), (string)$b->get_labels()); |
| 24 | } |
| 25 | |
| 26 | } |
| 27 |