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

Merge pull request #47 from DerManoMann/uri_protocol_prefix

Allow server name without mongodb:// prefix
Andreas 10 лет назад
Родитель
Сommit
f719cb7be3
2 измененных файлов с 10 добавлено и 1 удалено
  1. 4 1
      lib/Mongo/MongoClient.php
  2. 6 0
      tests/Alcaeus/MongoDbAdapter/MongoClientTest.php

+ 4 - 1
lib/Mongo/MongoClient.php

@@ -83,7 +83,10 @@ class MongoClient
         }
 
         $this->server = $server;
-        $this->client = new Client($server, $options, $driverOptions);
+        if (false === strpos($this->server, 'mongodb://')) {
+            $this->server = 'mongodb://'.$this->server;
+        }
+        $this->client = new Client($this->server, $options, $driverOptions);
         $info = $this->client->__debugInfo();
         $this->manager = $info['manager'];
 

+ 6 - 0
tests/Alcaeus/MongoDbAdapter/MongoClientTest.php

@@ -105,4 +105,10 @@ class MongoClientTest extends TestCase
         $this->assertArrayHasKey('databases', $databases);
         $this->assertContains('mongo-php-adapter', $databases['databases']);
     }
+
+    public function testNoPrefixUri()
+    {
+        $client = $this->getClient(null, 'localhost');
+        $this->assertNotNull($client);
+    }
 }