Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AiServiceFactory | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| createProvider | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getProviderName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isConfigured | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace App\Service\Api; |
| 5 | |
| 6 | use App\Service\Api\Anthropic\AnthropicApiService; |
| 7 | use App\Service\Api\OpenRouter\OpenRouterApiService; |
| 8 | use App\Utility\SettingsManager; |
| 9 | |
| 10 | /** |
| 11 | * AiServiceFactory |
| 12 | * |
| 13 | * Factory class for creating AI provider instances based on application settings. |
| 14 | * Supports switching between Anthropic (direct API) and OpenRouter providers. |
| 15 | */ |
| 16 | class AiServiceFactory |
| 17 | { |
| 18 | /** |
| 19 | * Create the appropriate AI provider based on settings. |
| 20 | * |
| 21 | * @return \App\Service\Api\AiProviderInterface The configured AI provider. |
| 22 | */ |
| 23 | public static function createProvider(): AiProviderInterface |
| 24 | { |
| 25 | $provider = SettingsManager::read('Anthropic.provider', 'anthropic'); |
| 26 | |
| 27 | return match ($provider) { |
| 28 | 'openrouter' => new OpenRouterApiService(), |
| 29 | default => new AnthropicApiService(), |
| 30 | }; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get the currently configured provider name. |
| 35 | * |
| 36 | * @return string The provider identifier ('anthropic' or 'openrouter'). |
| 37 | */ |
| 38 | public static function getProviderName(): string |
| 39 | { |
| 40 | return SettingsManager::read('Anthropic.provider', 'anthropic'); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Check if the configured provider is properly set up. |
| 45 | * |
| 46 | * @return bool True if the provider has valid credentials. |
| 47 | */ |
| 48 | public static function isConfigured(): bool |
| 49 | { |
| 50 | $provider = static::createProvider(); |
| 51 | |
| 52 | return $provider->isConfigured(); |
| 53 | } |
| 54 | } |