PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
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 / application / aggregate-site-schema-map-command-handler.php

aggregate-site-schema-map-command-handler.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/schema-aggregator/application/aggregate-site-schema-map-command-handler.php

79 lines 2.7 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\Schema_Aggregator\Application;
4
5 use Yoast\WP\SEO\Helpers\Indexable_Helper;
6 use Yoast\WP\SEO\Schema_Aggregator\Application\Schema_Map\Schema_Map_Builder;
7 use Yoast\WP\SEO\Schema_Aggregator\Application\Schema_Map\Schema_Map_Xml_Renderer;
8 use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Map\Schema_Map_Repository_Factory;
9
10 /**
11 * Class that handles the command to aggregate site schema map.
12 *
13 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
14 */
15 class Aggregate_Site_Schema_Map_Command_Handler {
16
17 /**
18 * The schema map factory.
19 *
20 * @var Schema_Map_Repository_Factory
21 */
22 private $schema_map_repository_factory;
23
24 /**
25 * The schema map builder.
26 *
27 * @var Schema_Map_Builder
28 */
29 private $schema_map_builder;
30
31 /**
32 * The schema map XML renderer.
33 *
34 * @var Schema_Map_Xml_Renderer
35 */
36 private $schema_map_xml_renderer;
37
38 /**
39 * The indexable helper.
40 *
41 * @var Indexable_Helper
42 */
43 private $indexable_helper;
44
45 /**
46 * Aggregate_Site_Schema_Map_Command_Handler constructor.
47 *
48 * @param Schema_Map_Repository_Factory $schema_map_repository_factory The schema map factory.
49 * @param Schema_Map_Builder $schema_map_builder The schema map builder.
50 * @param Schema_Map_Xml_Renderer $schema_map_xml_renderer The schema map XML renderer.
51 * @param Indexable_Helper $indexable_helper The indexable helper.
52 */
53 public function __construct( Schema_Map_Repository_Factory $schema_map_repository_factory, Schema_Map_Builder $schema_map_builder, Schema_Map_Xml_Renderer $schema_map_xml_renderer, Indexable_Helper $indexable_helper ) {
54 $this->schema_map_repository_factory = $schema_map_repository_factory;
55 $this->schema_map_builder = $schema_map_builder;
56 $this->schema_map_xml_renderer = $schema_map_xml_renderer;
57 $this->indexable_helper = $indexable_helper;
58 }
59
60 /**
61 * Handles the Aggregate_Site_Schema_Map_Command.
62 *
63 * @param Aggregate_Site_Schema_Map_Command $command The command.
64 *
65 * @return string The schema map xml.
66 */
67 public function handle( Aggregate_Site_Schema_Map_Command $command ): string {
68
69 $schema_map_repository = $this->schema_map_repository_factory->get_repository( $this->indexable_helper->should_index_indexables() );
70 $indexable_counts = $schema_map_repository->get_indexable_count_per_post_type( $command->get_post_types() );
71
72 $schema_map = $this->schema_map_builder
73 ->with_repository( $schema_map_repository )
74 ->build( $indexable_counts );
75
76 return $this->schema_map_xml_renderer->render( $schema_map );
77 }
78 }
79