Skip to content

Commit dac9df6

Browse files
committed
Merge pull request #611
2 parents a0e9215 + 31aa04b commit dac9df6

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

src/MongoDB/ReadConcern.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ static PHP_METHOD(ReadConcern, getLevel)
7979
RETURN_NULL();
8080
} /* }}} */
8181

82+
/* {{{ proto boolean MongoDB\Driver\ReadConcern::isDefault()
83+
Returns whether the read concern has not been modified (i.e. constructed
84+
without a level or from a Manager with no read concern URI options). */
85+
static PHP_METHOD(ReadConcern, isDefault)
86+
{
87+
php_phongo_readconcern_t *intern;
88+
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
89+
90+
intern = Z_READCONCERN_OBJ_P(getThis());
91+
92+
if (zend_parse_parameters_none() == FAILURE) {
93+
return;
94+
}
95+
96+
RETURN_BOOL(mongoc_read_concern_is_default(intern->read_concern));
97+
} /* }}} */
98+
8299
/* {{{ proto array MongoDB\Driver\ReadConcern::bsonSerialize()
83100
*/
84101
static PHP_METHOD(ReadConcern, bsonSerialize)
@@ -104,6 +121,7 @@ ZEND_END_ARG_INFO()
104121
static zend_function_entry php_phongo_readconcern_me[] = {
105122
PHP_ME(ReadConcern, __construct, ai_ReadConcern___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
106123
PHP_ME(ReadConcern, getLevel, ai_ReadConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
124+
PHP_ME(ReadConcern, isDefault, ai_ReadConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
107125
PHP_ME(ReadConcern, bsonSerialize, ai_ReadConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
108126
PHP_FE_END
109127
};

src/MongoDB/WriteConcern.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ static PHP_METHOD(WriteConcern, getJournal)
158158
RETURN_NULL();
159159
} /* }}} */
160160

161+
/* {{{ proto boolean MongoDB\Driver\WriteConcern::isDefault()
162+
Returns whether the write concern has not been modified (i.e. from a Manager
163+
with no write concern URI options). */
164+
static PHP_METHOD(WriteConcern, isDefault)
165+
{
166+
php_phongo_writeconcern_t *intern;
167+
SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)
168+
169+
intern = Z_WRITECONCERN_OBJ_P(getThis());
170+
171+
if (zend_parse_parameters_none() == FAILURE) {
172+
return;
173+
}
174+
175+
RETURN_BOOL(mongoc_write_concern_is_default(intern->write_concern));
176+
} /* }}} */
177+
161178
/* {{{ proto array MongoDB\Driver\WriteConcern::bsonSerialize()
162179
*/
163180
static PHP_METHOD(WriteConcern, bsonSerialize)
@@ -187,6 +204,7 @@ static zend_function_entry php_phongo_writeconcern_me[] = {
187204
PHP_ME(WriteConcern, getW, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
188205
PHP_ME(WriteConcern, getWtimeout, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
189206
PHP_ME(WriteConcern, getJournal, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
207+
PHP_ME(WriteConcern, isDefault, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
190208
PHP_ME(WriteConcern, bsonSerialize, ai_WriteConcern_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
191209
PHP_FE_END
192210
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
MongoDB\Driver\ReadConcern::isDefault()
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$tests = array(
10+
new MongoDB\Driver\ReadConcern(),
11+
new MongoDB\Driver\ReadConcern(null),
12+
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
13+
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
14+
new MongoDB\Driver\ReadConcern('not-yet-supported'),
15+
(new MongoDB\Driver\Manager('mongodb://127.0.0.1/?readconcernlevel=local'))->getReadConcern(),
16+
(new MongoDB\Driver\Manager(null, ['readconcernlevel' => 'local']))->getReadConcern(),
17+
(new MongoDB\Driver\Manager(null, ['readconcernlevel' => '']))->getReadConcern(),
18+
(new MongoDB\Driver\Manager)->getReadConcern(),
19+
);
20+
21+
foreach ($tests as $rc) {
22+
var_dump($rc->isDefault());
23+
}
24+
25+
?>
26+
===DONE===
27+
<?php exit(0); ?>
28+
--EXPECT--
29+
bool(true)
30+
bool(true)
31+
bool(false)
32+
bool(false)
33+
bool(false)
34+
bool(false)
35+
bool(false)
36+
bool(false)
37+
bool(true)
38+
===DONE===
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
MongoDB\Driver\WriteConcern::isDefault()
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$tests = array(
10+
new MongoDB\Driver\WriteConcern(1),
11+
(new MongoDB\Driver\Manager('mongodb://127.0.0.1/?w=1'))->getWriteConcern(),
12+
(new MongoDB\Driver\Manager(null, ['w' => 1]))->getWriteConcern(),
13+
(new MongoDB\Driver\Manager)->getWriteConcern(),
14+
);
15+
16+
foreach ($tests as $wc) {
17+
var_dump($wc->isDefault());
18+
}
19+
20+
?>
21+
===DONE===
22+
<?php exit(0); ?>
23+
--EXPECT--
24+
bool(false)
25+
bool(false)
26+
bool(false)
27+
bool(true)
28+
===DONE===

0 commit comments

Comments
 (0)