Skip to content

StubsGenerator ​

Class: Unusualify\Modularous\Generators\StubsGenerator
Source: src/Generators/StubsGenerator.php
Extends: Generator

A lighter variant of RouteGenerator that only regenerates stub-based files. It does not touch the module config, run migrations, create models, or seed permissions. Used by fix/patch commands to refresh specific generated files (controllers, Vue pages, routes) without disrupting the rest of the route.

Additional Properties ​

PropertyTypeDefaultDescription
$onlyStubsarray[]When set, only these stub keys will be (re)written
$exceptStubsarray[]When set, all stubs except these will be (re)written

Methods ​

setOnly(array $only) ​

Restricts stub generation to the listed stub keys. Only meaningful when $fix = true.

php
$generator->setOnly(['controller', 'vue-index']);

setExcept(array $except) ​

Regenerates all stubs except the listed stub keys. Only meaningful when $fix = true.

php
$generator->setExcept(['migration', 'model']);

generate(): int ​

Validates that the route config exists, then delegates entirely to generateFiles(). No config writes, no resource commands, no migrations.

generateFiles() ​

Iterates the stubs defined in modularous.stubs.files and writes each one if:

  • The file does not yet exist, or
  • forcibleStub($stub) returns true

forcibleStub(string $stub): bool ​

Determines whether an existing file should be overwritten:

StateBehaviour
$force = trueAlways overwrite every stub
$fix = true + $onlyStubs setOverwrite only stubs in the onlyStubs list
$fix = true + $exceptStubs setOverwrite all stubs not in the exceptStubs list
Neither flagNever overwrite existing files

Use Case ​

php
// Regenerate only the controller and Vue index page for the 'Post' route
$generator = new StubsGenerator('Post', $config, $filesystem, $console, $module);
$generator
    ->setFix(true)
    ->setOnly(['controller', 'vue-index'])
    ->generate();

This is the generator used when running modularous:fix:stubs — it lets developers refresh auto-generated boilerplate without losing manual edits to files like the migration or model.