Aggregate.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\TableIdsFactory; |
| 6 | |
| 7 | use AC\TableIdsFactory; |
| 8 | use AC\Type\TableIdCollection; |
| 9 | |
| 10 | class Aggregate implements TableIdsFactory |
| 11 | { |
| 12 | /** |
| 13 | * @var TableIdsFactory[] |
| 14 | */ |
| 15 | private static array $factories = []; |
| 16 | |
| 17 | public static function add(TableIdsFactory $factory): void |
| 18 | { |
| 19 | array_unshift(self::$factories, $factory); |
| 20 | } |
| 21 | |
| 22 | public function create(): TableIdCollection |
| 23 | { |
| 24 | $ids = new TableIdCollection(); |
| 25 | |
| 26 | foreach (self::$factories as $factory) { |
| 27 | foreach ($factory->create() as $table_id) { |
| 28 | if ($ids->contains($table_id)) { |
| 29 | continue; |
| 30 | } |
| 31 | |
| 32 | $ids->add($table_id); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return $ids; |
| 37 | } |
| 38 | |
| 39 | } |
| 40 |