Skip to content

Commit c4b2651

Browse files
committed
PHON-31: Add stream context options
1 parent 390ef25 commit c4b2651

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/MongoDB/Manager.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <php.h>
3333
#include <php_ini.h>
3434
#include <ext/standard/info.h>
35+
#include <ext/standard/file.h>
3536
#include <Zend/zend_interfaces.h>
3637
#include <ext/spl/spl_iterators.h>
3738
/* Our Compatability header */
@@ -73,6 +74,20 @@ PHP_METHOD(Manager, __construct)
7374
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "%s", "Failed to parse MongoDB URI");
7475
return;
7576
}
77+
if (driverOptions) {
78+
zval **tmp;
79+
80+
if (zend_hash_find(Z_ARRVAL_P(driverOptions), "context", strlen("context") + 1, (void**)&tmp) == SUCCESS) {
81+
ctx = php_stream_context_from_zval(*tmp, PHP_FILE_NO_DEFAULT_CONTEXT);
82+
}
83+
84+
if (zend_hash_find(Z_ARRVAL_P(driverOptions), "debug", strlen("debug") + 1, (void**)&tmp) == SUCCESS) {
85+
convert_to_string(*tmp);
86+
87+
zend_alter_ini_entry_ex(ZEND_STRS((char *)"phongo.debug_log"), Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
88+
}
89+
}
90+
7691
mongoc_client_set_stream_initiator(intern->client, phongo_stream_initiator, ctx);
7792
}
7893
/* }}} */

src/MongoDB/Server.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <php.h>
3333
#include <php_ini.h>
3434
#include <ext/standard/info.h>
35+
#include <ext/standard/file.h>
3536
#include <Zend/zend_interfaces.h>
3637
#include <ext/spl/spl_iterators.h>
3738
/* Our Compatability header */
@@ -80,6 +81,20 @@ PHP_METHOD(Server, __construct)
8081
return;
8182
}
8283

84+
if (driverOptions) {
85+
zval **tmp;
86+
87+
if (zend_hash_find(Z_ARRVAL_P(driverOptions), "context", strlen("context") + 1, (void**)&tmp) == SUCCESS) {
88+
ctx = php_stream_context_from_zval(*tmp, PHP_FILE_NO_DEFAULT_CONTEXT);
89+
}
90+
91+
if (zend_hash_find(Z_ARRVAL_P(driverOptions), "debug", strlen("debug") + 1, (void**)&tmp) == SUCCESS) {
92+
convert_to_string(*tmp);
93+
94+
zend_alter_ini_entry_ex(ZEND_STRS((char *)"phongo.debug_log"), Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
95+
}
96+
}
97+
8398
mongoc_client_set_stream_initiator(intern->client, phongo_stream_initiator, ctx);
8499
mongoc_uri_destroy(uri);
85100
}

0 commit comments

Comments
 (0)