| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
namespace Yoast\WP\SEO\Schema_Aggregator\Application; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Schema_Aggregator\Domain\Schema_Piece_Collection; |
| 6 |
|
| 7 |
/** |
| 8 |
* Class Schema_Aggregator_Response_Composer |
| 9 |
* |
| 10 |
* Composes the final schema response. |
| 11 |
*/ |
| 12 |
class Schema_Aggregator_Response_Composer { |
| 13 |
|
| 14 |
/** |
| 15 |
* Composes the final schema response. |
| 16 |
* |
| 17 |
* @param Schema_Piece_Collection $schema_pieces The schema pieces to include in the response. |
| 18 |
* |
| 19 |
* @return array<string> The composed schema response. |
| 20 |
*/ |
| 21 |
public function compose( Schema_Piece_Collection $schema_pieces ): array { |
| 22 |
$composed_pieces = []; |
| 23 |
foreach ( $schema_pieces->to_array() as $piece ) { |
| 24 |
$composed_pieces[] = \array_merge( |
| 25 |
[ |
| 26 |
'@context' => 'https://schema.org', |
| 27 |
], |
| 28 |
$piece->get_data(), |
| 29 |
); |
| 30 |
} |
| 31 |
return $composed_pieces; |
| 32 |
} |
| 33 |
} |
| 34 |
|