29
29
30
30
zend_class_entry * php_phongo_session_ce ;
31
31
32
+ #define SESSION_CHECK_LIVELINESS (i ,m ) \
33
+ if (!(i)->client_session) { \
34
+ phongo_throw_exception(PHONGO_ERROR_LOGIC TSRMLS_CC, "Cannot call '%s', as the session has already been ended.", (m)); \
35
+ return; \
36
+ }
37
+
32
38
static bool php_phongo_session_get_timestamp_parts (zval * obj , uint32_t * timestamp , uint32_t * increment TSRMLS_DC )
33
39
{
34
40
bool retval = false;
@@ -95,6 +101,7 @@ static PHP_METHOD(Session, advanceClusterTime)
95
101
SUPPRESS_UNUSED_WARNING (return_value_used )
96
102
97
103
intern = Z_SESSION_OBJ_P (getThis ());
104
+ SESSION_CHECK_LIVELINESS (intern , "advanceClusterTime" )
98
105
99
106
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "A" , & zcluster_time ) == FAILURE ) {
100
107
return ;
@@ -125,6 +132,7 @@ static PHP_METHOD(Session, advanceOperationTime)
125
132
SUPPRESS_UNUSED_WARNING (return_value_used )
126
133
127
134
intern = Z_SESSION_OBJ_P (getThis ());
135
+ SESSION_CHECK_LIVELINESS (intern , "advanceOperationTime" )
128
136
129
137
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "O" , & ztimestamp , php_phongo_timestamp_interface_ce ) == FAILURE ) {
130
138
return ;
@@ -148,6 +156,7 @@ static PHP_METHOD(Session, getClusterTime)
148
156
SUPPRESS_UNUSED_WARNING (return_value_used )
149
157
150
158
intern = Z_SESSION_OBJ_P (getThis ());
159
+ SESSION_CHECK_LIVELINESS (intern , "getClusterTime" )
151
160
152
161
if (zend_parse_parameters_none () == FAILURE ) {
153
162
return ;
@@ -183,6 +192,7 @@ static PHP_METHOD(Session, getLogicalSessionId)
183
192
SUPPRESS_UNUSED_WARNING (return_value_used )
184
193
185
194
intern = Z_SESSION_OBJ_P (getThis ());
195
+ SESSION_CHECK_LIVELINESS (intern , "getLogicalSessionId" )
186
196
187
197
if (zend_parse_parameters_none () == FAILURE ) {
188
198
return ;
@@ -213,6 +223,7 @@ static PHP_METHOD(Session, getOperationTime)
213
223
SUPPRESS_UNUSED_WARNING (return_value_used )
214
224
215
225
intern = Z_SESSION_OBJ_P (getThis ());
226
+ SESSION_CHECK_LIVELINESS (intern , "getOperationTime" )
216
227
217
228
if (zend_parse_parameters_none () == FAILURE ) {
218
229
return ;
@@ -310,6 +321,7 @@ static PHP_METHOD(Session, startTransaction)
310
321
SUPPRESS_UNUSED_WARNING (return_value_used )
311
322
312
323
intern = Z_SESSION_OBJ_P (getThis ());
324
+ SESSION_CHECK_LIVELINESS (intern , "startTransaction" )
313
325
314
326
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "|a" , & options ) == FAILURE ) {
315
327
return ;
@@ -342,6 +354,7 @@ static PHP_METHOD(Session, commitTransaction)
342
354
SUPPRESS_UNUSED_WARNING (return_value_used )
343
355
344
356
intern = Z_SESSION_OBJ_P (getThis ());
357
+ SESSION_CHECK_LIVELINESS (intern , "commitTransaction" )
345
358
346
359
if (zend_parse_parameters_none () == FAILURE ) {
347
360
return ;
@@ -363,6 +376,7 @@ static PHP_METHOD(Session, abortTransaction)
363
376
SUPPRESS_UNUSED_WARNING (return_value_used )
364
377
365
378
intern = Z_SESSION_OBJ_P (getThis ());
379
+ SESSION_CHECK_LIVELINESS (intern , "abortTransaction" )
366
380
367
381
if (zend_parse_parameters_none () == FAILURE ) {
368
382
return ;
@@ -388,6 +402,7 @@ static PHP_METHOD(Session, endSession)
388
402
}
389
403
390
404
mongoc_client_session_destroy (intern -> client_session );
405
+ intern -> client_session = NULL ;
391
406
} /* }}} */
392
407
393
408
/* {{{ MongoDB\Driver\Session function entries */
@@ -477,7 +492,7 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
477
492
478
493
array_init (& retval );
479
494
480
- {
495
+ if ( intern -> client_session ) {
481
496
const bson_t * lsid ;
482
497
483
498
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
@@ -494,9 +509,11 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
494
509
#else
495
510
ADD_ASSOC_ZVAL_EX (& retval , "logicalSessionId" , state .zchild );
496
511
#endif
512
+ } else {
513
+ ADD_ASSOC_NULL_EX (& retval , "logicalSessionId" );
497
514
}
498
515
499
- {
516
+ if ( intern -> client_session ) {
500
517
const bson_t * cluster_time ;
501
518
502
519
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
@@ -517,12 +534,18 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
517
534
} else {
518
535
ADD_ASSOC_NULL_EX (& retval , "clusterTime" );
519
536
}
537
+ } else {
538
+ ADD_ASSOC_NULL_EX (& retval , "clusterTime" );
520
539
}
521
540
522
- cs_opts = mongoc_client_session_get_opts (intern -> client_session );
523
- ADD_ASSOC_BOOL_EX (& retval , "causalConsistency" , mongoc_session_opts_get_causal_consistency (cs_opts ));
541
+ if (intern -> client_session ) {
542
+ cs_opts = mongoc_client_session_get_opts (intern -> client_session );
543
+ ADD_ASSOC_BOOL_EX (& retval , "causalConsistency" , mongoc_session_opts_get_causal_consistency (cs_opts ));
544
+ } else {
545
+ ADD_ASSOC_NULL_EX (& retval , "causalConsistency" );
546
+ }
524
547
525
- {
548
+ if ( intern -> client_session ) {
526
549
uint32_t timestamp , increment ;
527
550
528
551
mongoc_client_session_get_operation_time (intern -> client_session , & timestamp , & increment );
@@ -543,6 +566,8 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
543
566
} else {
544
567
ADD_ASSOC_NULL_EX (& retval , "operationTime" );
545
568
}
569
+ } else {
570
+ ADD_ASSOC_NULL_EX (& retval , "operationTime" );
546
571
}
547
572
548
573
return Z_ARRVAL (retval );
0 commit comments