Skip to content

Commit 76e26af

Browse files
committed
(style): Replace FQNs with use imports
1 parent 4d49a05 commit 76e26af

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/Server/HTTP/Swoole.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Swoole\Coroutine\Channel;
66
use Swoole\Coroutine\Client as CoroutineClient;
7+
use Swoole\Coroutine\Http\Client as HttpClient;
78
use Swoole\Http\Request;
89
use Swoole\Http\Response;
10+
use Swoole\Http\Server;
911
use Utopia\Proxy\Adapter;
1012
use Utopia\Proxy\Protocol;
1113
use Utopia\Proxy\Resolver;
@@ -22,7 +24,7 @@
2224
*/
2325
class Swoole
2426
{
25-
protected \Swoole\Http\Server $server;
27+
protected Server $server;
2628

2729
protected Adapter $adapter;
2830

@@ -36,7 +38,7 @@ public function __construct(
3638
?Config $config = null,
3739
) {
3840
$this->config = $config ?? new Config();
39-
$this->server = new \Swoole\Http\Server(
41+
$this->server = new Server(
4042
$this->config->host,
4143
$this->config->port,
4244
$this->config->serverMode,
@@ -79,14 +81,14 @@ protected function configure(): void
7981
$this->server->on('request', $this->onRequest(...));
8082
}
8183

82-
public function onStart(\Swoole\Http\Server $server): void
84+
public function onStart(Server $server): void
8385
{
8486
echo "HTTP Proxy Server started at http://{$this->config->host}:{$this->config->port}\n";
8587
echo "Workers: {$this->config->workers}\n";
8688
echo "Max connections: {$this->config->maxConnections}\n";
8789
}
8890

89-
public function onWorkerStart(\Swoole\Http\Server $server, int $workerId): void
91+
public function onWorkerStart(Server $server, int $workerId): void
9092
{
9193
$this->adapter = new Adapter($this->resolver, name: 'HTTP', protocol: Protocol::HTTP);
9294

@@ -198,8 +200,8 @@ protected function forwardRequest(Request $request, Response $response, string $
198200

199201
$isNewClient = false;
200202
$client = $pool->pop($this->config->poolTimeout);
201-
if (!$client instanceof \Swoole\Coroutine\Http\Client) {
202-
$client = new \Swoole\Coroutine\Http\Client($host, $port);
203+
if (!$client instanceof HttpClient) {
204+
$client = new HttpClient($host, $port);
203205
$client->set([
204206
'timeout' => $this->config->timeout,
205207
'keep_alive' => $this->config->keepAlive,

src/Server/HTTP/SwooleCoroutine.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Utopia\Proxy\Server\HTTP;
44

5+
use Swoole\Coroutine;
56
use Swoole\Coroutine\Channel;
67
use Swoole\Coroutine\Client as CoroutineClient;
8+
use Swoole\Coroutine\Http\Client as HttpClient;
79
use Swoole\Coroutine\Http\Server as CoroutineServer;
810
use Swoole\Http\Request;
911
use Swoole\Http\Response;
@@ -185,8 +187,8 @@ protected function forwardRequest(Request $request, Response $response, string $
185187

186188
$isNewClient = false;
187189
$client = $pool->pop($this->config->poolTimeout);
188-
if (!$client instanceof \Swoole\Coroutine\Http\Client) {
189-
$client = new \Swoole\Coroutine\Http\Client($host, $port);
190+
if (!$client instanceof HttpClient) {
191+
$client = new HttpClient($host, $port);
190192
$client->set([
191193
'timeout' => $this->config->timeout,
192194
'keep_alive' => $this->config->keepAlive,
@@ -456,15 +458,15 @@ protected function isValidHostname(string $hostname): bool
456458

457459
public function start(): void
458460
{
459-
if (\Swoole\Coroutine::getCid() > 0) {
461+
if (Coroutine::getCid() > 0) {
460462
$this->onStart();
461463
$this->onWorkerStart(0);
462464
$this->server->start();
463465

464466
return;
465467
}
466468

467-
\Swoole\Coroutine\run(function (): void {
469+
Coroutine\run(function (): void {
468470
$this->onStart();
469471
$this->onWorkerStart(0);
470472
$this->server->start();

src/Server/TCP/Swoole.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Swoole\Coroutine;
66
use Swoole\Coroutine\Client;
7+
use Swoole\Coroutine\Socket;
78
use Swoole\Server;
89
use Utopia\Proxy\Adapter\TCP as TCPAdapter;
910
use Utopia\Proxy\Resolver;
@@ -289,7 +290,7 @@ public function onReceive(Server $server, int $fd, int $reactorId, string $data)
289290
protected function forward(Server $server, int $clientFd, Client $backendClient): void
290291
{
291292
$bufferSize = $this->config->receiveBufferSize;
292-
/** @var \Swoole\Coroutine\Socket $backendSocket */
293+
/** @var Socket $backendSocket */
293294
$backendSocket = $backendClient->exportSocket();
294295

295296
$fdKey = (string) $clientFd;

src/Server/TCP/SwooleCoroutine.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Swoole\Coroutine;
66
use Swoole\Coroutine\Server as CoroutineServer;
77
use Swoole\Coroutine\Server\Connection;
8+
use Swoole\Coroutine\Socket;
89
use Utopia\Proxy\Adapter\TCP as TCPAdapter;
910
use Utopia\Proxy\Resolver;
1011

@@ -137,7 +138,7 @@ public function onWorkerStart(int $workerId = 0): void
137138

138139
protected function handleConnection(Connection $connection, int $port): void
139140
{
140-
/** @var \Swoole\Coroutine\Socket $clientSocket */
141+
/** @var Socket $clientSocket */
141142
$clientSocket = $connection->exportSocket();
142143
$clientId = spl_object_id($connection);
143144
$adapter = $this->adapters[$port];
@@ -179,7 +180,7 @@ protected function handleConnection(Connection $connection, int $port): void
179180

180181
try {
181182
$backendClient = $adapter->getConnection($data, $clientId);
182-
/** @var \Swoole\Coroutine\Socket $backendSocket */
183+
/** @var Socket $backendSocket */
183184
$backendSocket = $backendClient->exportSocket();
184185

185186
$adapter->notifyConnect($fdKey);
@@ -247,7 +248,7 @@ public function start(): void
247248
return;
248249
}
249250

250-
\Swoole\Coroutine\run($runner);
251+
Coroutine\run($runner);
251252
}
252253

253254
/**

0 commit comments

Comments
 (0)