Files
php-qml/framework/php/src/CorrelationContext.php
T

37 lines
814 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace PhpQml\Bridge;
/**
* Per-request correlation key holder.
*
* The HTTP request's `Idempotency-Key` (PLAN.md §4 *Idempotency*) is
* stashed here on RequestEvent and read back by ModelPublisher when
* it builds Mercure envelopes, so QML clients can match Mercure echoes
* to the optimistic mutation that originated them (§5).
*
* Cleared on TerminateEvent. CLI commands and out-of-request mutations
* see no correlation key, which is the correct behaviour.
*/
final class CorrelationContext
{
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;
}
}