renshan / randbuilder
A data builder
Installs: 25
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/renshan/randbuilder
Requires
- php: >=7.0.0
This package is not auto-updated.
Last update: 2025-12-21 02:18:36 UTC
README
A random data generator
Schema
$schema = array( "object" => array( "name" => array( "type" => "string", "length" => 10, "prefix" => "builder_", "end" => "_redliub", "unique" => true ), "hash" => array( "type" => "string", "length" => array(10,20), "reducer" => "md5" ), "number" => array( "type" => "integer", "range" => array(10, 100), "unique" => true ), "price" => array( "type" => "float", "range" => array(100, 1000), "precision" => 2 ) ), "count" => 10 // How many object will be make );
Ok, $scheme is a scheme used to generate the data you want, it's an array php, this array contains two items: object and count, object is the real schema, and count indicate how many you want.
Let's see the object, however of whatever, object is an array, items in object are fields to be generated, the most important thing is to define a field, items has a few attributes:
- type
typeis required, now RandBuilder support three types: string, integer and float. - length
typeis required iftypeis string - prefix
prefixdefaults to '' - end
enddefaults to '' - unique
uniqueindicate the field is unique or not, defaults tofalse - range
rangeis not required for integer and float, it indicate the min and the max number to be generated - precision
rangeforfloat, it default to 0
Note: if unique is true, the actual quantity produced may be less than the specified quantity.
Example
use RandBuilder\Builder; $schema = array( "object" => array( "name" => array( "type" => "string", "length" => 10, "prefix" => "builder_", "end" => "_redliub", "unique" => true ), "hash" => array( "type" => "string", "length" => array(10,20), "reducer" => "md5" ), "number" => array( "type" => "integer", "range" => array(10, 100), "unique" => true ), "price" => array( "type" => "float", "range" => array(100, 1000), "precision" => 2 ) ), "count" => 10 // How many object will be make ); $objects = Builder::build($schema); ``