BaseFactory.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\TableIdsFactory; |
| 6 | |
| 7 | use AC\PostTypeRepository; |
| 8 | use AC\TableIdsFactory; |
| 9 | use AC\Type\TableId; |
| 10 | use AC\Type\TableIdCollection; |
| 11 | |
| 12 | class BaseFactory implements TableIdsFactory |
| 13 | { |
| 14 | |
| 15 | private PostTypeRepository $post_type_repository; |
| 16 | |
| 17 | public function __construct(PostTypeRepository $post_type_repository) |
| 18 | { |
| 19 | $this->post_type_repository = $post_type_repository; |
| 20 | } |
| 21 | |
| 22 | public function create(): TableIdCollection |
| 23 | { |
| 24 | $keys = $this->post_type_repository->find_all(); |
| 25 | |
| 26 | $keys[] = 'wp-comments'; |
| 27 | $keys[] = 'wp-users'; |
| 28 | $keys[] = 'wp-media'; |
| 29 | |
| 30 | $collection = new TableIdCollection(); |
| 31 | |
| 32 | foreach ($keys as $key) { |
| 33 | $collection->add(new TableId($key)); |
| 34 | } |
| 35 | |
| 36 | return $collection; |
| 37 | } |
| 38 | |
| 39 | } |