Skip to content

Commit 011c0c2

Browse files
committed
PHPC-440: WriteErrorException extends abstract WriteException
This makes WriteException a common base class of WriteConcernException and WriteErrorException. BulkWriteException, which may contain multiple write and/or write concern errors, will continue to inherit WriteException.
1 parent e156b23 commit 011c0c2

File tree

6 files changed

+86
-2
lines changed

6 files changed

+86
-2
lines changed

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ if test "$MONGODB" != "no"; then
182182
src/MongoDB/Exception/ConnectionTimeoutException.c \
183183
src/MongoDB/Exception/WriteException.c \
184184
src/MongoDB/Exception/WriteConcernException.c \
185+
src/MongoDB/Exception/WriteErrorException.c \
185186
src/MongoDB/Exception/BulkWriteException.c \
186187
";
187188

config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (PHP_MONGODB != "no") {
1010
ADD_SOURCES(configure_module_dirname + "/src", "bson.c", "mongodb");
1111
ADD_SOURCES(configure_module_dirname + "/src/BSON", "Type.c Unserializable.c Serializable.c Persistable.c Binary.c Javascript.c MaxKey.c MinKey.c ObjectID.c Regex.c Timestamp.c UTCDateTime.c", "mongodb");
1212
ADD_SOURCES(configure_module_dirname + "/src/MongoDB", "Command.c Cursor.c CursorId.c Manager.c Query.c ReadPreference.c Server.c BulkWrite.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c", "mongodb");
13-
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "Exception.c LogicException.c RuntimeException.c UnexpectedValueException.c InvalidArgumentException.c ConnectionException.c AuthenticationException.c SSLConnectionException.c ExecutionTimeoutException.c ConnectionTimeoutException.c WriteException.c WriteConcernException.c BulkWriteException.c", "mongodb");
13+
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "Exception.c LogicException.c RuntimeException.c UnexpectedValueException.c InvalidArgumentException.c ConnectionException.c AuthenticationException.c SSLConnectionException.c ExecutionTimeoutException.c ConnectionTimeoutException.c WriteException.c WriteConcernException.c WriteErrorException.c BulkWriteException.c", "mongodb");
1414
ADD_SOURCES(configure_module_dirname + "/src/contrib/", "php-ssl.c", "mongodb");
1515
ADD_SOURCES(configure_module_dirname + "/src/libbson/src/yajl", "yajl_version.c yajl.c yajl_encode.c yajl_lex.c yajl_parser.c yajl_buf.c yajl_tree.c yajl_alloc.c yajl_gen.c", "mongodb");
1616
ADD_SOURCES(configure_module_dirname + "/src/libbson/src/bson", "bcon.c bson.c bson-atomic.c bson-clock.c bson-context.c bson-error.c bson-iter.c bson-iso8601.c bson-json.c bson-keys.c bson-md5.c bson-memory.c bson-oid.c bson-reader.c bson-string.c bson-timegm.c bson-utf8.c bson-value.c bson-version-functions.c bson-writer.c", "mongodb");

