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