chore: complete update
This commit is contained in:
92
src/Framework/Router/Result/SseResultWithCallback.php
Normal file
92
src/Framework/Router/Result/SseResultWithCallback.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user