| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace LaravelUi5\OData\Protocol\Planning; |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | final readonly class ExpandPruner |
| 17: | { |
| 18: | |
| 19: | |
| 20: | |
| 21: | public static function prune(ExpandList $list, array $droppedSetNames): ExpandList |
| 22: | { |
| 23: | if ($list->isEmpty() || $droppedSetNames === []) { |
| 24: | return $list; |
| 25: | } |
| 26: | |
| 27: | $kept = []; |
| 28: | |
| 29: | foreach ($list->items as $item) { |
| 30: | if (in_array($item->targetSet->getName(), $droppedSetNames, true)) { |
| 31: | continue; |
| 32: | } |
| 33: | |
| 34: | $kept[] = $item->expand->isEmpty() |
| 35: | ? $item |
| 36: | : $item->withExpand(self::prune($item->expand, $droppedSetNames)); |
| 37: | } |
| 38: | |
| 39: | return new ExpandList($kept); |
| 40: | } |
| 41: | } |
| 42: | |