Skip to content

🧰 Pillar Facade

Prefer dependency injection for core domain code, but the Pillar facade is a handy convenience in application code, console commands, and tests.

While the facade gives you quick access to core Pillar services, it is not intended for deep domain logic.
Your aggregates, projectors, and domain services should instead depend on the underlying abstractions directly:

Methods

Tinker Support

Pillar provides a rich developer experience inside php artisan tinker:

  • The Pillar facade is auto‑aliased — no use statement needed.
  • Commands, queries, and aggregate IDs from your registered Context Registries are also auto‑aliased.
  • Event‑sourced aggregates use a custom Tinker caster so they display meaningful state instead of …3.

Example

php
> $customer = Pillar::dispatch(new CreateCustomerCommand("Alex Developer"));
[!] Aliasing 'CreateCustomerCommand' to 'App\Billing\Application\Command\CreateCustomerCommand' for this Tinker session.
= App\Billing\Domain\Aggregate\Customer {#1234 …1}

> $customer;
= App\Billing\Domain\Aggregate\Customer {#1234
    id: "a02a5f0c-9317-4c72-8bf0-2a6df3c64101",
    name: "Alex Developer",
  }

This makes Tinker perfect for interactively experimenting with your domain model, trying commands end‑to‑end, and inspecting aggregate state without writing temporary routes or scripts.

  • Pillar::session(): AggregateSession — returns a fresh Aggregate Session for loading and committing aggregates.
  • Pillar::dispatch(object $command): void — dispatches a command through the registered Command Bus.
  • Pillar::ask(object $query): mixed — executes a query through the Query Bus.

Usage

Below is a typical application-layer example—calling Pillar from controllers, console commands, or other framework-facing code.

Example

php
$session = Pillar::session();

// Dispatch a command
Pillar::dispatch(new CreateDocumentCommand($id, $title, $authorId));

// Ask a query
$document = Pillar::ask(new FindDocumentQuery($id));

📝 Note:
The facade is intentionally thin. It does not expose low-level internals and it never bypasses the session/command/query patterns that keep your domain model consistent.