Skip to content

Commands and dependency injection

#[Command]
public function generateReport(
ReportService $reports,
int $accountId,
ReportFormat $format,
bool $notify = true,
): ReportResource {
return new ReportResource(
$reports->generate($accountId, $format, $notify),
);
}

Without an explicit name, generateReport becomes generate.report. Payload fields bind by parameter name. PHP defaults and nullable types behave normally.

ReportFormat should be an integer-backed enum with sequential values. PAM constructs it through from() and never introduces string coded variants into the protocol.

final readonly class DocumentData
{
public function __construct(
public int $id,
public string $title,
public ?string $body = null,
) {}
}
#[Command('documents.save')]
public function save(DocumentData $document): array
{
return ['id' => $document->id];
}
await window.pam.invoke("documents.save", {
document: { id: 42, title: "Roadmap", body: null },
});

Nested arrays must be JSON objects with string keys. Missing, extra-type, or invalid enum values fail visibly; PAM does not guess or coerce command input.

#[Command('documents.delete')]
final class DeleteDocument
{
public function __construct(private DocumentRepository $documents) {}
public function __invoke(int $documentId, Events $events): void
{
$this->documents->delete($documentId);
$events->emit(new DocumentDeleted($documentId));
}
}
protected function commands(): array
{
return [DeleteDocument::class];
}
Type Injected value
WindowHandle Source window for this invocation
Windows Validated named-window registry
DesktopWindow subclass One declared named window
Events Typed frontend-event collector
ApplicationControl Application lifecycle effects
CommandContext Raw low-level request context

Effects and events are accumulated and merged with the method’s return after successful execution. If the method throws, no partial response is published.

Arrays, objects, strings, integers, booleans, and null become successful payloads automatically.