VOOZH about

URL: https://deepwiki.com/hypervel/devtool/5-model-system-generators

⇱ Model System Generators | hypervel/devtool | DeepWiki


Loading...
Menu

Model System Generators

This document provides an overview of the model-related code generators in the Hypervel/Devtool package. These generators create Eloquent models, model factories, and database seeders. The system is designed with an orchestration pattern where ModelCommand acts as a central coordinator capable of invoking related generators automatically.

For detailed information about individual model and factory generation options, see Model and Factory Generation. For seeder-specific functionality, see Seeder Generation. For database migration generation, see Database Migration Generators.

Scope: This page covers the make:model, make:factory, and make:seeder commands, their interdependencies, the orchestration mechanism, stub templates, and output structure.

Command Overview

The model system consists of three generator commands that work together to provide a complete model scaffolding solution:

CommandClassPurposeDefault Output Location
make:modelModelCommandCreates Eloquent model classesapp/Models/
make:factoryFactoryCommandCreates model factory classesdatabase/factories/
make:seederSeederCommandCreates database seeder classesdatabase/seeders/

Each command extends Hyperf\Devtool\Generator\GeneratorCommand and follows the template-based generation pattern described in Generator Command Architecture and Stub Template System.

Sources: src/Generator/ModelCommand.php14-19 src/Generator/FactoryCommand.php11-16 src/Generator/SeederCommand.php9-14

ModelCommand as Orchestrator

The ModelCommand class implements an orchestration pattern where a single command invocation can trigger multiple related generators. This is achieved through the --all option and individual feature flags.

Orchestration Options

The command provides several options that trigger auxiliary generators:

OptionShortEffect
--all-aEnables --factory, --seed, --migration, --controller, --policy, and --resource
--factory-fInvokes make:factory
--seed-sInvokes make:seeder
--migration-mInvokes make:migration
--controller-cInvokes make:controller
--policyInvokes make:policy
--resource-rCreates a resource controller
--apiCreates an API resource controller
--requests-RCreates form request classes

When --all is specified, the command sets multiple option flags to true in the execution phase, enabling comprehensive scaffolding from a single command.

Sources: src/Generator/ModelCommand.php90-104 src/Generator/ModelCommand.php35-42

Orchestration Implementation

The orchestration is implemented through dedicated methods that programmatically invoke other commands:


Diagram: ModelCommand execution flow showing orchestration decision tree

Each invocation method uses the call() method to execute commands through the application container:

  • createFactory(): Invokes make:factory with {ModelName}Factory as the name
  • createSeeder(): Invokes make:seeder with {ModelName}Seeder as the name
  • createMigration(): Invokes make:migration with create_{table_name}_table pattern
  • createController(): Invokes make:controller with model binding and request options
  • createPolicy(): Invokes make:policy with {ModelName}Policy and model association
  • createFormRequests(): Invokes make:request twice for Store and Update requests

Sources: src/Generator/ModelCommand.php31-65 src/Generator/ModelCommand.php110-190 src/Generator/ModelCommand.php192-198

Command Relationships


Diagram: Class hierarchy and command invocation relationships

Sources: src/Generator/ModelCommand.php14 src/Generator/FactoryCommand.php11 src/Generator/SeederCommand.php9

Generated File Structure

The three commands produce files in distinct locations following Laravel/Hypervel conventions:


Diagram: File system structure generated by model system commands

ComponentNamespaceFile PathConfigured By
ModelApp\Modelsapp/Models/{Name}.phpgetDefaultNamespace()
FactoryDatabase\Factoriesdatabase/factories/{Name}Factory.phpgetPath()
SeederDatabase\Seedersdatabase/seeders/{Name}Seeder.phpgetPath()

Sources: src/Generator/ModelCommand.php85-88 src/Generator/FactoryCommand.php71-76 src/Generator/SeederCommand.php39-44

Stub Templates and Placeholder System

Each command uses a stub template file with placeholders that are replaced during generation:

Model Stub

The model stub defines the base structure for Eloquent models:

File: src/Generator/stubs/model.stub1-21

Placeholders:

  • %NAMESPACE%: The model namespace (default: App\Models)
  • %USES%: The base model class to extend (default: Hypervel\Database\Eloquent\Model)
  • %CLASS%: The model class name

The %USES% placeholder is replaced via the replaceClass() method, which reads from configuration or uses the default Hypervel model class.

Sources: src/Generator/stubs/model.stub1-21 src/Generator/ModelCommand.php71-78

Factory Stub

The factory stub creates factory classes following the Factory pattern:

File: src/Generator/stubs/factory.stub1-27

Placeholders:

  • %MODEL%: The model class name (without namespace)
  • %MODEL_NAMESPACE%: The fully qualified model class name

The FactoryCommand automatically determines the model name by stripping "Factory" from the input name, or uses the --model option if provided.

Sources: src/Generator/stubs/factory.stub1-27 src/Generator/FactoryCommand.php40-58

Seeder Stub

The seeder stub provides a minimal seeder structure:

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

Placeholders:

  • %CLASS%: The seeder class name

The seeder extends Hypervel\Database\Seeder and provides an empty run() method for developers to implement seeding logic.

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

Configuration System

All three commands support configuration through the getConfig() method inherited from GeneratorCommand. Configuration can customize:

Model Configuration

Config KeyPurposeDefault
stubCustom model stub path__DIR__ . '/stubs/model.stub'
namespaceModel namespaceApp\Models
usesBase model classHypervel\Database\Eloquent\Model

Sources: src/Generator/ModelCommand.php80-88 src/Generator/ModelCommand.php75

Factory Configuration

Config KeyPurposeDefault
stubCustom factory stub path__DIR__ . '/stubs/factory.stub'
pathFactory output directorydatabase/factories
model_namespaceModel namespace for importsApp\Models

Sources: src/Generator/FactoryCommand.php25-28 src/Generator/FactoryCommand.php71-76 src/Generator/FactoryCommand.php30-35

Seeder Configuration

Config KeyPurposeDefault
stubCustom seeder stub path__DIR__ . '/stubs/seeder.stub'
pathSeeder output directorydatabase/seeders

Sources: src/Generator/SeederCommand.php23-26 src/Generator/SeederCommand.php39-44

Command Invocation Examples

Basic Model Generation


Generates app/Models/User.php with the model class.

Full Scaffolding


Generates:

  • app/Models/User.php (model)
  • database/factories/UserFactory.php (factory)
  • database/seeders/UserSeeder.php (seeder)
  • database/migrations/YYYY_MM_DD_HHMMSS_create_users_table.php (migration)
  • app/Controller/UserController.php (resource controller)
  • app/Policy/UserPolicy.php (policy)

Selective Generation


Generates only the model, factory, and migration, omitting seeder, controller, and policy.

Sources: src/Generator/ModelCommand.php35-65

Name Transformation Rules

The ModelCommand applies consistent naming conventions when invoking auxiliary commands:


Diagram: Name transformation from input to generated files

The transformations use Hyperf\Stringable\Str utility methods:

  • Factory: Str::studly($name) . 'Factory'
  • Seeder: Str::studly($name) . 'Seeder'
  • Migration table: Str::snake(Str::pluralStudly(class_basename($name)))
  • Controller: Str::studly($name) . 'Controller'
  • Policy: Str::studly($name) . 'Policy'

Sources: src/Generator/ModelCommand.php112-118 src/Generator/ModelCommand.php124-130 src/Generator/ModelCommand.php136-143 src/Generator/ModelCommand.php149-161 src/Generator/ModelCommand.php182-189