Skip to content
docsv0.24.0

ControllerGenerator

Generates a controller in one of two conventions — see {@see Flavor} — auto-detected per app root by {@see ConventionDetector} (override with `GenerationContext`'s `flavor` option, e.g. `--flavor=runtime`): - **Legacy**: extends {@see \Milpa\app\Providers\BaseController} with one routed method per `--methods` entry (`#[Route]`, `array $params = []`, `HttpResponse`). Follows the framework's controller convention exactly so {@see \Milpa\DevTools\Verify\ControllerVerifier} passes on the output. - **Runtime**: a plain, dependency-free `final class` with a single `index(ServerRequestInterface $request): ResponseInterface` method — the `milpa/runtime` + skeleton convention, modelled on the skeleton's `HomeController`. An orphaned controller class boots nothing on its own, so this path ALSO wires a booting `GET <path> → Controller::index` route: a minimal `RouteProviderInterface` plugin is generated alongside the controller when the target plugin area doesn't exist yet, or the exact route snippet to add by hand is returned via {@see GenerationResult::$guidance} when it does — see {@see self::wireRoute()}.

ControllerGenerator::__construct()

public function __construct(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
$rendererMilpa\DevTools\Make\StubRenderer
$detectorMilpa\DevTools\Make\ConventionDetector
$markersMilpa\DevTools\Make\MarkerInserter
$surgeonMilpa\DevTools\Make\PluginSurgeon

ControllerGenerator::name()

public function name(): string

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

ControllerGenerator::generate()

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

Renders the controller (+ route wiring for runtime) per the detected/overridden {@see Flavor}.

Parameters

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