renshan / randbuilder
数据生成器
v1.0.0
2017-01-18 15:00 UTC
Requires
- php: >=7.0.0
This package is not auto-updated.
Last update: 2024-09-28 19:58:21 UTC
README
随机数据生成器
模式
$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 );
好的,$scheme 是用于生成所需数据的模式,它是一个 PHP 数组,这个数组包含两个项目:object 和 count,object 是真正的 模式,而 count 表示你想要的数量。
让我们看看 object,不过无论如何,object 是一个数组,object 中的项目是要生成的字段,最重要的是定义一个字段,项目有几个属性
- type
type是必需的,现在 RandBuilder 支持 three 种类型:string,integer 和 float。 - length 如果
type是 string,则length是必需的 - prefix
prefix默认为 '' - end
end默认为 '' - unique
unique表示字段是否唯一,默认为false - range 对于 integer 和 float,
range不是必需的,它表示要生成的最小和最大数字 - precision 对于
float,它是range,默认为 0
注意:如果 unique 为 true,实际产生的数量可能少于指定数量。
示例
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); ``