PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / ai / content-planner / domain / post.php

post.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/ai/content-planner/domain/post.php

125 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
110 * Returns the minimal array representation suitable for the REST response.
111 *
112 * Only includes fields the frontend round-trips into the get_outline call.
113 * Excludes editor-only metadata (focus keyphrase, cornerstone, schema type)
114 * that must not cross the REST boundary.
115 *
116 * @return array<string, string> The minimal post payload.
117 */
118 public function to_minimal_array(): array {
119 return [
120 'title' => $this->title,
121 'description' => $this->description,
122 ];
123 }
124 }
125