Skip to content

Commit 0ceac0c

Browse files
committed
Merge pull request #1087
2 parents 196901d + 78638e0 commit 0ceac0c

File tree

6 files changed

+74
-7
lines changed

6 files changed

+74
-7
lines changed

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ if test "$PHP_MONGODB" != "no"; then
153153
src/MongoDB/Exception/CommandException.c \
154154
src/MongoDB/Exception/ConnectionException.c \
155155
src/MongoDB/Exception/ConnectionTimeoutException.c \
156+
src/MongoDB/Exception/EncryptionException.c \
156157
src/MongoDB/Exception/Exception.c \
157158
src/MongoDB/Exception/ExecutionTimeoutException.c \
158159
src/MongoDB/Exception/InvalidArgumentException.c \

config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if (PHP_MONGODB != "no") {
9191
ADD_SOURCES(configure_module_dirname + "/src", "bson.c bson-encode.c", "mongodb");
9292
ADD_SOURCES(configure_module_dirname + "/src/BSON", "Binary.c BinaryInterface.c DBPointer.c Decimal128.c Decimal128Interface.c Int64.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c functions.c", "mongodb");
9393
ADD_SOURCES(configure_module_dirname + "/src/MongoDB", "BulkWrite.c ClientEncryption.c Command.c Cursor.c CursorId.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c Session.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c", "mongodb");
94-
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c", "mongodb");
94+
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c", "mongodb");
9595
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c Subscriber.c functions.c", "mongodb");
9696
ADD_SOURCES(configure_module_dirname + "/src/libmongoc/src/common", PHP_MONGODB_COMMON_SOURCES, "mongodb");
9797
ADD_SOURCES(configure_module_dirname + "/src/libmongoc/src/libbson/src/bson", PHP_MONGODB_BSON_SOURCES, "mongodb");

php_phongo.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,16 @@ zend_class_entry* phongo_exception_from_phongo_domain(php_phongo_error_domain_t
136136
MONGOC_ERROR("Resolving unknown phongo error domain: %d", domain);
137137
return php_phongo_runtimeexception_ce;
138138
}
139-
zend_class_entry* phongo_exception_from_mongoc_domain(uint32_t /* mongoc_error_domain_t */ domain, uint32_t /* mongoc_error_code_t */ code)
139+
zend_class_entry* phongo_exception_from_mongoc_domain(mongoc_error_domain_t domain, mongoc_error_code_t code)
140140
{
141-
if (domain == MONGOC_ERROR_CLIENT && code == MONGOC_ERROR_CLIENT_AUTHENTICATE) {
142-
return php_phongo_authenticationexception_ce;
141+
if (domain == MONGOC_ERROR_CLIENT) {
142+
if (code == MONGOC_ERROR_CLIENT_AUTHENTICATE) {
143+
return php_phongo_authenticationexception_ce;
144+
}
145+
146+
if (code == MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_ARG) {
147+
return php_phongo_invalidargumentexception_ce;
148+
}
143149
}
144150

145151
if (domain == MONGOC_ERROR_COMMAND && code == MONGOC_ERROR_COMMAND_INVALID_ARG) {
@@ -174,6 +180,10 @@ zend_class_entry* phongo_exception_from_mongoc_domain(uint32_t /* mongoc_error_d
174180
return php_phongo_connectionexception_ce;
175181
}
176182

183+
if (domain == MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION) {
184+
return php_phongo_encryptionexception_ce;
185+
}
186+
177187
return php_phongo_runtimeexception_ce;
178188
}
179189
void phongo_throw_exception(php_phongo_error_domain_t domain TSRMLS_DC, const char* format, ...)
@@ -3728,6 +3738,7 @@ PHP_MINIT_FUNCTION(mongodb)
37283738
php_phongo_bulkwriteexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
37293739
php_phongo_commandexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
37303740
php_phongo_connectiontimeoutexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
3741+
php_phongo_encryptionexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
37313742
php_phongo_executiontimeoutexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
37323743
php_phongo_invalidargumentexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
37333744
php_phongo_logicexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_classes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ extern zend_class_entry* php_phongo_invalidargumentexception_ce;
315315
extern zend_class_entry* php_phongo_connectionexception_ce;
316316
extern zend_class_entry* php_phongo_authenticationexception_ce;
317317
extern zend_class_entry* php_phongo_sslconnectionexception_ce;
318+
extern zend_class_entry* php_phongo_encryptionexception_ce;
318319
extern zend_class_entry* php_phongo_executiontimeoutexception_ce;
319320
extern zend_class_entry* php_phongo_connectiontimeoutexception_ce;
320321
extern zend_class_entry* php_phongo_writeexception_ce;
@@ -405,6 +406,7 @@ extern void php_phongo_bulkwriteexception_init_ce(INIT_FUNC_ARGS);
405406
extern void php_phongo_commandexception_init_ce(INIT_FUNC_ARGS);
406407
extern void php_phongo_connectionexception_init_ce(INIT_FUNC_ARGS);
407408
extern void php_phongo_connectiontimeoutexception_init_ce(INIT_FUNC_ARGS);
409+
extern void php_phongo_encryptionexception_init_ce(INIT_FUNC_ARGS);
408410
extern void php_phongo_exception_init_ce(INIT_FUNC_ARGS);
409411
extern void php_phongo_executiontimeoutexception_init_ce(INIT_FUNC_ARGS);
410412
extern void php_phongo_invalidargumentexception_init_ce(INIT_FUNC_ARGS);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2014-2020 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <php.h>
18+
19+
#ifdef HAVE_CONFIG_H
20+
#include "config.h"
21+
#endif
22+
23+
#include "phongo_compat.h"
24+
#include "php_phongo.h"
25+
26+
zend_class_entry* php_phongo_encryptionexception_ce;
27+
28+
/* {{{ MongoDB\Driver\Exception\EncryptionException function entries */
29+
static zend_function_entry php_phongo_encryptionexception_me[] = {
30+
PHP_FE_END
31+
};
32+
/* }}} */
33+
34+
void php_phongo_encryptionexception_init_ce(INIT_FUNC_ARGS) /* {{{ */
35+
{
36+
zend_class_entry ce;
37+
38+
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "EncryptionException", php_phongo_encryptionexception_me);
39+
#if PHP_VERSION_ID >= 70000
40+
php_phongo_encryptionexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce);
41+
#else
42+
php_phongo_encryptionexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce, NULL TSRMLS_CC);
43+
#endif
44+
} /* }}} */
45+
46+
/*
47+
* Local variables:
48+
* tab-width: 4
49+
* c-basic-offset: 4
50+
* End:
51+
* vim600: noet sw=4 ts=4 fdm=marker
52+
* vim<600: noet sw=4 ts=4
53+
*/

tests/manager/manager-ctor-auto_encryption-error-001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ $tests = [
1616
foreach ($tests as $driverOptions) {
1717
echo throws(function() use ($driverOptions) {
1818
$manager = new MongoDB\Driver\Manager(null, [], ['autoEncryption' => $driverOptions]);
19-
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n\n";
19+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n\n";
2020
}
2121

2222
?>
2323
===DONE===
2424
<?php exit(0); ?>
2525
--EXPECT--
26-
OK: Got MongoDB\Driver\Exception\RuntimeException
26+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
2727
Key vault namespace option required
2828

29-
OK: Got MongoDB\Driver\Exception\RuntimeException
29+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
3030
KMS providers option required
3131

3232
===DONE===

0 commit comments

Comments
 (0)