WordPress\AiClient\Providers
ProviderRegistry::getEnvVarName
Converts a provider ID and field name to a constant case environment variable name.
Method of the class: ProviderRegistry{}
No Hooks.
Returns
String. The environment variable name in CONSTANT_CASE.
Usage
// private - for code of main (parent) class only $result = $this->getEnvVarName( $providerId, $field ): string;
- $providerId(string) (required)
- The provider ID.
- $field(string) (required)
- The field name.
Changelog
| Since 0.1.0 | Introduced. |
ProviderRegistry::getEnvVarName() ProviderRegistry::getEnvVarName code WP 7.0
private function getEnvVarName(string $providerId, string $field): string
{
// Convert camelCase or kebab-case or snake_case to CONSTANT_CASE.
$constantCaseProviderId = strtoupper((string) preg_replace('/([a-z])([A-Z])/', '$1_$2', str_replace('-', '_', $providerId)));
$constantCaseField = strtoupper((string) preg_replace('/([a-z])([A-Z])/', '$1_$2', str_replace('-', '_', $field)));
return "{$constantCaseProviderId}_{$constantCaseField}";
}