wordpress-seo
/
src
/
schema-aggregator
/
infrastructure
/
elements-context-map
/
elements-context-map-repository.php
elements-context-map-repository.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/schema-aggregator/infrastructure/elements-context-map/elements-context-map-repository.php
| 1 | <?php |
| 2 | // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 | namespace Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Elements_Context_Map; |
| 4 | |
| 5 | /** |
| 6 | * Repository for the elements-context map. |
| 7 | */ |
| 8 | class Elements_Context_Map_Repository implements Elements_Context_Map_Repository_Interface { |
| 9 | |
| 10 | /** |
| 11 | * The elements-context map. |
| 12 | * |
| 13 | * @var array<array<string, string>>|null |
| 14 | */ |
| 15 | private $map = null; |
| 16 | |
| 17 | /** |
| 18 | * The map loader strategy. |
| 19 | * |
| 20 | * @var Map_Loader_Interface |
| 21 | */ |
| 22 | private $map_loader; |
| 23 | |
| 24 | /** |
| 25 | * Constructor. |
| 26 | * |
| 27 | * @param Map_Loader_Interface $map_loader The map loader strategy. |
| 28 | */ |
| 29 | public function __construct( Map_Loader_Interface $map_loader ) { |
| 30 | $this->map_loader = $map_loader; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Retrieves the elements-context map. |
| 35 | * |
| 36 | * @return array<array<string, string>> The elements context-map. |
| 37 | */ |
| 38 | public function get_map(): array { |
| 39 | $this->map ??= $this->map_loader->load(); |
| 40 | return $this->map; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Saves the elements-context map. |
| 45 | * |
| 46 | * @codeCoverageIgnore -- This is just a setter. |
| 47 | * |
| 48 | * @param array<array<string, string>> $map The elements-context map to besaved. |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | public function save_map( array $map ): void { |
| 53 | $this->map = $map; |
| 54 | } |
| 55 | } |
| 56 |