ValidatesInputs
Trait for input validation methods.
Provides reusable validation methods following the Python SDK's approach:
- Does NOT validate date formats strictly (allows relative dates, option expiration dates, etc.)
- Only validates date ranges when both dates are parseable
- Validates numeric ranges, symbols, resolutions, etc.
Table of Contents
Methods
- canParseAsDate() : bool
- Check if a string can be parsed as a date.
- parseDateToTimestamp() : int|null
- Parse a date string to unix timestamp.
- validateCountryCode() : void
- Validate ISO 3166 two-letter country code.
- validateDateRange() : void
- Validate date range logic.
- validateNonEmptyArray() : void
- Validate that an array is non-empty.
- validateNonEmptyString() : void
- Validate that a string is non-empty.
- validateNumericRange() : void
- Validate that min < max when both are provided.
- validatePositiveInteger() : void
- Validate that an integer is positive if provided.
- validatePositiveNumber() : void
- Validate that a number (int or float) is positive if provided.
- validateResolution() : void
- Validate resolution format.
- validateSymbols() : void
- Validate symbols array (trim and ensure non-empty).
Methods
canParseAsDate()
Check if a string can be parsed as a date.
protected
canParseAsDate(string|null $value) : bool
Similar to Python SDK's check_is_date() function. Returns true if the value contains "-" or "/" (indicating parseable date format) or is numeric (unix timestamp or spreadsheet format).
This allows relative dates ("today", "yesterday", "-5 days") and option expiration dates ("December expiration") to pass through without validation.
Parameters
- $value : string|null
-
The value to check
Return values
bool —True if the value can be parsed as a date
parseDateToTimestamp()
Parse a date string to unix timestamp.
protected
parseDateToTimestamp(string|null $value) : int|null
Handles ISO 8601, unix timestamps, spreadsheet dates, and American format.
Parameters
- $value : string|null
-
The date string to parse
Return values
int|null —Unix timestamp or null if cannot be parsed
validateCountryCode()
Validate ISO 3166 two-letter country code.
protected
validateCountryCode(string $country) : void
Parameters
- $country : string
-
The country code to validate
Tags
validateDateRange()
Validate date range logic.
protected
validateDateRange(string|null $from, string|null $to[, int|null $countback = null ][, string $context = '' ]) : void
Rules:
- If
tois provided, it requires eitherfromORcountback(but not both) - If both
fromandtoare parseable dates, validates thatfrom<to - If
countbackis provided, it must be a positive integer
This allows relative dates and option expiration dates to pass through without strict format validation.
Parameters
- $from : string|null
-
The start date
- $to : string|null
-
The end date
- $countback : int|null = null
-
The countback value
- $context : string = ''
-
Optional context for error messages
Tags
validateNonEmptyArray()
Validate that an array is non-empty.
protected
validateNonEmptyArray(array<string|int, mixed> $value, string $fieldName) : void
Parameters
- $value : array<string|int, mixed>
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validateNonEmptyString()
Validate that a string is non-empty.
protected
validateNonEmptyString(string $value, string $fieldName) : void
Parameters
- $value : string
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validateNumericRange()
Validate that min < max when both are provided.
protected
validateNumericRange(float|null $min, float|null $max, string $minField, string $maxField) : void
Parameters
- $min : float|null
-
The minimum value
- $max : float|null
-
The maximum value
- $minField : string
-
The minimum field name for error messages
- $maxField : string
-
The maximum field name for error messages
Tags
validatePositiveInteger()
Validate that an integer is positive if provided.
protected
validatePositiveInteger(int|null $value, string $fieldName) : void
Parameters
- $value : int|null
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validatePositiveNumber()
Validate that a number (int or float) is positive if provided.
protected
validatePositiveNumber(int|float|null $value, string $fieldName) : void
Parameters
- $value : int|float|null
-
The value to validate
- $fieldName : string
-
The field name for error messages
Tags
validateResolution()
Validate resolution format.
protected
validateResolution(string $resolution) : void
Valid resolutions: minutely, hourly, daily, weekly, monthly, yearly, or numeric with optional suffix (1, 3, 5, 15, 30, 45, H, 1H, 2H, D, 1D, 2D, etc.)
Parameters
- $resolution : string
-
The resolution to validate
Tags
validateSymbols()
Validate symbols array (trim and ensure non-empty).
protected
validateSymbols(array<string|int, mixed> $symbols) : void
Parameters
- $symbols : array<string|int, mixed>
-
The symbols array to validate