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
/* {{{ proto void MongoDB\Driver\Session::isInTransaction(void)
@@ -399,6 +414,7 @@ static PHP_METHOD(Session, isInTransaction)
399
414
SUPPRESS_UNUSED_WARNING (return_value_used )
400
415
401
416
intern = Z_SESSION_OBJ_P (getThis ());
417
+ SESSION_CHECK_LIVELINESS (intern , "isInTransaction" )
402
418
403
419
if (zend_parse_parameters_none () == FAILURE ) {
404
420
return ;
@@ -496,7 +512,7 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
496
512
497
513
array_init (& retval );
498
514
499
- {
515
+ if ( intern -> client_session ) {
500
516
const bson_t * lsid ;
501
517
502
518
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
@@ -513,9 +529,11 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
513
529
#else
514
530
ADD_ASSOC_ZVAL_EX (& retval , "logicalSessionId" , state .zchild );
515
531
#endif
532
+ } else {
533
+ ADD_ASSOC_NULL_EX (& retval , "logicalSessionId" );
516
534
}
517
535
518
- {
536
+ if ( intern -> client_session ) {
519
537
const bson_t * cluster_time ;
520
538
521
539
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
@@ -536,12 +554,18 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
536
554
} else {
537
555
ADD_ASSOC_NULL_EX (& retval , "clusterTime" );
538
556
}
557
+ } else {
558
+ ADD_ASSOC_NULL_EX (& retval , "clusterTime" );
539
559
}
540
560
541
- cs_opts = mongoc_client_session_get_opts (intern -> client_session );
542
- ADD_ASSOC_BOOL_EX (& retval , "causalConsistency" , mongoc_session_opts_get_causal_consistency (cs_opts ));
561
+ if (intern -> client_session ) {
562
+ cs_opts = mongoc_client_session_get_opts (intern -> client_session );
563
+ ADD_ASSOC_BOOL_EX (& retval , "causalConsistency" , mongoc_session_opts_get_causal_consistency (cs_opts ));
564
+ } else {
565
+ ADD_ASSOC_NULL_EX (& retval , "causalConsistency" );
566
+ }
543
567
544
- {
568
+ if ( intern -> client_session ) {
545
569
uint32_t timestamp , increment ;
546
570
547
571
mongoc_client_session_get_operation_time (intern -> client_session , & timestamp , & increment );
@@ -562,6 +586,8 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
562
586
} else {
563
587
ADD_ASSOC_NULL_EX (& retval , "operationTime" );
564
588
}
589
+ } else {
590
+ ADD_ASSOC_NULL_EX (& retval , "operationTime" );
565
591
}
566
592
567
593
return Z_ARRVAL (retval );
0 commit comments