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

38 lines
981 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace PhpQml\Bridge;
/**
* Default implementation of {@see CorrelationContextInterface}: a plain
* per-request holder for the `Idempotency-Key` value.
*
* 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*).
*
* Cleared on TerminateEvent. CLI commands and out-of-request mutations
* see no correlation key, which is the correct behaviour.
*/
final class CorrelationContext implements CorrelationContextInterface
{
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;
}
}