Skip to content
docsv0.24.0

ServiceGenerator

Generates a domain service — a plain, dependency-free class (optionally paired with a companion interface it implements, via `--interface`) targeting an EXISTING (or about-to-exist) plugin, the same `<Plugin> <Name>` shape {@see ControllerGenerator}/{@see EntityGenerator} use. A freestanding service class does nothing on its own until something resolves it from the DI container, so — mirroring {@see ControllerGenerator::wireRoute()} / {@see EntityGenerator::wireRepository()} exactly, one concern swapped for another (route/repository registration -> service registration) — this generator ALSO wires the new service into the target plugin's `boot()`: - No `PluginInterface` plugin exists yet at the target area's conventional path (`{appDir}/Plugins/{plugin}/{plugin}.php`) -> a minimal one is generated alongside the service, its `boot()` already registering `new Service()` under the service's own class (or its interface, when `--interface` was used) — plus guidance to register the new plugin class in `config/plugins.php`. - One already exists AND carries the {@see \Milpa\DevTools\Make\Markers::SERVICES} anchor (F1) -> the registration is INSERTED at that marker via {@see \Milpa\DevTools\Make\MarkerInserter} — a deterministic splice at a known anchor, not a rewrite — see {@see self::wireService()}. - One already exists but carries NO marker -> the registration is spliced STRUCTURALLY into its `boot()` via {@see \Milpa\DevTools\Make\PluginSurgeon} (same ladder as `make:crud`); only a file the surgeon refuses (naming the reason) falls back to a guidance snippet. Only a RUNTIME convention exists — see {@see generate()} for why LEGACY throws.

ServiceGenerator::__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

ServiceGenerator::name()

public function name(): string

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

ServiceGenerator::generate()

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

Renders the service (+ interface, + plugin wiring) 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()}.

ServiceGenerator::registrationSnippet()

public function registrationSnippet(string $registrationFqcn, string $serviceFqcn): string

The `registerService()` statement that registers `$serviceFqcn` under `$registrationFqcn`, with both class references fully qualified inline so splicing it into any plugin file — at a marker, structurally, or by hand — never has to touch the target's import block. {@see wireService()} and {@see ResourceGenerator} both land exactly this shape: one authority for what "the service is registered" looks like.

Parameters

Parameters of registrationSnippet()
NameTypeDescription
$registrationFqcnstring
$serviceFqcnstring