Download the PHP package nicholasjohn16/generate without Composer
On this page you can find all versions of the php package nicholasjohn16/generate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nicholasjohn16/generate
More information about nicholasjohn16/generate
Files in nicholasjohn16/generate
Package generate
Short Description Generate Command for Anahita CLI
License GPL-3.0-only
Informations about the package generate
Generate Command
The Generate Command is used to automatically generate sample data for testing and development.
Installation
Installation is done through composer. Since this is a dev tool, requiring it as a dev tool so it's not installed in production.
Usage
The Genereate Command is integrated into Anahita's CLI. To use it, you just need to pass in the repo and entity name that you wish to generate sample data for. Optionally, you can pass in the number of entities to generate using the count argument. This is 10 by default.
For example:
The above command will generate 10 person entities.
Relationships
Relationships can be specified when generating entities. For one to many relationships, you can optionally provide an id for the relationship by seperating the relationship name and id with a colon. If no id is provided, the child for the relationship will be randomly selected.
For example if we wanted to randomly generate a note with an owner of id 2 with a random author, we'd use the below command:
Many to many relationships are not yet supported.
Attributes
Attributes are generated randomly based on their entity definition. Non-required attributes have a chance of being null. If the generated value is null and they have a default value, the default value will be used instead. Faker PHP Library is used to generate the random values. The provider used for each attribute is based on the config.json
settings. Each attribute type has it's own set of defaults, followed by defaults for each entity attributes. Attributes not listed in will be skipped over and not generated.
These defaults can be overriden and extended to include attributes for your own entities. For your own projects, create a sample.json
file in the main directory of your Anahita installation and add an repo and entity object like below.
Then within your entity, list any additional attributes that you'd like to be randomly generated. As well, you can optional override the provider used for the attribute type and any arguments that are passed to it. You can also override core defaults using the same method. Providers must return a string, int, boolean or DateTime object.