@param list ,aggregation:string}> $projection */
(mixed $sort, FlexibleColumnResolver $resolver, array $projection)
| 724 | |
| 725 | /** @param list<array{column:array<string,mixed>,aggregation:string}> $projection */ |
| 726 | private function resolveSort(mixed $sort, FlexibleColumnResolver $resolver, array $projection): array { |
| 727 | if (!is_array($sort)) { |
| 728 | throw new FlexibleStorageException('invalid_sort', 'Sort options must be an array.'); |
| 729 | } |
| 730 | $selected = array_column(array_column($projection, 'column'), 'ref'); |
| 731 | $result = []; |
| 732 | foreach ($sort as $index => $item) { |
| 733 | if (!is_array($item)) { |
| 734 | throw new FlexibleStorageException('invalid_sort', 'Each sort option must be an object.', ['sort' => $index]); |
| 735 | } |
| 736 | $column = $resolver->resolve((string)($item['column'] ?? '')); |
| 737 | if (!in_array($column['ref'], $selected, true)) { |
| 738 | throw new FlexibleStorageException('invalid_sort', 'Sorting requires the column to be projected.', ['column' => $column['ref']]); |
| 739 | } |
| 740 | $direction = strtoupper((string)($item['direction'] ?? 'ASC')); |
| 741 | if (!in_array($direction, ['ASC', 'DESC'], true)) { |
| 742 | throw new FlexibleStorageException('invalid_sort', 'Sort direction must be ASC or DESC.', ['sort' => $index]); |
| 743 | } |
| 744 | $result[] = ['column' => $column, 'direction' => $direction]; |
| 745 | } |
| 746 | return $result; |
| 747 | } |
| 748 | |
| 749 | /** @param list<array{column:array<string,mixed>,aggregation:string}> $projection */ |
| 750 | private function resolveTimeAggregation(mixed $option, FlexibleColumnResolver $resolver, array $projection, bool $aggregate): ?array { |