Download the PHP package tobento/app-seeding without Composer
On this page you can find all versions of the php package tobento/app-seeding. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package app-seeding
App Seeding
Seeding support for the app using the Seeder Service.
Table of Contents
- Getting Started
- Requirements
- Documentation
- App
- Seeding Boot
- Adding Seed Resources
- Factories
- Creating Factories
- Using Factories
- Seeders
- Creating Seeders
- Adding Seeders
- Running Seeders
- User Seeding
- Repository
- Creating Repository Factories
- Credits
Getting Started
Add the latest version of the app seeding project running this command.
Requirements
- PHP 8.0 or greater
Documentation
App
Check out the App Skeleton if you are using the skeleton.
You may also check out the App to learn more about the app in general.
Seeding Boot
The seeding boot does the following:
- SeedInterface implementation
- SeedersInterface implementation
- adds console commands for seeding
The following seeders will be available:
Keep in mind that no Resources are set as they may be specific to your app needs. Therefore, the seeders mostly using the Lorem Seeder as fallback.
Adding Seed Resources
You may add seeder resources by the following ways:
Globally by using the app method
Specific on any service using the seed
Factories
Creating Factories
You may create seed factories for testing or other purposes.
To create a factory, create a class that extends the and configure your entity by using the method:
Creating entities
You may use the method to create specific entites using the definition. By default, a class will be created.
Storing entities
By default, entities will not be stored. You may use the method to store the entity based on the definition. In Addition, you may use method to get any service from the app container.
Using Factories
A factory can be created by calling the method on the factory class:
Make entities
The method creates an array of entities and returns them for further use in code, but does not store them in the database e.g.
Create entities
The method creates an array of entities, stores them in the database for instance and returns them for further use in the code.
Raw entities
The method creates an array of attributes from definition only and returns them for further use in code.
Modify definition
You may modify the definition by using the method:
You may use the method inside your factory class:
Modify entity
You may modify the entity by using the method:
You may use the method inside your factory class:
Seeders
You may create a seeder class to easily seed your application with test data.
Creating Seeders
To create a seeder, create a class that implements the :
If you want to seed millions of test data, using factories my not be the fastest solution. Instead you may directly use the storage if available which is much faster.
Example using the user repository from the App User bundle:
Adding Seeders
You may add seeders to be run by the app console using the app method.
Running Seeders
To run your added seeders use the console command.
Run only specific seeders by its name
Display seeded entities
You may display the seeded entities with the verbosity option:
List all seeder names
You may display the seeder names by using the console command.
User Seeding
If you have installed the User App bundle you may use the provided user factory and user seeder.
User Factory
User Seeder
Repository
You may easily create seed Repository Interface.
Creating Repository Factories
Using the repository factory
By using the method, you can quickly create a seed factory, which may be useful for testing purposes.
Storage Repositories with defined columns, will create the definition automatically based on the columns. You do not need to set a definition at all.
Check out the Using Factories section for more info using the factory in general.
Using the AbstractFactory
To create a factory, create a class that extends the and use the constant to define your repository class:
Sure, you may customize the definition for more flexibility:
Credits
- Tobias Strub
- All Contributors
All versions of app-seeding with dependencies
tobento/app Version ^1.0.7
tobento/app-migration Version ^1.0
tobento/app-console Version ^1.0
tobento/service-seeder Version ^1.0.1
tobento/service-iterable Version ^1.0
tobento/service-support Version ^1.0