Generators
class Generators (View source)
The GenericDatabase\Helpers\Generators class provides methods
for generating options and determining the type of values.
Example Usage:
$value = [
'option1' => 'value1',
'option2' => 'value2',
'option3' => 'value3',
];
$instance = new MyClass();
$className = 'MyClass';
$constantName = 'OPTIONS';
$attributes = ['option1', 'option2'];
$options = Generators::setConstant($value, $instance, $className, $constantName, $attributes);
Output: $options will be ['option1' => 'value1', 'option2' => 'value2', 'ATTR3' => 'value3']
// Determine the type of a value
$value = '123';
$type = Generators::setType($value);
Output: $type will be 123
Main functionalities:
- Setting a constant and generating options based on a provided value, instance, class name, constant name, and attributes.
- Determining the type of value based on its characteristics.
Methods:
setConstant($value, $instance, $className, $constantName, $attributes): Sets a constant and generates options based on the provided value, instance, class name, constant name, and attributes. Returns the generated options as an array.setType($value): Determines the type of value based on its characteristics. Returns the determined type as a boolean, integer, or string.generateKeyName($index, $constantName): Generates a key name based on the index and constant name. Returns the generated key name as a string.generateOptionKey($className, $constantName, $index): Generates an option key based on the class name, constant name, and index. Returns the generated option key as a string.generateHash(): Generates a random hash value. Returns the generated hash value as a string.
Methods
static array
setConstant(array $value, mixed $instance, string $className, string $constantName, array $attributes)
Sets a constant and generates options based on the provided value, instance, class name, constant name, and attributes.
static bool|int|string
setType(mixed $value)
Determines the type of value based on its characteristics.
static string
generateHash()
Generates a random hash value.
Details
static array
setConstant(array $value, mixed $instance, string $className, string $constantName, array $attributes)
Sets a constant and generates options based on the provided value, instance, class name, constant name, and attributes.
static bool|int|string
setType(mixed $value)
Determines the type of value based on its characteristics.
static string
generateHash()
Generates a random hash value.