php_phongo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ zend_class_entry* phongo_exception_from_phongo_domain(php_phongo_error_domain_t
101101
case PHONGO_ERROR_WRITE_FAILED:
102102
return php_phongo_bulkwriteexception_ce;
103103
case PHONGO_ERROR_WRITE_SINGLE_FAILED:
104-
return php_phongo_writeexception_ce;
104+
return php_phongo_writeerrorexception_ce;
105105
case PHONGO_ERROR_WRITECONCERN_FAILED:
106106
return php_phongo_writeconcernexception_ce;
107107
case PHONGO_ERROR_CONNECTION_FAILED:
@@ -2372,6 +2372,7 @@ PHP_MINIT_FUNCTION(mongodb)
23722372
PHP_MINIT(SSLConnectionException)(INIT_FUNC_ARGS_PASSTHRU);
23732373
PHP_MINIT(WriteException)(INIT_FUNC_ARGS_PASSTHRU);
23742374
PHP_MINIT(WriteConcernException)(INIT_FUNC_ARGS_PASSTHRU);
2375+
PHP_MINIT(WriteErrorException)(INIT_FUNC_ARGS_PASSTHRU);
23752376
PHP_MINIT(BulkWriteException)(INIT_FUNC_ARGS_PASSTHRU);
23762377
PHP_MINIT(ExecutionTimeoutException)(INIT_FUNC_ARGS_PASSTHRU);
23772378
PHP_MINIT(ConnectionTimeoutException)(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_classes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ extern PHONGO_API zend_class_entry *php_phongo_executiontimeoutexception_ce;
187187
extern PHONGO_API zend_class_entry *php_phongo_connectiontimeoutexception_ce;
188188
extern PHONGO_API zend_class_entry *php_phongo_writeexception_ce;
189189
extern PHONGO_API zend_class_entry *php_phongo_writeconcernexception_ce;
190+
extern PHONGO_API zend_class_entry *php_phongo_writeerrorexception_ce;
190191
extern PHONGO_API zend_class_entry *php_phongo_bulkwriteexception_ce;
191192

192193
extern PHONGO_API zend_class_entry *php_phongo_type_ce;
@@ -236,6 +237,7 @@ PHP_MINIT_FUNCTION(ExecutionTimeoutException);
236237
PHP_MINIT_FUNCTION(ConnectionTimeoutException);
237238
PHP_MINIT_FUNCTION(WriteException);
238239
PHP_MINIT_FUNCTION(WriteConcernException);
240+
PHP_MINIT_FUNCTION(WriteErrorException);
239241
PHP_MINIT_FUNCTION(BulkWriteException);
240242

241243
PHP_MINIT_FUNCTION(Type);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
+---------------------------------------------------------------------------+
3+
| PHP Driver for MongoDB |
4+
+---------------------------------------------------------------------------+
5+
| Copyright 2013-2015 MongoDB, Inc. |
6+
| |
7+
| Licensed under the Apache License, Version 2.0 (the "License"); |
8+
| you may not use this file except in compliance with the License. |
9+
| You may obtain a copy of the License at |
10+
| |
11+
| http://www.apache.org/licenses/LICENSE-2.0 |
12+
| |
13+
| Unless required by applicable law or agreed to in writing, software |
14+
| distributed under the License is distributed on an "AS IS" BASIS, |
15+
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16+
| See the License for the specific language governing permissions and |
17+
| limitations under the License. |
18+
+---------------------------------------------------------------------------+
19+
| Copyright (c) 2014-2015 MongoDB, Inc. |
20+
+---------------------------------------------------------------------------+
21+
*/
22+
23+
#ifdef HAVE_CONFIG_H
24+
# include "config.h"
25+
#endif
26+
27+
/* External libs */
28+
#include <bson.h>
29+
#include <mongoc.h>
30+
31+
/* PHP Core stuff */
32+
#include <php.h>
33+
#include <php_ini.h>
34+
#include <ext/standard/info.h>
35+
#include <Zend/zend_interfaces.h>
36+
#include <ext/spl/spl_iterators.h>
37+
/* Our Compatability header */
38+
#include "phongo_compat.h"
39+
40+
/* Our stuffz */
41+
#include "php_phongo.h"
42+
#include "php_bson.h"
43+
#include <ext/spl/spl_exceptions.h>
44+
45+
46+
PHONGO_API zend_class_entry *php_phongo_writeerrorexception_ce;
47+
48+
/* {{{ MongoDB\Driver\WriteErrorException */
49+
50+
static zend_function_entry php_phongo_writeerrorexception_me[] = {
51+
PHP_FE_END
52+
};
53+
54+
/* }}} */
55+
56+
57+
/* {{{ PHP_MINIT_FUNCTION */
58+
PHP_MINIT_FUNCTION(WriteErrorException)
59+
{
60+
zend_class_entry ce;
61+
(void)type;(void)module_number;
62+
63+
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "WriteErrorException", php_phongo_writeerrorexception_me);
64+
php_phongo_writeerrorexception_ce = zend_register_internal_class_ex(&ce, php_phongo_writeexception_ce, NULL TSRMLS_CC);
65+
66+
return SUCCESS;
67+
}
68+
/* }}} */
69+
70+
71+
72+
/*
73+
* Local variables:
74+
* tab-width: 4
75+
* c-basic-offset: 4
76+
* End:
77+
* vim600: noet sw=4 ts=4 fdm=marker
78+
* vim<600: noet sw=4 ts=4
79+
*/

src/MongoDB/Exception/WriteException.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ PHP_MINIT_FUNCTION(WriteException)
8989

9090
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "WriteException", php_phongo_writeexception_me);
9191
php_phongo_writeexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce, NULL TSRMLS_CC);
92+
php_phongo_writeexception_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
9293

9394
zend_declare_property_null(php_phongo_writeexception_ce, ZEND_STRL("writeResult"), ZEND_ACC_PROTECTED TSRMLS_CC);
9495

0 commit comments

Comments
 (0)