diff --git a/src/Adapter/SwooleClient.php b/src/Adapter/SwooleClient.php index dbb44470f0..c0f9386f0e 100644 --- a/src/Adapter/SwooleClient.php +++ b/src/Adapter/SwooleClient.php @@ -8,4 +8,23 @@ use Utopia\Mongo\Adapter; class SwooleClient extends Adapter { + public function isConnected(): bool + { + // TODO: Implement isConnected() method. + } + + public function connect(string $host, int $port = null, float $timeout = null): bool + { + // TODO: Implement connect() method. + } + + public function send(mixed $data): int|bool + { + // TODO: Implement send() method. + } + + public function recv(int $timeout = null): string|bool + { + // TODO: Implement recv() method. + } } diff --git a/src/Adapter/SwooleCoroutineClient.php b/src/Adapter/SwooleCoroutineClient.php index 9dd62dbd89..783c0dfe93 100644 --- a/src/Adapter/SwooleCoroutineClient.php +++ b/src/Adapter/SwooleCoroutineClient.php @@ -7,4 +7,23 @@ use Utopia\Mongo\Adapter; class SwooleCoroutineClient extends Adapter { + public function isConnected(): bool + { + // TODO: Implement isConnected() method. + } + + public function connect(string $host, int $port = null, float $timeout = null): bool + { + // TODO: Implement connect() method. + } + + public function send(mixed $data): int|bool + { + // TODO: Implement send() method. + } + + public function recv(int $timeout = null): string|bool + { + // TODO: Implement recv() method. + } } \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index e724a348c0..74d7d48304 100644 --- a/src/Client.php +++ b/src/Client.php @@ -17,7 +17,7 @@ class Client /** * Socket (sync or async) client. */ - private Adapter $client; + private SwooleClient|CoroutineClient $client; /** * Defines commands Mongo uses over wire protocol. @@ -72,13 +72,16 @@ class Client int $port, string $user, string $password, - Adapter $adapter + bool $useCoroutine = true ){ $this->id = uniqid('utopia.mongo.client'); $this->database = $database; $this->host = $host; $this->port = $port; - $this->client = $adapter; + + $this->client = $useCoroutine + ? new CoroutineClient(SWOOLE_SOCK_TCP | SWOOLE_KEEP) + : new SwooleClient(SWOOLE_SOCK_TCP | SWOOLE_KEEP); $this->auth = new Auth([ 'authcid' => $user, @@ -215,7 +218,7 @@ class Client } if ($result->ok === 1.0) { - return $result; + return $result; } return $result->cursor->firstBatch; @@ -714,13 +717,13 @@ class Client private function cleanFilters($filters):array { $cleanedFilters = []; - + foreach($filters as $k => $v) { $value = $v; if(in_array($k, ['$and', '$or', '$nor']) && is_array($v)) { $values = []; - + foreach($v as $item) { if(is_null($item)) continue; @@ -735,4 +738,4 @@ class Client return $cleanedFilters; } -} \ No newline at end of file +} diff --git a/tests/MongoTest.php b/tests/MongoTest.php index c435faca6a..273a48ada7 100644 --- a/tests/MongoTest.php +++ b/tests/MongoTest.php @@ -4,6 +4,7 @@ namespace Utopia\Tests; use MongoDB\BSON\ObjectId; use PHPUnit\Framework\TestCase; +use Utopia\Mongo\Adapter\SwooleClient; use Utopia\Mongo\Client; use Utopia\Mongo\Exception;