mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
088f1c2953
The formatOptions min/max may be integers after JSON decode or may be on the attribute directly (from range filter). Use floatval() and check both formatOptions and direct attribute keys. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
|
use Utopia\Database\Validator\Structure;
|
|
use Utopia\Emails\Validator\Email;
|
|
use Utopia\Query\Schema\ColumnType;
|
|
use Utopia\Validator\IP;
|
|
use Utopia\Validator\Range;
|
|
use Utopia\Validator\URL;
|
|
use Utopia\Validator\WhiteList;
|
|
|
|
Structure::addFormat(APP_DATABASE_ATTRIBUTE_EMAIL, function () {
|
|
return new Email();
|
|
}, ColumnType::String);
|
|
|
|
Structure::addFormat(APP_DATABASE_ATTRIBUTE_DATETIME, function () {
|
|
return new DatetimeValidator();
|
|
}, ColumnType::Datetime);
|
|
|
|
Structure::addFormat(APP_DATABASE_ATTRIBUTE_ENUM, function ($attribute) {
|
|
$elements = $attribute['formatOptions']['elements'] ?? [];
|
|
return new WhiteList($elements, true);
|
|
}, ColumnType::String);
|
|
|
|
Structure::addFormat(APP_DATABASE_ATTRIBUTE_IP, function () {
|
|
return new IP();
|
|
}, ColumnType::String);
|
|
|
|
Structure::addFormat(APP_DATABASE_ATTRIBUTE_URL, function () {
|
|
return new URL();
|
|
}, ColumnType::String);
|
|
|
|
Structure::addFormat(APP_DATABASE_ATTRIBUTE_INT_RANGE, function ($attribute) {
|
|
$min = $attribute['formatOptions']['min'] ?? -INF;
|
|
$max = $attribute['formatOptions']['max'] ?? INF;
|
|
return new Range($min, $max, Range::TYPE_INTEGER);
|
|
}, ColumnType::Integer);
|
|
|
|
Structure::addFormat(APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, function ($attribute) {
|
|
$min = \floatval($attribute['formatOptions']['min'] ?? $attribute['min'] ?? -INF);
|
|
$max = \floatval($attribute['formatOptions']['max'] ?? $attribute['max'] ?? INF);
|
|
return new Range($min, $max, Range::TYPE_FLOAT);
|
|
}, ColumnType::Double);
|