Automattic\WooCommerce\Internal\Checkout
DateFormatLimitParser::parse
Parses a literal date limit or a reference to another date.
Method of the class: DateFormatLimitParser{}
No Hooks.
Returns
Keyword|null. The date comparison, if present.
Usage
$DateFormatLimitParser = new DateFormatLimitParser(); $DateFormatLimitParser->parse( $info, $parser, $shared ): ?Keyword;
- $info(SchemaInfo) (required)
- The schema to parse.
- $parser(SchemaParser) (required)
- The Opis schema parser.
- $shared(object) (required)
- State shared by the keyword parsers.
Changelog
| Since 11.2.0 | Introduced. |
DateFormatLimitParser::parse() DateFormatLimitParser::parse code WC 11.2.1
public function parse( SchemaInfo $info, SchemaParser $parser, object $shared ): ?Keyword {
unset( $shared );
if ( ! $this->keywordExists( $info ) ) {
return null;
}
if ( 'date' !== ( $info->data()->format ?? null ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Opis requires the schema object, which is not output.
throw $this->keywordException( '{keyword} requires format: date.', $info );
}
$value = $this->keywordValue( $info );
if ( $this->isDataKeywordAllowed( $parser, $this->keyword ) ) {
$pointer = $this->getDataKeywordPointer( $value );
if ( $pointer ) {
return new DateFormatLimit( $this->keyword, $pointer );
}
}
if ( ! is_string( $value ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Opis requires the schema object, which is not output.
throw $this->keywordException( '{keyword} must contain a string or a valid $data reference.', $info );
}
return new DateFormatLimit( $this->keyword, $value );
}