← All changes
|
src/schema-aggregator/user-interface/site-schema-aggregator-xml-route.php
+10
-52
28.2
→
trunk
View file →
| @@ -1,17 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 | 3 | namespace Yoast\WP\SEO\Schema_Aggregator\User_Interface; |
| 4 | 4 | |
| 5 | -use WP_Error; | |
| 6 | 5 | use WP_REST_Response; |
| 7 | 6 | use Yoast\WP\SEO\Main; |
| 8 | 7 | use Yoast\WP\SEO\Routes\Route_Interface; |
| 9 | -use Yoast\WP\SEO\Schema_Aggregator\Application\Aggregate_Site_Schema_Map_Command; | |
| 10 | -use Yoast\WP\SEO\Schema_Aggregator\Application\Aggregate_Site_Schema_Map_Command_Handler; | |
| 11 | -use Yoast\WP\SEO\Schema_Aggregator\Application\Cache\Xml_Manager; | |
| 12 | -use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Aggregator_Config; | |
| 13 | -use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Config; | |
| 8 | +use Yoast\WP\SEO\Schema_Aggregator\Application\Schema_Map\Schema_Map_Xml_Provider; | |
| 14 | 9 | use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Aggregator_Conditional; |
| 15 | 10 | |
| 16 | 11 | /** |
| 17 | 12 | * Handles the route to represent all indexable post types as XML. |
| @@ -33,29 +28,15 @@ | ||
| 33 | 28 | */ |
| 34 | 29 | public const GET_SCHEMA_ROUTE = self::ROUTE_PREFIX . '/get-xml'; |
| 35 | 30 | |
| 36 | 31 | /** |
| 37 | - * The command handler instance. | |
| 32 | + * The schema map XML provider. | |
| 38 | 33 | * |
| 39 | - * @var Aggregate_Site_Schema_Map_Command_Handler | |
| 34 | + * @var Schema_Map_Xml_Provider | |
| 40 | 35 | */ |
| 41 | - private $aggregate_site_schema_map_command_handler; | |
| 36 | + private $schema_map_xml_provider; | |
| 42 | 37 | |
| 43 | 38 | /** |
| 44 | - * The XML cache manager instance. | |
| 45 | - * | |
| 46 | - * @var Xml_Manager | |
| 47 | - */ | |
| 48 | - private $xml_cache_manager; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * The aggregator configuration instance. | |
| 52 | - * | |
| 53 | - * @var Aggregator_Config | |
| 54 | - */ | |
| 55 | - private $aggregator_config; | |
| 56 | - | |
| 57 | - /** | |
| 58 | 39 | * Returns the conditional for this route. |
| 59 | 40 | * |
| 60 | 41 | * @return array<string> The conditionals that must be met to load this. |
| 61 | 42 | */ |
| @@ -65,22 +46,12 @@ | ||
| 65 | 46 | |
| 66 | 47 | /** |
| 67 | 48 | * Site_Schema_Aggregator_Route constructor. |
| 68 | 49 | * |
| 69 | - * @param Aggregate_Site_Schema_Map_Command_Handler $aggregate_site_schema_map_command_handler The command handler. | |
| 70 | - * @param Xml_Manager $xml_cache_manager The XML cache | |
| 71 | - * manager. | |
| 72 | - * @param Aggregator_Config $aggregator_config The aggregator | |
| 73 | - * configuration. | |
| 50 | + * @param Schema_Map_Xml_Provider $schema_map_xml_provider The schema map XML provider. | |
| 74 | 51 | */ |
| 75 | - public function __construct( | |
| 76 | - Aggregate_Site_Schema_Map_Command_Handler $aggregate_site_schema_map_command_handler, | |
| 77 | - Xml_Manager $xml_cache_manager, | |
| 78 | - Aggregator_Config $aggregator_config | |
| 79 | - ) { | |
| 80 | - $this->aggregate_site_schema_map_command_handler = $aggregate_site_schema_map_command_handler; | |
| 81 | - $this->xml_cache_manager = $xml_cache_manager; | |
| 82 | - $this->aggregator_config = $aggregator_config; | |
| 52 | + public function __construct( Schema_Map_Xml_Provider $schema_map_xml_provider ) { | |
| 53 | + $this->schema_map_xml_provider = $schema_map_xml_provider; | |
| 83 | 54 | } |
| 84 | 55 | |
| 85 | 56 | /** |
| 86 | 57 | * Registers routes with WordPress. |
| @@ -108,27 +79,14 @@ | ||
| 108 | 79 | return true; |
| 109 | 80 | } |
| 110 | 81 | |
| 111 | 82 | /** |
| 112 | - * Returns a XML representation of the possible post types that can be used for schema. | |
| 83 | + * Returns a XML representation of the post types that are used for schema. | |
| 113 | 84 | * |
| 114 | - * @return WP_REST_Response|WP_Error The success or failure response. | |
| 85 | + * @return WP_REST_Response The response. | |
| 115 | 86 | */ |
| 116 | 87 | public function render_schema_xml() { |
| 117 | - $cached_xml = $this->xml_cache_manager->get(); | |
| 118 | - if ( $cached_xml !== null ) { | |
| 119 | - $xml = $cached_xml; | |
| 120 | - } | |
| 121 | - else { | |
| 122 | - | |
| 123 | - $post_types = $this->aggregator_config->get_allowed_post_types(); | |
| 124 | - | |
| 125 | - $command = new Aggregate_Site_Schema_Map_Command( $post_types ); | |
| 126 | - $xml = $this->aggregate_site_schema_map_command_handler->handle( $command ); | |
| 127 | - | |
| 128 | - $this->xml_cache_manager->set( $xml ); | |
| 129 | - } | |
| 130 | - $response = new WP_REST_Response( $xml, 200 ); | |
| 88 | + $response = new WP_REST_Response( $this->schema_map_xml_provider->get_xml(), 200 ); | |
| 131 | 89 | $response->header( 'Content-Type', 'application/xml; charset=UTF-8' ); |
| 132 | 90 | $response->header( 'Cache-Control', 'public, max-age=300' ); |
| 133 | 91 | |
| 134 | 92 | return $response; |