PluginProbe
Auto Alt Text / trunk
Auto Alt Text vtrunk
3.0.3 2.8.2 1.3.1 1.3.2 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.7.0 2.8.0 2.8.1 All 28 releases
auto-alt-text / src / App / Configuration / AzureConfig.php

AzureConfig.php in Auto Alt Text trunk, at src/App/Configuration/AzureConfig.php

148 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AATXT\App\Configuration;
6
7 /**
8 * Configuration object for Azure Computer Vision provider.
9 *
10 * Immutable value object that holds configuration data for Azure Computer Vision
11 * and Azure Translator API calls. This class implements the Dependency Injection
12 * pattern, removing the need for static calls to PluginOptions.
13 *
14 * Azure services used:
15 * - Computer Vision: for generating image captions
16 * - Translator (optional): for translating captions to different languages
17 */
18 final class AzureConfig implements AIProviderConfig
19 {
20 private string $apiKey;
21 private string $endpoint;
22 private string $model = '';
23 private string $prompt = '';
24 private string $translationApiKey = '';
25 private string $translationEndpoint = '';
26 private string $translationRegion = '';
27 private string $translationLanguage = 'en';
28
29 /**
30 * @param string $apiKey The Azure Computer Vision API key
31 * @param string $endpoint The Azure Computer Vision endpoint URL
32 * @param string $model The API version (e.g., '2023-10-01')
33 * @param string $prompt Not used by Azure (empty string)
34 * @param string $translationApiKey The Azure Translator API key (optional)
35 * @param string $translationEndpoint The Azure Translator endpoint URL (optional)
36 * @param string $translationRegion The Azure Translator region (e.g., 'westeurope')
37 * @param string $translationLanguage The target language code (e.g., 'it', 'fr', 'de')
38 */
39 public function __construct(
40 string $apiKey,
41 string $endpoint,
42 string $model = '',
43 string $prompt = '',
44 string $translationApiKey = '',
45 string $translationEndpoint = '',
46 string $translationRegion = '',
47 string $translationLanguage = 'en'
48 ) {
49 $this->translationLanguage = $translationLanguage;
50 $this->translationRegion = $translationRegion;
51 $this->translationEndpoint = $translationEndpoint;
52 $this->translationApiKey = $translationApiKey;
53 $this->prompt = $prompt;
54 $this->model = $model;
55 $this->endpoint = $endpoint;
56 $this->apiKey = $apiKey;
57 }
58
59 /**
60 * {@inheritDoc}
61 * Returns the Computer Vision API key.
62 */
63 public function getApiKey(): string
64 {
65 return $this->apiKey;
66 }
67
68 /**
69 * {@inheritDoc}
70 * Azure does not use custom prompts, returns empty string.
71 */
72 public function getPrompt(): string
73 {
74 return $this->prompt;
75 }
76
77 /**
78 * {@inheritDoc}
79 * Returns the API version or empty string if not specified.
80 */
81 public function getModel(): string
82 {
83 return $this->model;
84 }
85
86 /**
87 * Get the Azure Computer Vision endpoint URL.
88 *
89 * @return string The endpoint URL (e.g., 'https://computer-vision-france-central.cognitiveservices.azure.com/')
90 */
91 public function getEndpoint(): string
92 {
93 return $this->endpoint;
94 }
95
96 /**
97 * Get the Azure Translator API key.
98 *
99 * @return string The translator API key (empty if translation is not configured)
100 */
101 public function getTranslationApiKey(): string
102 {
103 return $this->translationApiKey;
104 }
105
106 /**
107 * Get the Azure Translator endpoint URL.
108 *
109 * @return string The translator endpoint URL (empty if translation is not configured)
110 */
111 public function getTranslationEndpoint(): string
112 {
113 return $this->translationEndpoint;
114 }
115
116 /**
117 * Get the Azure Translator region.
118 *
119 * @return string The region (e.g., 'westeurope', empty if translation is not configured)
120 */
121 public function getRegion(): string
122 {
123 return $this->translationRegion;
124 }
125
126 /**
127 * Get the target language for translation.
128 *
129 * @return string The language code (e.g., 'it', 'fr', 'de', defaults to 'en')
130 */
131 public function getTranslationLanguage(): string
132 {
133 return $this->translationLanguage;
134 }
135
136 /**
137 * Check if translation is configured and should be used.
138 *
139 * @return bool True if translation is configured and target language is not English
140 */
141 public function shouldTranslate(): bool
142 {
143 return !empty($this->translationApiKey)
144 && !empty($this->translationEndpoint)
145 && $this->translationLanguage !== 'en';
146 }
147 }
148