2026-05-02 02:32:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace PhpQml\Bridge;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-05-03 19:50:01 +02:00
|
|
|
* Default implementation of {@see CorrelationContextInterface}: a plain
|
|
|
|
|
* per-request holder for the `Idempotency-Key` value.
|
2026-05-02 02:32:51 +02:00
|
|
|
*
|
2026-05-03 19:50:01 +02:00
|
|
|
* Stashed here on RequestEvent (see {@see EventSubscriber\CorrelationKeyListener})
|
|
|
|
|
* and read back by {@see ModelPublisher} when it builds Mercure envelopes,
|
|
|
|
|
* so QML clients can match Mercure echoes to the optimistic mutation that
|
|
|
|
|
* originated them (PLAN.md §4 *Idempotency*, §5 *Optimistic updates*).
|
2026-05-02 02:32:51 +02:00
|
|
|
*
|
|
|
|
|
* Cleared on TerminateEvent. CLI commands and out-of-request mutations
|
|
|
|
|
* see no correlation key, which is the correct behaviour.
|
|
|
|
|
*/
|
2026-05-03 19:50:01 +02:00
|
|
|
final class CorrelationContext implements CorrelationContextInterface
|
2026-05-02 02:32:51 +02:00
|
|
|
{
|
|
|
|
|
private ?string $key = null;
|
|
|
|
|
|
|
|
|
|
public function set(?string $key): void
|
|
|
|
|
{
|
|
|
|
|
$this->key = $key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function clear(): void
|
|
|
|
|
{
|
|
|
|
|
$this->key = null;
|
|
|
|
|
}
|
|
|
|
|
}
|