- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
98 lines
2.2 KiB
PHP
98 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Router\Result;
|
|
|
|
use App\Framework\Http\SseStream;
|
|
use App\Framework\Http\Status;
|
|
use App\Framework\Router\ActionResult;
|
|
|
|
/**
|
|
* Erweiterte SSE-Klasse, die eine Callback-Funktion für Live-Updates unterstützt
|
|
*/
|
|
final class SseResultWithCallback implements ActionResult
|
|
{
|
|
/**
|
|
* @var callable|null Callback-Funktion, die während des Streamings ausgeführt wird
|
|
*/
|
|
private $callback = null;
|
|
|
|
/**
|
|
* @var int Maximale Streaming-Dauer in Sekunden (0 = unbegrenzt)
|
|
*/
|
|
private int $maxDuration = 0;
|
|
|
|
/**
|
|
* @var int Intervall für Heartbeats in Sekunden
|
|
*/
|
|
private int $heartbeatInterval = 30;
|
|
|
|
public function __construct(
|
|
public readonly Status $status = Status::OK,
|
|
public readonly array $headers = []
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Setzt die Callback-Funktion, die während des Streamings aufgerufen wird
|
|
* Der Callback erhält den SseStream als Parameter
|
|
*
|
|
* @param callable $callback Funktion mit Signatur: function(SseStream $stream): void
|
|
*/
|
|
public function setCallback(callable $callback): self
|
|
{
|
|
$this->callback = $callback;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Setzt die maximale Streaming-Dauer
|
|
*
|
|
* @param int $seconds Maximale Dauer in Sekunden (0 = unbegrenzt)
|
|
*/
|
|
public function setMaxDuration(int $seconds): self
|
|
{
|
|
$this->maxDuration = $seconds;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Setzt das Intervall für Heartbeats
|
|
*
|
|
* @param int $seconds Intervall in Sekunden
|
|
*/
|
|
public function setHeartbeatInterval(int $seconds): self
|
|
{
|
|
$this->heartbeatInterval = $seconds;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Gibt den Callback zurück
|
|
*/
|
|
public function getCallback(): ?callable
|
|
{
|
|
return $this->callback;
|
|
}
|
|
|
|
/**
|
|
* Gibt die maximale Streaming-Dauer zurück
|
|
*/
|
|
public function getMaxDuration(): int
|
|
{
|
|
return $this->maxDuration;
|
|
}
|
|
|
|
/**
|
|
* Gibt das Heartbeat-Intervall zurück
|
|
*/
|
|
public function getHeartbeatInterval(): int
|
|
{
|
|
return $this->heartbeatInterval;
|
|
}
|
|
}
|