4848#include "php_phongo.h"
4949#include "php_bson.h"
5050
51+ #define PHONGO_MANAGER_URI_DEFAULT "mongodb://localhost:27017/"
5152
5253PHONGO_API zend_class_entry * php_phongo_manager_ce ;
5354
5455zend_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 */
5859PHP_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 )
0 commit comments