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:
28
framework/php/tests/snapshot/TodoSummaryList.qml
Normal file
28
framework/php/tests/snapshot/TodoSummaryList.qml
Normal file
@@ -0,0 +1,28 @@
|
||||
// Auto-generated by `bin/console make:bridge:read-model TodoSummary`.
|
||||
// Read-only projection — no Mercure topic, no auto-updates.
|
||||
//
|
||||
// For invalidation: when the underlying data changes, dispatch a
|
||||
// domain event from PHP (see `make:bridge:event`) and call
|
||||
// `todoSummaryList.refresh()` from the event-handler in QML.
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import PhpQml.Bridge
|
||||
|
||||
ListView {
|
||||
id: todoSummaryList
|
||||
|
||||
model: ReactiveListModel {
|
||||
baseUrl: BackendConnection.url
|
||||
token: BackendConnection.token
|
||||
source: "/api/todo-summaries"
|
||||
// topic: intentionally unset — read-models are queries, not
|
||||
// reactive resources. Drive refreshes from domain events.
|
||||
}
|
||||
|
||||
delegate: ItemDelegate {
|
||||
// Replace with your projection's columns.
|
||||
text: String(model.modelData)
|
||||
width: ListView.view.width
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user