Automattic\WooCommerce\Internal\Checkout
DateFormatLimit::validate
Checks the date against its limit without changing either value.
Метод класса: DateFormatLimit{}
Хуков нет.
Возвращает
ValidationError|null. The comparison error, if any.
Использование
$DateFormatLimit = new DateFormatLimit(); $DateFormatLimit->validate( $context, $schema ): ?ValidationError;
- $context(ValidationContext) (обязательный)
- The current document and value.
- $schema(Schema) (обязательный)
- The schema being evaluated.
Список изменений
| С версии 11.2.0 | Введена. |
Код DateFormatLimit::validate() DateFormatLimit::validate WC 11.2.2
public function validate( ValidationContext $context, Schema $schema ): ?ValidationError {
$limit = $this->limit instanceof JsonPointer
? $this->limit->data( $context->rootData(), $context->currentDataPath(), $this )
: $this->limit;
// AJV skips an unresolved $data reference, but rejects one with the wrong type.
if ( $this === $limit ) {
return null;
}
if ( ! is_string( $limit ) ) {
return $this->error( $schema, $context, $this->keyword, 'The date limit must be a string.' );
}
// ajv-formats does not compare dates when either string is empty.
if ( '' === $limit || '' === $context->currentData() ) {
return null;
}
$comparison = strcmp( $context->currentData(), $limit );
switch ( $this->keyword ) {
case 'formatMinimum':
$valid = $comparison >= 0;
break;
case 'formatMaximum':
$valid = $comparison <= 0;
break;
case 'formatExclusiveMinimum':
$valid = $comparison > 0;
break;
case 'formatExclusiveMaximum':
$valid = $comparison < 0;
break;
default:
return $this->error( $schema, $context, $this->keyword, 'Unsupported date comparison keyword.' );
}
return $valid ? null : $this->error(
$schema,
$context,
$this->keyword,
'Date does not satisfy {keyword}: {limit}.',
array(
'keyword' => $this->keyword,
'limit' => $limit,
)
);
}