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 / schema-aggregator / application / schema_map / schema-map-xml-provider.php

schema-map-xml-provider.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/schema-aggregator/application/schema_map/schema-map-xml-provider.php

74 lines 2.5 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\Schema_Map;
4
5 use Yoast\WP\SEO\Schema_Aggregator\Application\Aggregate_Site_Schema_Map_Command;
6 use Yoast\WP\SEO\Schema_Aggregator\Application\Aggregate_Site_Schema_Map_Command_Handler;
7 use Yoast\WP\SEO\Schema_Aggregator\Application\Cache\Xml_Manager;
8 use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Aggregator_Config;
9
10 /**
11 * Provides the schema map XML, building and caching it when needed.
12 */
13 class Schema_Map_Xml_Provider {
14
15 /**
16 * The command handler instance.
17 *
18 * @var Aggregate_Site_Schema_Map_Command_Handler
19 */
20 private $aggregate_site_schema_map_command_handler;
21
22 /**
23 * The XML cache manager instance.
24 *
25 * @var Xml_Manager
26 */
27 private $xml_cache_manager;
28
29 /**
30 * The aggregator configuration instance.
31 *
32 * @var Aggregator_Config
33 */
34 private $aggregator_config;
35
36 /**
37 * Schema_Map_Xml_Provider constructor.
38 *
39 * @param Aggregate_Site_Schema_Map_Command_Handler $aggregate_site_schema_map_command_handler The command handler.
40 * @param Xml_Manager $xml_cache_manager The XML cache
41 * manager.
42 * @param Aggregator_Config $aggregator_config The aggregator
43 * configuration.
44 */
45 public function __construct(
46 Aggregate_Site_Schema_Map_Command_Handler $aggregate_site_schema_map_command_handler,
47 Xml_Manager $xml_cache_manager,
48 Aggregator_Config $aggregator_config
49 ) {
50 $this->aggregate_site_schema_map_command_handler = $aggregate_site_schema_map_command_handler;
51 $this->xml_cache_manager = $xml_cache_manager;
52 $this->aggregator_config = $aggregator_config;
53 }
54
55 /**
56 * Returns the schema map XML, building and caching it when it is not cached yet.
57 *
58 * @return string The schema map XML.
59 */
60 public function get_xml(): string {
61 $cached_xml = $this->xml_cache_manager->get();
62 if ( $cached_xml !== null ) {
63 return $cached_xml;
64 }
65
66 $command = new Aggregate_Site_Schema_Map_Command( $this->aggregator_config->get_allowed_post_types() );
67 $xml = $this->aggregate_site_schema_map_command_handler->handle( $command );
68
69 $this->xml_cache_manager->set( $xml );
70
71 return $xml;
72 }
73 }
74