WordPress\AiClient\Providers\Models\DTO

ModelConfig::validateMediaOrientationAspectRatioCompatibility │ protected │ WP 0.4.0

Validates that the given media orientation and aspect ratio values do not conflict with each other.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validateMediaOrientationAspectRatioCompatibility( $orientation, $aspectRatio ): void;
$orientation(MediaOrientationEnum) (обязательный)
The desired media orientation.
$aspectRatio(строка) (обязательный)
The desired media aspect ratio.

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

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

Код ModelConfig::validateMediaOrientationAspectRatioCompatibility() WP 7.1.2

protected function validateMediaOrientationAspectRatioCompatibility(MediaOrientationEnum $orientation, string $aspectRatio): void
{
    $aspectRatioParts = explode(':', $aspectRatio);
    if ($orientation->isSquare() && $aspectRatioParts[0] !== $aspectRatioParts[1]) {
        throw new InvalidArgumentException('The aspect ratio "' . $aspectRatio . '" is not compatible with the square orientation.');
    }
    if ($orientation->isLandscape() && $aspectRatioParts[0] <= $aspectRatioParts[1]) {
        throw new InvalidArgumentException('The aspect ratio "' . $aspectRatio . '" is not compatible with the landscape orientation.');
    }
    if ($orientation->isPortrait() && $aspectRatioParts[0] >= $aspectRatioParts[1]) {
        throw new InvalidArgumentException('The aspect ratio "' . $aspectRatio . '" is not compatible with the portrait orientation.');
    }
}