Validations
class Validations (View source)
The GenericDatabase\Helpers\Validations class provides several static methods for performing common validation
tasks. These methods include checking if a value is numeric, checking "Booleanic" conditions, generating random
strings, and detecting if a query is a SELECT statement.
Example Usage:
// Check if a value is numeric
$value = '123';
$isNumber = Validations::isNumber($value);
echo $isNumber ? 'Numeric' : 'Not numeric';
Output: Numeric
// Check "Booleanic" conditions
$value = 'true';
$isBoolean = Validations::isBoolean($value);
echo $isBoolean ? 'True' : 'False';
Output: True
// Generate a random string
$length = 10;
$randomString = Validations::randomString($length);
echo $randomString;
Output: Random string of length 10
Main functionalities:
- The
isNumbermethod checks if a value is numeric by using the is_numeric function. - The
isBooleanmethod checks "Booleanic" conditions by using thefilter_varfunction with theFILTER_VALIDATE_BOOLEANflag. - The
randomStringmethod generates a random string of a specified length by selecting random characters from an array of letters. - The
isSelectmethod detects if a query is a SELECT statement by checking if the query starts with the word "SELECT" (case-insensitive).
Methods:
isNumber(string $value): bool: Checks if a value is numeric.isBoolean(mixed $value): mixed: Checks "Booleanic" conditions.randomString(int $length): string: Generates a random string of a specified length.
Methods
Check if a value is numeric
Check "Booleanic" Conditions :)
Make a random string in length size
Converts elements of an array to specific types based on their original type.
Details
static bool
isNumber(string $value)
Check if a value is numeric
static mixed
isBoolean(mixed $value)
Check "Booleanic" Conditions :)
static string
randomString(int $length)
Make a random string in length size
static mixed
detectTypes(mixed $data)
Converts elements of an array to specific types based on their original type.