From cbe7caad1f81c2cf64e99009f392a63806e295a4 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 23 Jul 2025 08:44:38 +0300 Subject: [PATCH] update driver to 2.1.1 --- Dockerfile-php-8.3 | 2 +- composer.json | 4 ++-- composer.lock | 25 ++++++++++++------------- src/Client.php | 19 ++++++++++--------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Dockerfile-php-8.3 b/Dockerfile-php-8.3 index cb031e1f47..d65b1c804e 100644 --- a/Dockerfile-php-8.3 +++ b/Dockerfile-php-8.3 @@ -13,7 +13,7 @@ RUN composer update --ignore-platform-reqs --optimize-autoloader \ FROM appwrite/utopia-base:php-8.3-0.1.0 as compile -ENV PHP_MONGO_VERSION=1.11.1 +ENV PHP_MONGO_VERSION=2.1.1 RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone diff --git a/composer.json b/composer.json index 1ee3dcb499..8ca49e8158 100755 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ }, "require": { "php": ">=8.0", - "ext-mongodb": "*", + "ext-mongodb": "2.1.1", "mongodb/mongodb": "2.1.0" }, "require-dev": { @@ -37,6 +37,6 @@ "phpunit/phpunit": "^9.4", "swoole/ide-helper": "4.8.0", "laravel/pint": "1.2.*", - "phpstan/phpstan": "1.8.*" + "phpstan/phpstan": "2.1.*" } } diff --git a/composer.lock b/composer.lock index 0fa64a4865..444eb47507 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6def0d090ef1b5df4a7d2af3ea71fe1c", + "content-hash": "66c3842bf94f4946d1277b41cf28219d", "packages": [ { "name": "mongodb/mongodb", @@ -648,20 +648,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.8.11", + "version": "2.1.19", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "46e223dd68a620da18855c23046ddb00940b4014" + "reference": "473a8c30e450d87099f76313edcbb90852f9afdf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46e223dd68a620da18855c23046ddb00940b4014", - "reference": "46e223dd68a620da18855c23046ddb00940b4014", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/473a8c30e450d87099f76313edcbb90852f9afdf", + "reference": "473a8c30e450d87099f76313edcbb90852f9afdf", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -686,8 +686,11 @@ "static analysis" ], "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.8.11" + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, "funding": [ { @@ -697,13 +700,9 @@ { "url": "https://github.com/phpstan", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" } ], - "time": "2022-10-24T15:45:13+00:00" + "time": "2025-07-21T19:58:24+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2318,7 +2317,7 @@ "prefer-lowest": false, "platform": { "php": ">=8.0", - "ext-mongodb": "*" + "ext-mongodb": "2.1.1" }, "platform-dev": [], "plugin-api-version": "2.2.0" diff --git a/src/Client.php b/src/Client.php index 2e61c49451..29d7ce1245 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,7 +2,8 @@ namespace Utopia\Mongo; -use MongoDB\BSON; +use MongoDB\BSON\Document; +use MongoDB\BSON\ObjectId; use Swoole\Client as SwooleClient; use Swoole\Coroutine\Client as CoroutineClient; use stdClass; @@ -141,7 +142,7 @@ class Client '$db' => $db ?? $this->database, ]); - $sections = BSON\fromPHP($params); + $sections = Document::fromPHP($params); $message = pack('V*', 21 + strlen($sections), $this->id, 0, 2013, 0) . "\0" . $sections; return $this->send($message); } @@ -201,11 +202,11 @@ class Client (!isset($responseLength)) || ($receivedLength < $responseLength) ); - /** - * @var stdClass $result - */ - $result = BSON\toPHP(substr($res, 21, $responseLength - 21)); - + $bsonString = substr($res, 21, $responseLength - 21); + $result = Document::fromBSON($bsonString)->toPHP(); + if (is_array($result)) { + $result = (object) $result; + } if (property_exists($result, "writeErrors")) { // Throws Utopia\Mongo\Exception throw new Exception( @@ -439,7 +440,7 @@ class Client $docObj->{$key} = $value; } - $docObj->_id ??= new BSON\ObjectId(); + $docObj->_id ??= new ObjectId(); $this->query(array_merge([ self::COMMAND_INSERT => $collection, @@ -464,7 +465,7 @@ class Client $docObj->{$key} = $value; } - $docObj->_id ??= new BSON\ObjectId(); + $docObj->_id ??= new ObjectId(); $docObjs[] = $docObj; }