mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #9 from utopia-php/feat-add-adapter-pattern
feat: draft for adapter pattern
This commit is contained in:
5 files changed
+46
-13
No files matched your search
Generated
+7
-7
@@ -1095,16 +1095,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "9.5.25",
|
||||
"version": "9.5.26",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d"
|
||||
"reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d",
|
||||
"reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/851867efcbb6a1b992ec515c71cdcf20d895e9d2",
|
||||
"reference": "851867efcbb6a1b992ec515c71cdcf20d895e9d2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1177,7 +1177,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.25"
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.26"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -1193,7 +1193,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-09-25T03:44:45+00:00"
|
||||
"time": "2022-10-28T06:00:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
@@ -2382,5 +2382,5 @@
|
||||
"ext-mongodb": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.2.0"
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Utopia\Mongo;
|
||||
|
||||
abstract class Adapter
|
||||
{
|
||||
abstract public function isConnected(): bool;
|
||||
abstract public function connect(
|
||||
string $host,
|
||||
int $port = null,
|
||||
float $timeout = null
|
||||
): bool;
|
||||
abstract public function send(mixed $data): int|bool;
|
||||
abstract public function recv(int $timeout = null): string|bool;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Utopia\Mongo\Adapter;
|
||||
|
||||
use Swoole\Client;
|
||||
use Utopia\Mongo\Adapter;
|
||||
|
||||
class SwooleClient extends Adapter
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Utopia\Mongo\Adapter;
|
||||
|
||||
use Utopia\Mongo\Adapter;
|
||||
|
||||
class SwooleCoroutineClient extends Adapter
|
||||
{
|
||||
|
||||
}
|
||||
+3
-6
@@ -17,7 +17,7 @@ class Client
|
||||
/**
|
||||
* Socket (sync or async) client.
|
||||
*/
|
||||
private SwooleClient|CoroutineClient $client;
|
||||
private Adapter $client;
|
||||
|
||||
/**
|
||||
* Defines commands Mongo uses over wire protocol.
|
||||
@@ -72,16 +72,13 @@ class Client
|
||||
int $port,
|
||||
string $user,
|
||||
string $password,
|
||||
bool $useCoroutine = true
|
||||
Adapter $adapter
|
||||
){
|
||||
$this->id = uniqid('utopia.mongo.client');
|
||||
$this->database = $database;
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
|
||||
$this->client = $useCoroutine
|
||||
? new CoroutineClient(SWOOLE_SOCK_TCP | SWOOLE_KEEP)
|
||||
: new SwooleClient(SWOOLE_SOCK_TCP | SWOOLE_KEEP);
|
||||
$this->client = $adapter;
|
||||
|
||||
$this->auth = new Auth([
|
||||
'authcid' => $user,
|
||||
|
||||
Reference in new issue
Block a user