Просмотр исходного кода

Merge pull request #250 from kevindh89/master

Ensure options in mongo uri of integer type to be integers after extracting them
Andreas Braun 6 лет назад
Родитель
Сommit
eae6393b9d

+ 1 - 0
composer.json

@@ -10,6 +10,7 @@
     ],
     "require": {
         "php": "^5.6 || ^7.0",
+        "ext-ctype": "*",
         "ext-hash": "*",
         "ext-mongodb": "^1.2.0",
         "mongodb/mongodb": "^1.0.1"

+ 2 - 0
lib/Mongo/MongoClient.php

@@ -376,6 +376,8 @@ class MongoClient
             $keyValue = explode('=', $option);
             if ($keyValue[0] === 'readPreferenceTags') {
                 $options[$keyValue[0]][] = $this->getReadPreferenceTags($keyValue[1]);
+            } elseif (ctype_digit($keyValue[1])) {
+                $options[$keyValue[0]] = (int) $keyValue[1];
             } else {
                 $options[$keyValue[0]] = $keyValue[1];
             }

+ 7 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php

@@ -279,6 +279,13 @@ class MongoClientTest extends TestCase
         $collection->insert($document);
     }
 
+    public function testConnectionUriOptionIntegerTypeCasting()
+    {
+        $client = new \MongoClient('mongodb://localhost/db?w=0&wtimeout=0', ['connect' => false]);
+
+        $this->assertSame(['w' => 0, 'wtimeout' => 0], $client->getWriteConcern());
+    }
+
     /**
      * @param array $options
      * @return string