v0.2.0 (8/N): make:bridge:read-model maker
Implements PLAN.md §8's fourth makers-table row. Read-models are
server-side projections — joined fetches, aggregates, denormalised
views — that QML reads without going through a writable
#[BridgeResource]. The maker emits:
- src/ReadModel/<Name>ReadModel.php — query service stub injecting
EntityManagerInterface; user fills query() with DQL / QueryBuilder
/ raw SQL as fits.
- src/Controller/<Name>Controller.php — single GET handler at
/api/<kebab-plural>, just normalises the read-model output to JSON.
- {qml_path}/<Name>List.qml — ReactiveListModel bound to the route,
deliberately no Mercure topic.
The "no topic" choice is the design call worth documenting: read-models
are queries, not reactive resources, and pretending otherwise would
either auto-publish stale aggregates on every entity change or require
the user to invent invalidation logic in the listener. Better: pair
the read-model with `make:bridge:event` and call refresh() from the
QML event-handler when the underlying data really changes.
Naming convention: kebab-PLURAL routes (`/api/todo-summaries`) for
consistency with REST list semantics; resource path stays singular
under `src/ReadModel/`.
Wired into services.yaml's when@dev block. Three new snapshot
baselines (TodoSummaryReadModel.php / TodoSummaryController.php /
TodoSummaryList.qml) plus runner extension. All 14 maker outputs
verify on the committed state.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
framework/php/tests/snapshot/TodoSummaryReadModel.php
Normal file
37
framework/php/tests/snapshot/TodoSummaryReadModel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\ReadModel;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* Auto-generated query service for the TodoSummary read-model.
|
||||
*
|
||||
* Read-models are server-side projections — joined fetches, aggregates,
|
||||
* denormalised views — that QML reads without going through a writable
|
||||
* `#[BridgeResource]`. Replace the body of `query()` with the actual
|
||||
* DQL / raw SQL / joined fetch.
|
||||
*
|
||||
* Per PLAN.md §4 *Pagination*, return an array of associative arrays so
|
||||
* the controller can normalise to JSON without a serializer; or wire up
|
||||
* a normalizer if you prefer typed DTOs in the projection.
|
||||
*/
|
||||
final readonly class TodoSummaryReadModel
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function query(): array
|
||||
{
|
||||
// TODO: implement the read query — DQL, ->createQueryBuilder(),
|
||||
// or ->getConnection()->executeQuery() as fits.
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user