| 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 |
* Value object for a Post. |
| 7 |
*/ |
| 8 |
class Post { |
| 9 |
|
| 10 |
/** |
| 11 |
* The title. |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
private $title; |
| 16 |
|
| 17 |
/** |
| 18 |
* The description. |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
private $description; |
| 23 |
|
| 24 |
/** |
| 25 |
* The category. |
| 26 |
* |
| 27 |
* @var Category|null |
| 28 |
*/ |
| 29 |
private $category; |
| 30 |
|
| 31 |
/** |
| 32 |
* The primary focus keyword. |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
private $primary_focus_keyword; |
| 37 |
|
| 38 |
/** |
| 39 |
* Whether the post is cornerstone content. |
| 40 |
* |
| 41 |
* @var bool |
| 42 |
*/ |
| 43 |
private $is_cornerstone; |
| 44 |
|
| 45 |
/** |
| 46 |
* The last modified date. |
| 47 |
* |
| 48 |
* @var string |
| 49 |
*/ |
| 50 |
private $last_modified; |
| 51 |
|
| 52 |
/** |
| 53 |
* The schema article type. |
| 54 |
* |
| 55 |
* @var string |
| 56 |
*/ |
| 57 |
private $schema_article_type; |
| 58 |
|
| 59 |
/** |
| 60 |
* The constructor. |
| 61 |
* |
| 62 |
* @param string $title The title. |
| 63 |
* @param string $description The description. |
| 64 |
* @param ?Category $category The category, or null if the post has no category. |
| 65 |
* @param string $primary_focus_keyword The primary focus keyword. |
| 66 |
* @param int $is_cornerstone Whether the post is cornerstone content. |
| 67 |
* @param string $last_modified The last modified date. |
| 68 |
* @param ?string $schema_article_type The schema article type. |
| 69 |
*/ |
| 70 |
public function __construct( |
| 71 |
string $title, |
| 72 |
string $description, |
| 73 |
?Category $category, |
| 74 |
string $primary_focus_keyword, |
| 75 |
int $is_cornerstone, |
| 76 |
string $last_modified, |
| 77 |
?string $schema_article_type |
| 78 |
) { |
| 79 |
$this->title = $title; |
| 80 |
$this->description = $description; |
| 81 |
$this->category = $category; |
| 82 |
$this->primary_focus_keyword = $primary_focus_keyword; |
| 83 |
$this->is_cornerstone = $is_cornerstone; |
| 84 |
$this->last_modified = $last_modified; |
| 85 |
$this->schema_article_type = $schema_article_type; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Returns this object in array format. |
| 90 |
* |
| 91 |
* @return array<string, string|bool|array<string, int>> The post as an array. |
| 92 |
*/ |
| 93 |
public function to_array(): array { |
| 94 |
$data = [ |
| 95 |
'title' => $this->title, |
| 96 |
'description' => $this->description, |
| 97 |
'category' => isset( $this->category ) ? $this->category->to_array() : null, |
| 98 |
'primary_focus_keyword' => $this->primary_focus_keyword, |
| 99 |
'is_cornerstone' => $this->is_cornerstone, |
| 100 |
'last_modified' => $this->last_modified, |
| 101 |
]; |
| 102 |
if ( isset( $this->schema_article_type ) ) { |
| 103 |
$data['schema_article_type'] = $this->schema_article_type; |
| 104 |
} |
| 105 |
|
| 106 |
return $data; |
| 107 |
} |
| 108 |
} |
| 109 |
|