Phase 2 sub-commit 2: ModelPublisher + #[BridgeResource] + Doctrine listener
Some checks failed
CI / Quality (push) Failing after 1m54s
Some checks failed
CI / Quality (push) Failing after 1m54s
Bundle gains the model layer that bridges Doctrine entities to Mercure
without per-resource glue. Three new pieces:
- `#[BridgeResource(name: ?string)]` attribute marks an entity as a
reactive bridge model. Topic name defaults to the lowercased class
basename and can be overridden per resource.
- `ModelPublisher` translates entity changes into PLAN.md §4 envelopes
({op, id, data, version, ?correlationKey}) and dual-publishes them
on `app://model/{name}` (collection topic) and `app://model/{name}/{id}`
(entity topic). Entity normalisation goes through Symfony's Serializer
(ObjectNormalizer + DateTime + BackedEnum) for predictable JSON. The
envelope `version` field is a per-process monotonic counter — fine for
single-instance dev mode; production should back this with a Postgres
SEQUENCE or equivalent (noted for Phase 4).
- `DoctrineBridgeListener` registers `postPersist`/`postUpdate`/
`postRemove` via `#[AsDoctrineListener]` and routes events through
ModelPublisher. Entities without `#[BridgeResource]` are silently
skipped.
Plus the correlation-key plumbing the §5 Update Semantics layer needs:
- `CorrelationContext` is a per-request holder for the originating
request's `Idempotency-Key`.
- `CorrelationKeyListener` reads the header on `KernelEvents::REQUEST`
and clears the context on `KernelEvents::TERMINATE` (worker mode
hygiene). CLI mutations see no key, which is correct.
Bundle composer.json picks up `doctrine/dbal`, `doctrine/orm`,
`doctrine/doctrine-bundle`, `symfony/serializer`, `symfony/property-*`,
`symfony/uid`. PHPStan extension `phpstan-doctrine` added so the listener's
event-args types resolve. Skeleton's framework.yaml enables `serializer`
and `property_info`.
Tests: 5 new for ModelPublisher (dual publish, correlation echo, delete
op omits data, untagged entities ignored, version increments). Total:
16 tests, 45 assertions, PHPStan clean, cs-fixer clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,19 +12,22 @@
|
||||
"symfony/http-foundation": "^8.0",
|
||||
"symfony/console": "^8.0",
|
||||
"symfony/dependency-injection": "^8.0",
|
||||
"symfony/config": "^8.0"
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/dbal": "Required for the bridge:doctor database-reachable check and for ModelPublisher (Phase 2 sub-commit 2).",
|
||||
"doctrine/orm": "Required for #[BridgeResource]-based reactive models (Phase 2 sub-commit 2)."
|
||||
"symfony/config": "^8.0",
|
||||
"symfony/serializer": "^8.0",
|
||||
"symfony/property-access": "^8.0",
|
||||
"symfony/property-info": "^8.0",
|
||||
"symfony/uid": "^8.0",
|
||||
"doctrine/dbal": "^4.0",
|
||||
"doctrine/orm": "^3.0",
|
||||
"doctrine/doctrine-bundle": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^11",
|
||||
"phpstan/phpstan": "^2",
|
||||
"phpstan/phpstan-symfony": "^2",
|
||||
"phpstan/phpstan-doctrine": "^2",
|
||||
"friendsofphp/php-cs-fixer": "^3",
|
||||
"symfony/phpunit-bridge": "^8.0",
|
||||
"doctrine/dbal": "^4.0"
|
||||
"symfony/phpunit-bridge": "^8.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
Reference in New Issue
Block a user