diff --git a/src/Application.php b/src/Application.php index a9c617b2..d99559fe 100644 --- a/src/Application.php +++ b/src/Application.php @@ -39,7 +39,7 @@ public function __construct( array $map = [], private readonly Logger $logger = new Logger(), private array $senders = [], - bool $configureUI = true, + bool $withFrontend = true, ) { $this->buffer = new Buffer(bufferSize: 10485760, timer: 0.1); @@ -62,7 +62,7 @@ public function __construct( ); $this->processors[] = $inspector; - $configureUI and $this->configureUI(8000); + $withFrontend and $this->configureFrontend(8000); foreach ($map as $config) { $this->prepareServerFiber($config, $inspector, $this->logger); @@ -165,20 +165,20 @@ public function prepareServerFiber(SocketServer $config, Inspector $inspector, L }); } - public function configureUI(int $port): void + public function configureFrontend(int $port): void { - $this->senders[] = $wsSender = Sender\WebsocketSender::create($this->logger); + $this->senders[] = $wsSender = Sender\FrontendSender::create($this->logger); $inspector = new Inspector( $this->buffer, $this->logger, new Traffic\Dispatcher\Http( [ - new Sender\Websocket\Http\StaticFiles(), - new Sender\Websocket\Http\Events($wsSender->getEventStorage()), - new Sender\Websocket\Http\Version(), + new Sender\Frontend\Http\StaticFiles(), + new Sender\Frontend\Http\Events($wsSender->getEventStorage()), + new Sender\Frontend\Http\Version(), ], - [new Sender\Websocket\Http\RequestHandler($wsSender->getConnectionPool())], + [new Sender\Frontend\Http\RequestHandler($wsSender->getConnectionPool())], silentMode: true, ), ); diff --git a/src/Sender/Websocket/ConnectionPool.php b/src/Sender/Frontend/ConnectionPool.php similarity index 96% rename from src/Sender/Websocket/ConnectionPool.php rename to src/Sender/Frontend/ConnectionPool.php index 637957d4..d354aa58 100644 --- a/src/Sender/Websocket/ConnectionPool.php +++ b/src/Sender/Frontend/ConnectionPool.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket; +namespace Buggregator\Trap\Sender\Frontend; use Buggregator\Trap\Logger; use Buggregator\Trap\Processable; -use Buggregator\Trap\Sender\Websocket\RPC\Connect; -use Buggregator\Trap\Sender\Websocket\RPC\Response; +use Buggregator\Trap\Sender\Frontend\Message\Connect; +use Buggregator\Trap\Sender\Frontend\Message\Response; use Buggregator\Trap\Support\Json; use Buggregator\Trap\Support\Timer; use Buggregator\Trap\Support\Uuid; diff --git a/src/Sender/Websocket/Event.php b/src/Sender/Frontend/Event.php similarity index 89% rename from src/Sender/Websocket/Event.php rename to src/Sender/Frontend/Event.php index b791ee8d..8d5c94a4 100644 --- a/src/Sender/Websocket/Event.php +++ b/src/Sender/Frontend/Event.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket; +namespace Buggregator\Trap\Sender\Frontend; final class Event { diff --git a/src/Sender/Websocket/EventsStorage.php b/src/Sender/Frontend/EventsStorage.php similarity index 94% rename from src/Sender/Websocket/EventsStorage.php rename to src/Sender/Frontend/EventsStorage.php index 2f859bae..c17c16b8 100644 --- a/src/Sender/Websocket/EventsStorage.php +++ b/src/Sender/Frontend/EventsStorage.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket; +namespace Buggregator\Trap\Sender\Frontend; use Buggregator\Trap\Proto\Frame; use IteratorAggregate; diff --git a/src/Sender/Websocket/FrameHandler.php b/src/Sender/Frontend/FrameHandler.php similarity index 91% rename from src/Sender/Websocket/FrameHandler.php rename to src/Sender/Frontend/FrameHandler.php index a89990dd..f84bf041 100644 --- a/src/Sender/Websocket/FrameHandler.php +++ b/src/Sender/Frontend/FrameHandler.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket; +namespace Buggregator\Trap\Sender\Frontend; use Buggregator\Trap\Proto\Frame; use Buggregator\Trap\Sender\FrameHandler as HandlerInterface; -use Buggregator\Trap\Sender\Websocket\RPC\Push; +use Buggregator\Trap\Sender\Frontend\Message\Push; use Buggregator\Trap\Support\Json; /** diff --git a/src/Sender/Websocket/FrameMapper.php b/src/Sender/Frontend/FrameMapper.php similarity index 91% rename from src/Sender/Websocket/FrameMapper.php rename to src/Sender/Frontend/FrameMapper.php index 8688cf4f..01461231 100644 --- a/src/Sender/Websocket/FrameMapper.php +++ b/src/Sender/Frontend/FrameMapper.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket; +namespace Buggregator\Trap\Sender\Frontend; use Buggregator\Trap\Proto\Frame; use IteratorAggregate; diff --git a/src/Sender/Websocket/Http/Events.php b/src/Sender/Frontend/Http/Events.php similarity index 91% rename from src/Sender/Websocket/Http/Events.php rename to src/Sender/Frontend/Http/Events.php index 8d05e699..c6620e01 100644 --- a/src/Sender/Websocket/Http/Events.php +++ b/src/Sender/Frontend/Http/Events.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\Http; +namespace Buggregator\Trap\Sender\Frontend\Http; use Buggregator\Trap\Handler\Http\Middleware; -use Buggregator\Trap\Sender\Websocket\EventsStorage; +use Buggregator\Trap\Sender\Frontend\EventsStorage; use Buggregator\Trap\Support\Json; use Nyholm\Psr7\Response; use Psr\Http\Message\ResponseInterface; diff --git a/src/Sender/Websocket/Http/RequestHandler.php b/src/Sender/Frontend/Http/RequestHandler.php similarity index 93% rename from src/Sender/Websocket/Http/RequestHandler.php rename to src/Sender/Frontend/Http/RequestHandler.php index b2a7cf47..fdc8a514 100644 --- a/src/Sender/Websocket/Http/RequestHandler.php +++ b/src/Sender/Frontend/Http/RequestHandler.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\Http; +namespace Buggregator\Trap\Sender\Frontend\Http; use Buggregator\Trap\Handler\Http\Emitter as HttpEmitter; use Buggregator\Trap\Handler\Http\RequestHandler as RequestHandlernterace; @@ -22,7 +22,7 @@ final class RequestHandler implements RequestHandlernterace { public function __construct( - private readonly Sender\Websocket\ConnectionPool $connectionPool, + private readonly Sender\Frontend\ConnectionPool $connectionPool, ) { } diff --git a/src/Sender/Websocket/Http/StaticFiles.php b/src/Sender/Frontend/Http/StaticFiles.php similarity index 98% rename from src/Sender/Websocket/Http/StaticFiles.php rename to src/Sender/Frontend/Http/StaticFiles.php index 73ec3d92..9a58420e 100644 --- a/src/Sender/Websocket/Http/StaticFiles.php +++ b/src/Sender/Frontend/Http/StaticFiles.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\Http; +namespace Buggregator\Trap\Sender\Frontend\Http; use Buggregator\Trap\Handler\Http\Middleware; use Buggregator\Trap\Info; diff --git a/src/Sender/Websocket/Http/Version.php b/src/Sender/Frontend/Http/Version.php similarity index 94% rename from src/Sender/Websocket/Http/Version.php rename to src/Sender/Frontend/Http/Version.php index 20ae7498..f3569180 100644 --- a/src/Sender/Websocket/Http/Version.php +++ b/src/Sender/Frontend/Http/Version.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\Http; +namespace Buggregator\Trap\Sender\Frontend\Http; use Buggregator\Trap\Handler\Http\Middleware; use Buggregator\Trap\Info; diff --git a/src/Sender/Websocket/Mapper/VarDump.php b/src/Sender/Frontend/Mapper/VarDump.php similarity index 94% rename from src/Sender/Websocket/Mapper/VarDump.php rename to src/Sender/Frontend/Mapper/VarDump.php index 243f32c7..169f20da 100644 --- a/src/Sender/Websocket/Mapper/VarDump.php +++ b/src/Sender/Frontend/Mapper/VarDump.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\Mapper; +namespace Buggregator\Trap\Sender\Frontend\Mapper; use Buggregator\Trap\Proto\Frame\VarDumper; -use Buggregator\Trap\Sender\Websocket\Event; +use Buggregator\Trap\Sender\Frontend\Event; use Buggregator\Trap\Support\Uuid; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Cloner\Stub; diff --git a/src/Sender/Websocket/RPC/Connect.php b/src/Sender/Frontend/Message/Connect.php similarity index 92% rename from src/Sender/Websocket/RPC/Connect.php rename to src/Sender/Frontend/Message/Connect.php index 21f7d399..a3e9ef26 100644 --- a/src/Sender/Websocket/RPC/Connect.php +++ b/src/Sender/Frontend/Message/Connect.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\RPC; +namespace Buggregator\Trap\Sender\Frontend\Message; use Buggregator\Trap\Info; use JsonSerializable; diff --git a/src/Sender/Websocket/RPC/Push.php b/src/Sender/Frontend/Message/Push.php similarity index 92% rename from src/Sender/Websocket/RPC/Push.php rename to src/Sender/Frontend/Message/Push.php index 7243db8d..808a1ffb 100644 --- a/src/Sender/Websocket/RPC/Push.php +++ b/src/Sender/Frontend/Message/Push.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\RPC; +namespace Buggregator\Trap\Sender\Frontend\Message; use JsonSerializable; diff --git a/src/Sender/Websocket/RPC/Response.php b/src/Sender/Frontend/Message/Response.php similarity index 90% rename from src/Sender/Websocket/RPC/Response.php rename to src/Sender/Frontend/Message/Response.php index fcbb0f08..a1c1017b 100644 --- a/src/Sender/Websocket/RPC/Response.php +++ b/src/Sender/Frontend/Message/Response.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\RPC; +namespace Buggregator\Trap\Sender\Frontend\Message; use JsonSerializable; diff --git a/src/Sender/Websocket/RPC/Rpc.php b/src/Sender/Frontend/Message/Rpc.php similarity index 86% rename from src/Sender/Websocket/RPC/Rpc.php rename to src/Sender/Frontend/Message/Rpc.php index e5596c6a..e6773af0 100644 --- a/src/Sender/Websocket/RPC/Rpc.php +++ b/src/Sender/Frontend/Message/Rpc.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\RPC; +namespace Buggregator\Trap\Sender\Frontend\Message; use JsonSerializable; diff --git a/src/Sender/Websocket/RPC/Success.php b/src/Sender/Frontend/Message/Success.php similarity index 89% rename from src/Sender/Websocket/RPC/Success.php rename to src/Sender/Frontend/Message/Success.php index f5057341..3489da74 100644 --- a/src/Sender/Websocket/RPC/Success.php +++ b/src/Sender/Frontend/Message/Success.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket\RPC; +namespace Buggregator\Trap\Sender\Frontend\Message; use JsonSerializable; diff --git a/src/Sender/Websocket/RPC.php b/src/Sender/Frontend/RPC.php similarity index 82% rename from src/Sender/Websocket/RPC.php rename to src/Sender/Frontend/RPC.php index 8587bcab..4ea9b63b 100644 --- a/src/Sender/Websocket/RPC.php +++ b/src/Sender/Frontend/RPC.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket; +namespace Buggregator\Trap\Sender\Frontend; use Buggregator\Trap\Handler\Router\Method; use Buggregator\Trap\Handler\Router\Router; @@ -27,7 +27,7 @@ public function __construct( * method?: non-empty-string, * } $message */ - public function handleMessage(mixed $message): ?RPC\Rpc + public function handleMessage(mixed $message): ?Message\Rpc { try { if (!\is_array($message)) { @@ -45,7 +45,7 @@ public function handleMessage(mixed $message): ?RPC\Rpc return null; } - private function callMethod(string $initMethod): ?RPC\Rpc + private function callMethod(string $initMethod): ?Message\Rpc { [$method, $path] = \explode(':', $initMethod, 2); @@ -57,6 +57,6 @@ private function callMethod(string $initMethod): ?RPC\Rpc } $result = $route(); - return $result === null ? null : new RPC\Rpc(data: $result); + return $result === null ? null : new Message\Rpc(data: $result); } } diff --git a/src/Sender/Websocket/Service.php b/src/Sender/Frontend/Service.php similarity index 73% rename from src/Sender/Websocket/Service.php rename to src/Sender/Frontend/Service.php index f77d687d..184673f9 100644 --- a/src/Sender/Websocket/Service.php +++ b/src/Sender/Frontend/Service.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Buggregator\Trap\Sender\Websocket; +namespace Buggregator\Trap\Sender\Frontend; use Buggregator\Trap\Handler\Router\Attribute\RegexpRoute; use Buggregator\Trap\Handler\Router\Attribute\StaticRoute; @@ -23,6 +23,7 @@ public function __construct( #[RegexpRoute(Method::Delete, '#^/api/events/(?[a-f0-9-]++)#i')] public function eventDelete(string $uuid): bool { + $this->debug('Delete event %s', $uuid); $this->eventsStorage->delete($uuid); return true; } @@ -30,7 +31,13 @@ public function eventDelete(string $uuid): bool #[StaticRoute(Method::Delete, 'api/events')] public function eventsDelete(): bool { + $this->debug('Delete all events'); $this->eventsStorage->clear(); return true; } + + private function debug(string $pattern, string ...$args): void + { + $this->logger->debug("[UI Service] $pattern", ...$args); + } } diff --git a/src/Sender/WebsocketSender.php b/src/Sender/FrontendSender.php similarity index 61% rename from src/Sender/WebsocketSender.php rename to src/Sender/FrontendSender.php index dc4d867a..5e566c0b 100644 --- a/src/Sender/WebsocketSender.php +++ b/src/Sender/FrontendSender.php @@ -7,30 +7,30 @@ use Buggregator\Trap\Logger; use Buggregator\Trap\Processable; use Buggregator\Trap\Proto\Frame; -use Buggregator\Trap\Sender\Websocket\ConnectionPool; +use Buggregator\Trap\Sender\Frontend\ConnectionPool; /** * @internal */ -final class WebsocketSender implements \Buggregator\Trap\Sender, Processable +final class FrontendSender implements \Buggregator\Trap\Sender, Processable { public static function create( Logger $logger, - ?Websocket\ConnectionPool $connectionPool = null, - ?Websocket\EventsStorage $eventStorage = null, + ?Frontend\ConnectionPool $connectionPool = null, + ?Frontend\EventsStorage $eventStorage = null, ): self { - $eventStorage ??= new Websocket\EventsStorage(); - $connectionPool ??= new Websocket\ConnectionPool($logger, new Websocket\RPC($logger, $eventStorage)); + $eventStorage ??= new Frontend\EventsStorage(); + $connectionPool ??= new Frontend\ConnectionPool($logger, new Frontend\RPC($logger, $eventStorage)); return new self( $connectionPool, $eventStorage, - new Websocket\FrameHandler($connectionPool, $eventStorage), + new Frontend\FrameHandler($connectionPool, $eventStorage), ); } private function __construct( private readonly ConnectionPool $connectionPool, - private readonly Websocket\EventsStorage $framesStorage, + private readonly Frontend\EventsStorage $framesStorage, private readonly FrameHandler $handler, ) { } @@ -52,9 +52,9 @@ public function getConnectionPool(): ConnectionPool } /** - * @return Websocket\EventsStorage + * @return Frontend\EventsStorage */ - public function getEventStorage(): Websocket\EventsStorage + public function getEventStorage(): Frontend\EventsStorage { return $this->framesStorage; }