PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.5
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 / schema-aggregator / domain / schema-piece.php

schema-piece.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.5, at src/schema-aggregator/domain/schema-piece.php

74 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Schema_Aggregator\Domain;
5
6 /**
7 * Represents a piece of schema.org data.
8 */
9 class Schema_Piece {
10
11 /**
12 * The type(s) of the schema piece.
13 *
14 * @var string|array<string>
15 */
16 private $type;
17
18 /**
19 * The data of the schema piece.
20 *
21 * @var array<string, string|int|bool>
22 */
23 private $data;
24
25 /**
26 * Class constructor.
27 *
28 * @param array<string, string|int|bool> $data The data of the schema piece.
29 * @param string|array<string> $type The type of the schema piece.
30 */
31 public function __construct( array $data, $type ) {
32 $this->data = $data;
33 $this->type = $type;
34 }
35
36 /**
37 * Gets the type of the schema piece.
38 *
39 * @return string|array<string> The type(s) of the schema piece.
40 */
41 public function get_type() {
42 return $this->type;
43 }
44
45 /**
46 * Gets the data of the schema piece.
47 *
48 * @return array<string, string|int|bool> The data of the schema piece.
49 */
50 public function get_data(): array {
51 return $this->data;
52 }
53
54 /**
55 * Gets the ID of the schema piece.
56 *
57 * @return string|null The ID of the schema piece, or null if not set.
58 */
59 public function get_id(): ?string {
60 return ( $this->data['@id'] ?? null );
61 }
62
63 /**
64 * Converts multiple schema pieces to a JSON-LD-encoded graph.
65 *
66 * @return array<string, string|int|bool> The JSON-LD graph representation.
67 */
68 public function to_json_ld_graph(): array {
69 return [
70 '@graph' => $this->data,
71 ];
72 }
73 }
74