Skip to content

Commit 9d04bcd

Browse files
committed
PHPC-509: Default Manager URI to "mongodb://localhost:27017/"
1 parent 79c268a commit 9d04bcd

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

src/MongoDB/Manager.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@
4848
#include "php_phongo.h"
4949
#include "php_bson.h"
5050

51+
#define PHONGO_MANAGER_URI_DEFAULT "mongodb://localhost:27017/"
5152

5253
PHONGO_API zend_class_entry *php_phongo_manager_ce;
5354

5455
zend_object_handlers php_phongo_handler_manager;
5556

56-
/* {{{ proto MongoDB\Driver\Manager Manager::__construct(string $uri[, array $options = array()[, array $driverOptions = array()]])
57+
/* {{{ proto MongoDB\Driver\Manager Manager::__construct([string $uri = "mongodb://localhost:27017/"[, array $options = array()[, array $driverOptions = array()]]])
5758
Constructs a new Manager */
5859
PHP_METHOD(Manager, __construct)
5960
{
6061
php_phongo_manager_t *intern;
6162
zend_error_handling error_handling;
6263
mongoc_uri_t *uri;
63-
char *uri_string;
64-
int uri_string_len;
64+
char *uri_string = NULL;
65+
int uri_string_len = 0;
6566
zval *options = NULL;
6667
bson_t bson_options = BSON_INITIALIZER;
6768
zval *driverOptions = NULL;
@@ -71,19 +72,18 @@ PHP_METHOD(Manager, __construct)
7172
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
7273
intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
7374

74-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a!a!", &uri_string, &uri_string_len, &options, &driverOptions) == FAILURE) {
75+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!a!a!", &uri_string, &uri_string_len, &options, &driverOptions) == FAILURE) {
7576
zend_restore_error_handling(&error_handling TSRMLS_CC);
7677
return;
7778
}
7879
zend_restore_error_handling(&error_handling TSRMLS_CC);
7980

80-
8181
if (options) {
8282
zval_to_bson(options, PHONGO_BSON_NONE, &bson_options, NULL TSRMLS_CC);
8383
}
8484

85-
if (!(uri = php_phongo_make_uri(uri_string, &bson_options))) {
86-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Failed to parse MongoDB URI: '%s'", uri_string);
85+
if (!(uri = php_phongo_make_uri(uri_string ? uri_string : PHONGO_MANAGER_URI_DEFAULT, &bson_options))) {
86+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Failed to parse MongoDB URI: '%s'", uri_string ? uri_string : PHONGO_MANAGER_URI_DEFAULT);
8787
bson_destroy(&bson_options);
8888

8989
return;
@@ -93,7 +93,7 @@ PHP_METHOD(Manager, __construct)
9393
mongoc_uri_destroy(uri);
9494

9595
if (!intern->client) {
96-
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to create Manager from URI: '%s'", uri_string);
96+
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to create Manager from URI: '%s'", uri_string ? uri_string : PHONGO_MANAGER_URI_DEFAULT);
9797
bson_destroy(&bson_options);
9898

9999
return;
@@ -323,7 +323,7 @@ PHP_METHOD(Manager, __wakeUp)
323323
*/
324324
/* {{{ MongoDB\Driver\Manager */
325325

326-
ZEND_BEGIN_ARG_INFO_EX(ai_Manager___construct, 0, 0, 1)
326+
ZEND_BEGIN_ARG_INFO_EX(ai_Manager___construct, 0, 0, 0)
327327
ZEND_ARG_INFO(0, uri)
328328
ZEND_ARG_ARRAY_INFO(0, options, 0)
329329
ZEND_ARG_ARRAY_INFO(0, driverOptions, 0)

tests/manager/manager-ctor-001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
--TEST--
2-
MongoDB\Driver\Manager::__construct()
2+
MongoDB\Driver\Manager::__construct() with default URI
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?>
55
--FILE--
66
<?php
77
require_once __DIR__ . "/../utils/basic.inc";
88

9-
$manager = new MongoDB\Driver\Manager(STANDALONE);
9+
$manager = new MongoDB\Driver\Manager();
1010

1111
?>
1212
===DONE===

tests/manager/manager-ctor-002.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct() with URI
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$manager = new MongoDB\Driver\Manager(STANDALONE);
10+
11+
?>
12+
===DONE===
13+
<?php exit(0); ?>
14+
--EXPECT--
15+
===DONE===

0 commit comments

Comments
 (0)