wordpress-seo
/
src
/
schema-aggregator
/
application
/
enhancement
/
schema-enhancement-factory.php
schema-enhancement-factory.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.7, at src/schema-aggregator/application/enhancement/schema-enhancement-factory.php
| 1 | <?php |
| 2 | // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 | namespace Yoast\WP\SEO\Schema_Aggregator\Application\Enhancement; |
| 4 | |
| 5 | use Yoast\WP\SEO\Schema_Aggregator\Domain\Enhancement\Schema_Enhancement_Interface; |
| 6 | |
| 7 | /** |
| 8 | * The Schema_Enhancement_Factory. |
| 9 | */ |
| 10 | class Schema_Enhancement_Factory { |
| 11 | |
| 12 | /** |
| 13 | * The schema enhancer. |
| 14 | * |
| 15 | * @var Article_Schema_Enhancer |
| 16 | */ |
| 17 | private $article_schema_enhancer; |
| 18 | |
| 19 | /** |
| 20 | * The person schema enhancer. |
| 21 | * |
| 22 | * @var Person_Schema_Enhancer |
| 23 | */ |
| 24 | private $person_schema_enhancer; |
| 25 | |
| 26 | /** |
| 27 | * Constructor. |
| 28 | * |
| 29 | * @param Article_Schema_Enhancer $article_schema_enhancer The article schema enhancer. |
| 30 | * @param Person_Schema_Enhancer $person_schema_enhancer The person schema enhancer. |
| 31 | */ |
| 32 | public function __construct( |
| 33 | Article_Schema_Enhancer $article_schema_enhancer, |
| 34 | Person_Schema_Enhancer $person_schema_enhancer |
| 35 | ) { |
| 36 | $this->article_schema_enhancer = $article_schema_enhancer; |
| 37 | $this->person_schema_enhancer = $person_schema_enhancer; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns the appropriate schema enhancer based on the schema type. |
| 42 | * |
| 43 | * @param array<string> $schema_types The types of schema (e.g., 'Article', 'Person'). |
| 44 | * |
| 45 | * @return Schema_Enhancement_Interface|null The corresponding schema enhancer or null if none exists. |
| 46 | */ |
| 47 | public function get_enhancer( array $schema_types ): ?Schema_Enhancement_Interface { |
| 48 | foreach ( $schema_types as $schema_type_value ) { |
| 49 | switch ( $schema_type_value ) { |
| 50 | case 'Article': |
| 51 | return $this->article_schema_enhancer; |
| 52 | case 'Person': |
| 53 | return $this->person_schema_enhancer; |
| 54 | default: |
| 55 | return null; // No enhancer available for the given schema type. |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 |