48
48
#include "php_phongo.h"
49
49
#include "php_bson.h"
50
50
51
+ #define PHONGO_MANAGER_URI_DEFAULT "mongodb://localhost:27017/"
51
52
52
53
PHONGO_API zend_class_entry * php_phongo_manager_ce ;
53
54
54
55
zend_object_handlers php_phongo_handler_manager ;
55
56
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()] ]])
57
58
Constructs a new Manager */
58
59
PHP_METHOD (Manager , __construct )
59
60
{
60
61
php_phongo_manager_t * intern ;
61
62
zend_error_handling error_handling ;
62
63
mongoc_uri_t * uri ;
63
- char * uri_string ;
64
- int uri_string_len ;
64
+ char * uri_string = NULL ;
65
+ int uri_string_len = 0 ;
65
66
zval * options = NULL ;
66
67
bson_t bson_options = BSON_INITIALIZER ;
67
68
zval * driverOptions = NULL ;
@@ -71,19 +72,18 @@ PHP_METHOD(Manager, __construct)
71
72
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
72
73
intern = (php_phongo_manager_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
73
74
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 ) {
75
76
zend_restore_error_handling (& error_handling TSRMLS_CC );
76
77
return ;
77
78
}
78
79
zend_restore_error_handling (& error_handling TSRMLS_CC );
79
80
80
-
81
81
if (options ) {
82
82
zval_to_bson (options , PHONGO_BSON_NONE , & bson_options , NULL TSRMLS_CC );
83
83
}
84
84
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 );
87
87
bson_destroy (& bson_options );
88
88
89
89
return ;
@@ -93,7 +93,7 @@ PHP_METHOD(Manager, __construct)
93
93
mongoc_uri_destroy (uri );
94
94
95
95
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 );
97
97
bson_destroy (& bson_options );
98
98
99
99
return ;
@@ -323,7 +323,7 @@ PHP_METHOD(Manager, __wakeUp)
323
323
*/
324
324
/* {{{ MongoDB\Driver\Manager */
325
325
326
- ZEND_BEGIN_ARG_INFO_EX (ai_Manager___construct , 0 , 0 , 1 )
326
+ ZEND_BEGIN_ARG_INFO_EX (ai_Manager___construct , 0 , 0 , 0 )
327
327
ZEND_ARG_INFO (0 , uri )
328
328
ZEND_ARG_ARRAY_INFO (0 , options , 0 )
329
329
ZEND_ARG_ARRAY_INFO (0 , driverOptions , 0 )
0 commit comments