Skip to content
docsv0.24.0

CrudGenerator

Generates the compound: a full HTTP+persistence resource in one shot, by COMPOSING {@see EntityGenerator} (entity class + its `--fields` DSL — never reimplemented here) with a new 5-method CRUD controller and a combined repository+routes wiring plugin this generator owns. `make:controller`'s runtime stub only ever renders a single `index()` method (see its class docblock), so a REST resource controller (`index`/`show`/`create`/`update`/`delete`) is a genuinely new shape — {@see self::generateRuntime()} renders it from its own `crud-controller.runtime.php.stub` rather than calling `ControllerGenerator::generate()` at all. Likewise, wiring both a a `Milpa\Data` repository AND 5 routes into one plugin's `boot()`/`routes()` is a shape neither `entity-plugin.runtime.php.stub` (repository only) nor `plugin.runtime.php.stub` (a single GET route) covers alone, so it gets its own `crud-plugin.runtime.php.stub` too — see {@see self::wireCrudPlugin()}. `EntityGenerator::generate()` IS reused for the entity class itself (property/accessor generation from the `--fields` DSL is exactly the "do not reimplement" concern this composition avoids duplicating). Calling it in isolation would ALSO plan its own repository-only wiring plugin at this same target path when none exists on disk yet (see {@see EntityGenerator::wireRepository()}) — that planned file is superseded by this generator's own combined repo+routes plugin and dropped rather than written twice to the same path; see {@see self::generateRuntime()}. Only a RUNTIME convention exists — see {@see generate()} for why LEGACY throws.

CrudGenerator::__construct()

public function __construct(Milpa\DevTools\Make\Generators\EntityGenerator $entityGenerator = new EntityGenerator(), Milpa\DevTools\Make\StubRenderer $renderer = new StubRenderer(), Milpa\DevTools\Make\ConventionDetector $detector = new ConventionDetector(), Milpa\DevTools\Make\MarkerInserter $markers = new MarkerInserter(), Milpa\DevTools\Make\PluginSurgeon $surgeon = new PluginSurgeon()):

Parameters

Parameters of __construct()
NameTypeDescription
$entityGeneratorMilpa\DevTools\Make\Generators\EntityGenerator
$rendererMilpa\DevTools\Make\StubRenderer
$detectorMilpa\DevTools\Make\ConventionDetector
$markersMilpa\DevTools\Make\MarkerInserter
$surgeonMilpa\DevTools\Make\PluginSurgeon

CrudGenerator::name()

public function name(): string

The `<what>` token this generator answers to: `'crud'`.

CrudGenerator::generate()

public function generate(Milpa\DevTools\Make\GenerationContext $context): Milpa\DevTools\Make\GenerationResult

Renders the entity + controller + wiring plugin per the detected/overridden {@see Flavor}.

Parameters

Parameters of generate()
NameTypeDescription
$contextMilpa\DevTools\Make\GenerationContext

Throws

\RuntimeException When the detected/forced flavor is {@see Flavor::Legacy} — see {@see generateLegacy()}.