Download the PHP package kfilin/randdata without Composer
On this page you can find all versions of the php package kfilin/randdata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kfilin/randdata
More information about kfilin/randdata
Files in kfilin/randdata
Package randdata
Short Description Data generator with support for complex data and dependency realization
License MIT
Homepage https://github.com/KonstantinFilin/RandData
Informations about the package randdata
RandData
Data generator with support for complex data and dependency realization. You can check demo site of the project.
Installation
Basic usage
More examples in src/examples folder
Raw random values example
Filling string by template
Let's we have a string with a pair of variable words in it. We will fill this fields with random values:
Let's make it a little more complicated:
Generators. Creating csv
Generators. Filling database and more
First of all, you can define your data manually:
If your database is too big and you want to get it fast, you can get it from sql SHOW CREATE TABLE command:
If you want it VERY fast and you don't care much about plausibility, you can fill all database tables (if any field is NULL possible, its value will be NULL with about 50% probability):
Currenty only this data types supported (feel free to ask for extanding the list or make your own contribution to the project):
- (tiny|small|medium|big)int
- decimal
- varchar
- (tiny|medium|long)text
- enum
- set (only one of available values for the row will be generated, i.e. one OR two OR three, but not one,two or one,three
- datetime/date/time/year/year(4)/year(2)
Data dependency
In real life data is dependant. Birth must be before death, sunrise time before sunset time, salary is calculating from worked hours, hourly rate, fines and so on.
This library can generate data dependant from other object attributes (for example, hired date dependant from birth date).
If you have dependencies between different objects (Authors and Books), it can be little tricky, but something about this:
Or simplier, if you test with 100 authors:
Data dependency. Nested datasets
Another way to declare dependency is nested datasets
Filling forms
See demo site
Main Objects
RandData Fabric
Creates RandDataSet objects
RandData Set
Generates one random value. Atomic piece of data, may be simple (boolean, number or char) or complex, for example PersonName Object (FirstName + MiddleName + LastName) or AviaTicket Order Object (departure information, route, passenger list, status information and so on)
Tuple
Manages list of datasets. Can add dataset from PHP object or from string. Generates array of random values
RandData Generator
Manages generation process. Produces amount of random datasets (array of arrays of random values).
RandData Formatter
Buids data stream into something useful. Now it can be csv file, sql INSERT commands or JSON array.
DataSet options
All DataSet can be created from string identificator ("boolean", "string", "integer" and so on):
There also may be an optional params:
Params seperated by semicolon and name/value pairs separated by equal sign:
Value may be an array item, its item seperated by comma:
Counter
Simple counter. Generates number sequence inside string or as number. When calling by Generator object, it is incremented automatically. When calling direct or by Tuple object, you need to set counter value manually
ID
counter, cnt
Params
- tpl, template: When setted, it generates string with counter (for example, template "user_#" turns to { user_1, user_2, user_3, ... }. When missed, then usual unsigned integer will be returned { 1, 2, 3, ... }
- start: Default start value. For example, you set generator's amount property to 20, and start counter property setted to 100, then you get values { 100, 101, 102, ..., 119 }
Initialization string example
Boolean
ID
boolean
Params
- valTrue: String to show when true (examples: 1, Y, Yes, +, ...)
- valFalse: String to show when false (examples: 0, N, No, -, ...)
Initialization string examples
Integer
ID
int, integer
Params
- min: Minimum value (default to 0)
- max: Maximum value (default to return value of getrandmax() PHP function
Initialization string examples
Decimal
ID
decimal
Params
- min: Minimum value (default to 0)
- max: Maximum value (default to return value of getrandmax() PHP function
- minFractionDigits: Minimum digits after the point. Default to 0
- maxFractionDigits: Maximum digits after the point. Default to 8
Initialization string examples
String
A string of selected chars
ID
string
Params
- length_min: String length. Defaults to 1. Must be minimum 1
- length_max: String length. Defaults to 10. Must be maximum 100
- char_list: List of chars that random string consists of. Defaults to [A-Za-z0-9]
Initialization string examples
Paragraph
A paragraph of words (random char strings) separated by spaces
ID
paragraph
Params
- words_min: Minimum words in paragraph. Defaults to 3. Must be minimum 1
- words_max: Maximum words in paragraph. Defaults to 100. Must be maximum 500
- length_min: String length. Defaults to 1. Must be minimum 1
- length_max: String length. Defaults to 10. Must be maximum 100
- char_list: List of chars that random string consists of. Defaults to [A-Za-z0-9]
Initialization string examples
String List
String from the list
ID
string_list
Params
- values: Comma seperated list of available values
- possibility: The possibility of values (in percents). Must be equal to the values count and its sum must be 100. If missing, then all values has the same possibility.
Initialization string examples
Time
ID
time
Params
- min: Minimum time. Default to "00:00"
- max: Maximum time. Default to "23:59"
- seconds: Whether to show seconds. 1 - show, 0 - hide. Default to 0
Initialization string examples
Date
ID
date
Params
- min: Minimum date. Default to today minus one month. Input format YYYY-MM-DD.
- max: Maximum date. Default to today. Input format YYYY-MM-DD.
- format: Output format. Understands any format of date() PHP function. Default to YYYY-MM-DD
Initialization string examples
Datetime
ID
datetime
Params
- date_min: Minimum date. Default to today minus one month. Input format YYYY-MM-DD.
- date_max: Maximum date. Default to today. Input format YYYY-MM-DD.
- date_format: Output format. Understands any format of date() PHP function. Default to YYYY-MM-DD
- time_min: Minimum time. Default to "00:00"
- time_max: Maximum time. Default to "23:59"
- seconds: Whether to show seconds. 1 - show, 0 - hide. Default to 1
Initialization string examples
Phone
ID
phone
Params
- country_list: List of available country codes (1-9)
- region_list: List of available region codes (3 or 4 digits)
- format: Whether to show number formatted as +# (###) ###-##-## or +# (####) ###-### or as 11 digits. 1 - formatted (default), 0 - unformatted.
Initialization string examples
Domain
ID
Two level www domain
domain
Params
- tld_list: List of available top domain. Default: com,edu,org,net
- char_list_edge: First and last char. Default: abcdefghijklmnoprstuvwxyz0123456789
- char_list: Available characters (except first and last one). Default is char_list_edge chars and a hyphen char ("-").
- skip_www: Skip www part of domain. Can be 0 or 1. Default 0
Initialization string examples
ID
Params
- domain_list: Generate mail only in this domains
Initialization string example
Value
Generates single value
ID
value
Params
- value: Value to generate
Initialization string example
Complex
Dataset consists of other datasets
ID
complex
Params
- template: initialization string - any string with dataset definitions enclosed with {}. See examples for details
Initialization string example
Examples
DataSet (en_GB)
Address
ID
en_address
Params
No params
City
ID
en_city
Params
- postcode: post area to take city from
Initialization string example
Person
ID
en_person
Params
- sex: List of person's sex. m - Male, f - female. Default to both
- format: First name (%f), middle name (%m) and last name (%l) order. Default to "%f %m %l". %f1 - first letter of the first name, %m1 - first letter of the middle name, %l1 - last letter of ther first name
Initialization string examples
Postcode
ID
en_postcode
Params
No params
Street
ID
en_street
Params
No params
DataSet (ru_RU)
Address (ru)
ID
ru_address
Params
- show_flat: Whether to show flat number. 1 - show, 0 - hide
Initialization string examples
City (ru)
ID
ru_city
Params
No params
Person (ru)
ID
ru_person
Params
- sex: List of person's sex. m - Male, f - female. Default to both
- format: First name (%f), middle name (%m) and last name (%l) order. Default to "%l %f %m". %f1 - first letter of the first name, %m1 - first letter of the middle name, %l1 - last letter of ther first name
Initialization string examples
Postcode (ru)
ID
ru_postcode
Params
No params
Street (ru)
ID
ru_street
Params
No params
TODO
- (-) Code style, mess detector, code metrics
- (-) CI
- (-) v1.0