VOOZH about

URL: https://deepwiki.com/hypervel/devtool/5.2-seeder-generation

⇱ Seeder Generation | hypervel/devtool | DeepWiki


Loading...
Menu

Seeder Generation

Purpose and Scope

This document covers the seeder generation system provided by the make:seeder command. Seeders are classes used to populate database tables with test or default data. The document explains the SeederCommand generator, the seeder class structure, file output paths, and how seeders integrate with factory classes to create model instances.

For information about model and factory generation, see Model and Factory Generation. For broader context on the model system generators, see Model System Generators.

Sources: src/Generator/SeederCommand.php1-50


Command Overview

The make:seeder command generates seeder classes that extend Hypervel\Database\Seeder. The command is implemented by the SeederCommand class, which follows the standard generator pattern by extending Hyperf\Devtool\Generator\GeneratorCommand.

SeederCommand Class Structure


Sources: src/Generator/SeederCommand.php9-50

Command Signature

PropertyValue
Command Namemake:seeder
DescriptionCreate a new seeder class
ArgumentsClass name (e.g., UserSeeder)
Base ClassHyperf\Devtool\Generator\GeneratorCommand

Sources: src/Generator/SeederCommand.php13-20


Seeder Class Structure

The generated seeder class follows a simple, consistent structure defined in the seeder.stub template.

Template Structure


Generated Seeder Example

When you run php bin/hypervel.php make:seeder UserSeeder, the following file is created:

ElementValue
NamespaceDatabase\Seeders
Base ClassHypervel\Database\Seeder
Methodrun(): void
Locationdatabase/seeders/UserSeeder.php

The generated class structure from src/Generator/stubs/seeder.stub1-19:

<?php

declare(strict_types=1);

namespace Database\Seeders;

use Hypervel\Database\Seeder;

class %CLASS% extends Seeder
{
 /**
 * Run the database seeds.
 */
 public function run(): void
 {
 //
 }
}

The %CLASS% placeholder is replaced with the provided class name.

Sources: src/Generator/stubs/seeder.stub1-19


File Generation Process

The SeederCommand class overrides key methods to customize the generation behavior for seeder classes.

File Path Resolution


Key Method Behaviors

MethodBehaviorImplementation
getStub()Returns stub file pathReads from config or uses default stub at __DIR__ . '/stubs/seeder.stub'
qualifyClass()Returns class name unchangedSimply returns the input $name without namespace manipulation
getPath()Constructs file system pathUses database/seeders directory by default, configurable via path key
getDefaultNamespace()Returns empty stringSeeders don't use traditional namespacing pattern

Sources: src/Generator/SeederCommand.php23-49

Configuration Options

The SeederCommand supports configuration through the standard generator config system:


Sources: src/Generator/SeederCommand.php25-41


Integration with Factories

Seeders commonly use factory classes to generate model instances. This integration allows for realistic test data generation.

Seeder-Factory Integration Pattern


Typical Usage Pattern

A seeder typically calls factory methods within its run() method:


Factory Definition Reference

The factory stub structure from src/Generator/stubs/factory.stub1-27 shows the corresponding factory class:

ElementPurpose
extends FactoryProvides factory functionality
definition() methodReturns default attribute array
%MODEL_NAMESPACE%References the model class
@extends Factory<%MODEL%>Type hint for IDE support

Sources: src/Generator/stubs/factory.stub1-27 src/Generator/stubs/seeder.stub1-19


Class Qualification and Namespacing

Unlike most generator commands, SeederCommand uses a simplified qualification strategy.

Namespace Resolution Diagram


The qualifyClass() method at src/Generator/SeederCommand.php31-34 simply returns the input name unchanged:


The namespace Database\Seeders is hardcoded in the stub template at src/Generator/stubs/seeder.stub5

Sources: src/Generator/SeederCommand.php31-34 src/Generator/stubs/seeder.stub5


File System Output

The getPath() method constructs the complete file system path for the generated seeder.

Path Construction Flow


The implementation at src/Generator/SeederCommand.php39-44:


Output Location Table

ComponentDefault ValueConfigurable
Base directoryBASE_PATHNo (constant)
Seeder directorydatabase/seedersYes (via path config)
File extension.phpNo
NamespaceDatabase\SeedersNo (hardcoded in stub)

Sources: src/Generator/SeederCommand.php39-44


Stub Template System

The seeder stub template uses a minimal placeholder replacement system.

Stub Placeholder Mapping


Stub Location Resolution

The getStub() method at src/Generator/SeederCommand.php23-26 determines which stub file to use:






















PrioritySourcePath
1 (Highest)Configuration stub keyCustom path specified in config
2 (Default)Package defaultsrc/Generator/stubs/seeder.stub

Sources: src/Generator/SeederCommand.php23-26 src/Generator/stubs/seeder.stub1-19


Command Registration

The SeederCommand is registered through the ConfigProvider along with other generator commands.

Registration Context


The command is registered alongside other model system generators documented in Model System Generators. When a model is generated with the --all flag via ModelCommand, the seeder can be automatically generated (see Model and Factory Generation).

Sources: src/Generator/SeederCommand.php1-50