WordPress\AiClient\Providers\Models\Enums

OptionEnum::determineClassEnumerations │ protected static │ WP 0.1.0

Determines the class enumerations by reflecting on class constants.

Overrides the parent method to dynamically add constants from ModelConfig that are prefixed with KEY_. These are transformed to remove the KEY_ prefix and converted to snake_case values.

Метод класса: OptionEnum{}

Хуков нет.

Возвращает

array<string, string>. The enum constants.

Использование

$result = OptionEnum::determineClassEnumerations( $className ): array;
$className(class-string) (обязательный)
The fully qualified class name.

Список изменений

С версии 0.1.0 Введена.

Код OptionEnum::determineClassEnumerations() WP 7.1.4

protected static function determineClassEnumerations(string $className): array
{
    // Start with the constants defined in this class using parent method
    $constants = parent::determineClassEnumerations($className);
    // Use reflection to get all constants from ModelConfig
    $modelConfigReflection = new ReflectionClass(ModelConfig::class);
    $modelConfigConstants = $modelConfigReflection->getConstants();
    // Add ModelConfig constants that start with KEY_
    foreach ($modelConfigConstants as $constantName => $constantValue) {
        if (str_starts_with($constantName, 'KEY_')) {
            // Remove KEY_ prefix to get the enum constant name
            $enumConstantName = substr($constantName, 4);
            // The value is the snake_case version stored in ModelConfig
            // ModelConfig already stores these as snake_case strings
            if (is_string($constantValue)) {
                $constants[$enumConstantName] = $constantValue;
            }
        }
    }
    return $constants;
}