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:
Jepp9350
2025-03-07 12:29:45 +01:00
parent 370760fbd3
commit d160ecbb63
3 changed files with 103 additions and 3 deletions
+28
View File
@@ -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