| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
namespace Yoast\WP\SEO\AI\Content_Planner\Domain; |
| 4 |
|
| 5 |
/** |
| 6 |
* List of posts. |
| 7 |
*/ |
| 8 |
class Post_List { |
| 9 |
|
| 10 |
/** |
| 11 |
* The posts. |
| 12 |
* |
| 13 |
* @var array<Post> |
| 14 |
*/ |
| 15 |
private $posts = []; |
| 16 |
|
| 17 |
/** |
| 18 |
* Adds a post to the list. |
| 19 |
* |
| 20 |
* @param Post $post A post. |
| 21 |
* |
| 22 |
* @return void |
| 23 |
*/ |
| 24 |
public function add( Post $post ): void { |
| 25 |
$this->posts[] = $post; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Returns this object in array format. |
| 30 |
* |
| 31 |
* @return array<array<string, string|bool|array<string, int>>> The posts as an array. |
| 32 |
*/ |
| 33 |
public function to_array(): array { |
| 34 |
$result = []; |
| 35 |
foreach ( $this->posts as $post ) { |
| 36 |
$result[] = $post->to_array(); |
| 37 |
} |
| 38 |
|
| 39 |
return $result; |
| 40 |
} |
| 41 |
} |
| 42 |
|