Add min and max fields to product options
This commit introduces support for `min` and `max` fields in product options. It includes backend changes to handle validation, setting, and retrieval of these new fields, ensuring compatibility. Additionally, a new `requireTypeIn` utility and `TYPE_NULL` constant were added for improved type validation.
This commit is contained in:
@@ -39,6 +39,34 @@ trait route_t
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Require parameter to be one of the given types
|
||||
* @param mixed $value The value to check
|
||||
* @param array $types The types to check against
|
||||
* @return bool
|
||||
*/
|
||||
public function requireTypeIn(mixed $value, array $types): bool
|
||||
{
|
||||
// Get the type of the value
|
||||
$value_type = gettype($value);
|
||||
// Check if the value is of the required type
|
||||
if (!in_array($value_type, $types)) {
|
||||
global $response;
|
||||
$response->error('Invalid type. Expected: ' . implode(', ', $types) . ' Got: ' . $value_type . ' Value: ' . $value, 400);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE_NULL
|
||||
* @note This is used to check if the value is null, this is used in routes to validate input
|
||||
* @return string
|
||||
*/
|
||||
public function TYPE_NULL(): string
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
/**
|
||||
* The default date format (Y-m-d) Example: 2023-01-01
|
||||
* @note This is used to format dates in the API
|
||||
|
||||
Reference in New Issue
Block a user