fully qualified class name. */ private const MAP = array( 'description' => SectionGenerator::class, 'taxonomy' => SectionGenerator::class, 'title' => TitleGenerator::class, 'seo_meta' => SeoMetaGenerator::class, 'faq' => FaqGenerator::class, 'image_alt' => ImageAltGenerator::class, ); /** * Class name for a generator key, or '' when unknown. * * @param string $generator Generator key. * @return string */ public static function classFor( string $generator ): string { return isset( self::MAP[ $generator ] ) ? self::MAP[ $generator ] : ''; } /** * Instantiate the generator for a key. * * @param string $generator Generator key. * @return GeneratorInterface|null Null when the key is unknown or the class is unavailable. */ public static function create( string $generator ): ?GeneratorInterface { $class = self::classFor( $generator ); if ( '' === $class || ! class_exists( $class ) ) { return null; } $instance = new $class(); return $instance instanceof GeneratorInterface ? $instance : null; } }