Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ContentGenerationPrompt | |
0.00% |
0 / 22 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| validate_input | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| get_refined_site_description | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_meta_response | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| get_prompt | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Content Generation Prompt Class |
| 4 | * |
| 5 | * This file contains the ContentGenerationPrompt class which processes |
| 6 | * site info entered during onboarding and generates structured prompt |
| 7 | * for AI content generation. |
| 8 | * |
| 9 | * @package NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration |
| 10 | */ |
| 11 | |
| 12 | namespace NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration; |
| 13 | |
| 14 | use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen; |
| 15 | use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService; |
| 16 | use NewfoldLabs\WP\Module\Onboarding\Services\LanguageService; |
| 17 | |
| 18 | /** |
| 19 | * Content Generation Prompt Class |
| 20 | * |
| 21 | * This class processes the site info entered during onboarding and generates |
| 22 | * structured prompt for AI content generation. |
| 23 | */ |
| 24 | class ContentGenerationPrompt { |
| 25 | |
| 26 | /** |
| 27 | * The original site description provided by the user. |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | private $site_description; |
| 32 | |
| 33 | /** |
| 34 | * The type of site (e.g., 'business', 'blog', 'ecommerce', 'linkinbio'). |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | private $site_type; |
| 39 | |
| 40 | /** |
| 41 | * The required site meta dependencies. |
| 42 | * |
| 43 | * @var array |
| 44 | */ |
| 45 | private $prompt_site_meta_dependencies = array( |
| 46 | 'target_audience', |
| 47 | 'content_tones', |
| 48 | 'keywords', |
| 49 | ); |
| 50 | |
| 51 | /** |
| 52 | * Constructor for ContentGenerationPrompt. |
| 53 | * |
| 54 | * @param string $site_description The user-provided site description. |
| 55 | * @param string $site_type The type of site (e.g., 'business', 'personal', 'ecommerce', 'linkinbio'). |
| 56 | */ |
| 57 | public function __construct( $site_description, $site_type ) { |
| 58 | $this->validate_input( $site_description, $site_type ); |
| 59 | |
| 60 | $this->site_description = trim( $site_description ); |
| 61 | $this->site_type = trim( $site_type ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Validates the input parameters. |
| 66 | * |
| 67 | * @param string $site_description The site description. |
| 68 | * @param string $site_type The site type. |
| 69 | * |
| 70 | * @throws \Exception If any parameter is empty. |
| 71 | */ |
| 72 | private function validate_input( $site_description, $site_type ) { |
| 73 | if ( empty( $site_description ) ) { |
| 74 | throw new \Exception( 'Site description cannot be empty' ); |
| 75 | } |
| 76 | |
| 77 | if ( empty( $site_type ) ) { |
| 78 | throw new \Exception( 'Site type cannot be empty' ); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Sets the refined site description using AI processing. |
| 84 | * |
| 85 | * @return string The refined site description. |
| 86 | */ |
| 87 | private function get_refined_site_description(): string { |
| 88 | return SiteGen::get_refined_site_description( $this->site_description ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets the meta response for the site meta dependency. |
| 93 | * |
| 94 | * @param string $site_meta_dependency The site meta dependency. |
| 95 | * |
| 96 | * @return array The meta response. |
| 97 | */ |
| 98 | private function get_meta_response( $site_meta_dependency ): array { |
| 99 | $response = LegacySiteGenService::instantiate_site_meta( |
| 100 | $this->site_description, |
| 101 | $site_meta_dependency, |
| 102 | $this->site_type, |
| 103 | LanguageService::get_site_locale() |
| 104 | ); |
| 105 | |
| 106 | if ( is_wp_error( $response ) ) { |
| 107 | return array(); |
| 108 | } |
| 109 | |
| 110 | return $response; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Gets the complete prompt array for content generation. |
| 115 | * |
| 116 | * @return array { |
| 117 | * The complete prompt array for content generation. |
| 118 | * |
| 119 | * @type string $site_description The refined site description. |
| 120 | * @type array $target_audience The target audience information. |
| 121 | * @type array $content_style The content style/tone information. |
| 122 | * @type array $keywords The relevant keywords. |
| 123 | * } |
| 124 | */ |
| 125 | public function get_prompt(): array { |
| 126 | $prompt = array(); |
| 127 | $prompt['site_description'] = $this->get_refined_site_description(); |
| 128 | |
| 129 | foreach ( $this->prompt_site_meta_dependencies as $site_meta_dependency ) { |
| 130 | $prompt[ $site_meta_dependency ] = $this->get_meta_response( $site_meta_dependency ); |
| 131 | } |
| 132 | |
| 133 | return $prompt; |
| 134 | } |
| 135 | } |