wordpress-seo
/
src
/
schema-aggregator
/
infrastructure
/
schema_map
/
schema-map-repository-factory.php
schema-map-repository-factory.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/schema-aggregator/infrastructure/schema_map/schema-map-repository-factory.php
| 1 | <?php |
| 2 | // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 | namespace Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Map; |
| 4 | |
| 5 | /** |
| 6 | * Factory for getting the amount of posts per post type. |
| 7 | */ |
| 8 | class Schema_Map_Repository_Factory { |
| 9 | |
| 10 | /** |
| 11 | * The native indexable repository. |
| 12 | * |
| 13 | * @var Schema_Map_Indexable_Repository |
| 14 | */ |
| 15 | private $native_repository; |
| 16 | |
| 17 | /** |
| 18 | * The WordPress indexable repository. |
| 19 | * |
| 20 | * @var Schema_Map_WordPress_Repository |
| 21 | */ |
| 22 | private $wordpress_repository; |
| 23 | |
| 24 | /** |
| 25 | * Constructor. |
| 26 | * |
| 27 | * @param Schema_Map_Indexable_Repository $native_repository The native indexable repository. |
| 28 | * @param Schema_Map_WordPress_Repository $wordpress_repository The WordPress indexable repository. |
| 29 | */ |
| 30 | public function __construct( |
| 31 | Schema_Map_Indexable_Repository $native_repository, |
| 32 | Schema_Map_WordPress_Repository $wordpress_repository |
| 33 | ) { |
| 34 | $this->native_repository = $native_repository; |
| 35 | $this->wordpress_repository = $wordpress_repository; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Gets the appropriate indexable repository based on availability. |
| 40 | * |
| 41 | * @param bool $indexables_available Whether native indexables are available. |
| 42 | * |
| 43 | * @return Schema_Map_Repository_Interface The selected indexable repository. |
| 44 | */ |
| 45 | public function get_repository( bool $indexables_available ): Schema_Map_Repository_Interface { |
| 46 | if ( $indexables_available ) { |
| 47 | return $this->native_repository; |
| 48 | } |
| 49 | |
| 50 | return $this->wordpress_repository; |
| 51 | } |
| 52 | } |
| 53 |