| 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 |
* The response to a content suggestion request, bundling suggestions with the recent content used to generate them. |
| 7 |
*/ |
| 8 |
class Content_Suggestion_Response { |
| 9 |
|
| 10 |
/** |
| 11 |
* The content suggestions. |
| 12 |
* |
| 13 |
* @var Content_Suggestion_List |
| 14 |
*/ |
| 15 |
private $suggestions; |
| 16 |
|
| 17 |
/** |
| 18 |
* The recent content used to generate the suggestions. |
| 19 |
* |
| 20 |
* @var Post_List |
| 21 |
*/ |
| 22 |
private $recent_content; |
| 23 |
|
| 24 |
/** |
| 25 |
* The constructor. |
| 26 |
* |
| 27 |
* @param Content_Suggestion_List $suggestions The content suggestions. |
| 28 |
* @param Post_List $recent_content The recent content. |
| 29 |
*/ |
| 30 |
public function __construct( Content_Suggestion_List $suggestions, Post_List $recent_content ) { |
| 31 |
$this->suggestions = $suggestions; |
| 32 |
$this->recent_content = $recent_content; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Returns the content suggestions. |
| 37 |
* |
| 38 |
* @return Content_Suggestion_List The content suggestions. |
| 39 |
*/ |
| 40 |
public function get_suggestions(): Content_Suggestion_List { |
| 41 |
return $this->suggestions; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Returns the recent content. |
| 46 |
* |
| 47 |
* @return Post_List The recent content. |
| 48 |
*/ |
| 49 |
public function get_recent_content(): Post_List { |
| 50 |
return $this->recent_content; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Returns this object in array format. |
| 55 |
* |
| 56 |
* Uses the minimal Post representation so editor-only metadata |
| 57 |
* (focus keyphrase, cornerstone flag, schema type) never crosses |
| 58 |
* the REST boundary into the browser. |
| 59 |
* |
| 60 |
* @return array<string, array<array<string, string>>> The response as an array. |
| 61 |
*/ |
| 62 |
public function to_array(): array { |
| 63 |
$result = $this->suggestions->to_array(); |
| 64 |
$result['recent_content'] = $this->recent_content->to_minimal_array(); |
| 65 |
return $result; |
| 66 |
} |
| 67 |
} |
| 68 |
|