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

Ensure options in mongo uri of integer type to be integers after extracting them

Kevin de Heer 6 лет назад
Родитель
Сommit
1fe220e0c7
2 измененных файлов с 10 добавлено и 0 удалено
  1. 2 0
      lib/Mongo/MongoClient.php
  2. 8 0
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php

+ 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];
             }

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

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