Skip to content

Commit

Permalink
Rename classes and namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 15, 2023
1 parent ea65f68 commit 966b704
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 44 deletions.
16 changes: 8 additions & 8 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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())],

Check failure on line 181 in src/Application.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

InternalClass

src/Application.php:181:18: InternalClass: Buggregator\Trap\Sender\Frontend\Http\RequestHandler is internal to Buggregator\Trap * Read about Sec-WebSocket-Extensions: but called from Buggregator\Trap\Application (see https://psalm.dev/174)

Check failure on line 181 in src/Application.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

InternalMethod

src/Application.php:181:18: InternalMethod: Constructor Buggregator\Trap\Sender\Frontend\Http\RequestHandler::__construct is internal to Buggregator\Trap * Read about Sec-WebSocket-Extensions: but called from Buggregator\Trap\Application::configureFrontend (see https://psalm.dev/175)
silentMode: true,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Sender\Websocket;
namespace Buggregator\Trap\Sender\Frontend;

final class Event
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +22,7 @@
final class RequestHandler implements RequestHandlernterace
{
public function __construct(
private readonly Sender\Websocket\ConnectionPool $connectionPool,
private readonly Sender\Frontend\ConnectionPool $connectionPool,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Sender\Websocket\RPC;
namespace Buggregator\Trap\Sender\Frontend\Message;

use JsonSerializable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Sender\Websocket\RPC;
namespace Buggregator\Trap\Sender\Frontend\Message;

use JsonSerializable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Sender\Websocket\RPC;
namespace Buggregator\Trap\Sender\Frontend\Message;

use JsonSerializable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Buggregator\Trap\Sender\Websocket\RPC;
namespace Buggregator\Trap\Sender\Frontend\Message;

use JsonSerializable;

Expand Down
8 changes: 4 additions & 4 deletions src/Sender/Websocket/RPC.php → src/Sender/Frontend/RPC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -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);

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,14 +23,21 @@ public function __construct(
#[RegexpRoute(Method::Delete, '#^/api/events/(?<uuid>[a-f0-9-]++)#i')]
public function eventDelete(string $uuid): bool
{
$this->debug('Delete event %s', $uuid);
$this->eventsStorage->delete($uuid);
return true;
}

#[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);
}
}
20 changes: 10 additions & 10 deletions src/Sender/WebsocketSender.php → src/Sender/FrontendSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 966b704

Please sign in to comment.