Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| TranslationProviderFactory | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
| create | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Factory for creating translation provider instances. |
| 7 | * |
| 8 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 9 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 10 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 11 | * |
| 12 | * @package phpMyFAQ |
| 13 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 14 | * @copyright 2026 phpMyFAQ Team |
| 15 | * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 16 | * @link https://www.phpmyfaq.de |
| 17 | * @since 2026-01-17 |
| 18 | */ |
| 19 | |
| 20 | namespace phpMyFAQ\Translation; |
| 21 | |
| 22 | use phpMyFAQ\Configuration; |
| 23 | use phpMyFAQ\Translation\Provider\AmazonTranslationProvider; |
| 24 | use phpMyFAQ\Translation\Provider\AzureTranslationProvider; |
| 25 | use phpMyFAQ\Translation\Provider\DeepLTranslationProvider; |
| 26 | use phpMyFAQ\Translation\Provider\GoogleTranslationProvider; |
| 27 | use phpMyFAQ\Translation\Provider\LibreTranslationProvider; |
| 28 | use Symfony\Contracts\HttpClient\HttpClientInterface; |
| 29 | |
| 30 | /** |
| 31 | * Class TranslationProviderFactory |
| 32 | * |
| 33 | * Factory for creating translation provider instances based on configuration. |
| 34 | */ |
| 35 | class TranslationProviderFactory |
| 36 | { |
| 37 | /** |
| 38 | * Create a translation provider instance. |
| 39 | * |
| 40 | * @param Configuration $configuration phpMyFAQ configuration |
| 41 | * @param HttpClientInterface $httpClient HTTP client for API requests |
| 42 | * @return TranslationProviderInterface|null Provider instance or null if none configured |
| 43 | */ |
| 44 | public static function create( |
| 45 | Configuration $configuration, |
| 46 | HttpClientInterface $httpClient, |
| 47 | ): ?TranslationProviderInterface { |
| 48 | $provider = $configuration->get('translation.provider'); |
| 49 | |
| 50 | return match ($provider) { |
| 51 | 'google' => new GoogleTranslationProvider($configuration, $httpClient), |
| 52 | 'deepl' => new DeepLTranslationProvider($configuration, $httpClient), |
| 53 | 'azure' => new AzureTranslationProvider($configuration, $httpClient), |
| 54 | 'amazon' => new AmazonTranslationProvider($configuration, $httpClient), |
| 55 | 'libretranslate' => new LibreTranslationProvider($configuration, $httpClient), |
| 56 | default => null, |
| 57 | }; |
| 58 | } |
| 59 | } |