PHP-1230: Implement WriteException class

This commit is contained in:
Jeremy Mikola
2014-09-24 17:40:28 -04:00
parent b4b858abe9
commit 9aaa2de17b
6 changed files with 189 additions and 0 deletions
+1
View File
@@ -125,6 +125,7 @@ if test "$PHONGO" != "no"; then
src/MongoDB/WriteConcern.c \
src/MongoDB/WriteConcernError.c \
src/MongoDB/WriteError.c \
src/MongoDB/WriteException.c \
src/MongoDB/WriteResult.c \
";
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace MongoDB;
/**
* Value object for write concern used in issuing write operations.
*/
final class WriteException extends \RuntimeException
{
private $writeResult;
/**
* Returns the WriteResult from the failed write operation.
*
* In the event of a batch write, WriteResult may have relevant information
* on the successful writes in the batch.
*
* @return WriteResult
*/
public function getWriteResult()
{
/*** CEF ***/
/*
zval *writeresult;
*/
/*** CEF ***/
/*** CIMPL ***/
/*
writeresult = zend_read_property(php_phongo_writeexception_ce, getThis(), ZEND_STRL("writeResult"), 0 TSRMLS_CC);
RETURN_ZVAL(writeresult, 1, 0);
*/
/*** CIMPL ***/
}
}
$WriteException["headers"][] = '<ext/spl/spl_exceptions.h>';
+1
View File
@@ -15,3 +15,4 @@ include "api/MongoDB/Server.php";
include "api/MongoDB/GeneratedId.php";
include "api/MongoDB/WriteConcern.php";
include "api/MongoDB/WriteResult.php";
include "api/MongoDB/WriteException.php";
+1
View File
@@ -1027,6 +1027,7 @@ PHP_MINIT_FUNCTION(phongo)
PHP_MINIT(WriteConcern)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(WriteConcernError)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(WriteError)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(WriteException)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(WriteResult)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(Type)(INIT_FUNC_ARGS_PASSTHRU);
+6
View File
@@ -116,6 +116,10 @@ typedef struct {
zval *writeConcernErrors;
} php_phongo_writeresult_t;
typedef struct {
zend_object std;
} php_phongo_writeexception_t;
typedef struct {
zend_object std;
} php_phongo_binary_t;
@@ -171,6 +175,7 @@ extern PHONGO_API zend_class_entry *php_phongo_writebatch_ce;
extern PHONGO_API zend_class_entry *php_phongo_writeconcern_ce;
extern PHONGO_API zend_class_entry *php_phongo_writeconcernerror_ce;
extern PHONGO_API zend_class_entry *php_phongo_writeerror_ce;
extern PHONGO_API zend_class_entry *php_phongo_writeexception_ce;
extern PHONGO_API zend_class_entry *php_phongo_writeresult_ce;
extern PHONGO_API zend_class_entry *php_phongo_type_ce;
@@ -202,6 +207,7 @@ PHP_MINIT_FUNCTION(WriteBatch);
PHP_MINIT_FUNCTION(WriteConcern);
PHP_MINIT_FUNCTION(WriteConcernError);
PHP_MINIT_FUNCTION(WriteError);
PHP_MINIT_FUNCTION(WriteException);
PHP_MINIT_FUNCTION(WriteResult);
PHP_MINIT_FUNCTION(Type);
+143
View File
@@ -0,0 +1,143 @@
/*
+---------------------------------------------------------------------------+
| PHP Driver for MongoDB |
+---------------------------------------------------------------------------+
| Copyright 2013-2014 MongoDB, Inc. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+---------------------------------------------------------------------------+
| Copyright (c) 2014, MongoDB, Inc. |
+---------------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/* External libs */
#include <bson.h>
#include <mongoc.h>
/* PHP Core stuff */
#include <php.h>
#include <php_ini.h>
#include <ext/standard/info.h>
#include <Zend/zend_interfaces.h>
#include <ext/spl/spl_iterators.h>
/* Our Compatability header */
#include "php_compat_53.h"
/* Our stuffz */
#include "php_phongo.h"
#include "php_bson.h"
#include <ext/spl/spl_exceptions.h>
PHONGO_API zend_class_entry *php_phongo_writeexception_ce;
/* {{{ proto MongoDB\WriteResult WriteException::getWriteResult()
Returns the WriteResult from the failed write operation. */
PHP_METHOD(WriteException, getWriteResult)
{
php_phongo_writeexception_t *intern;
zend_error_handling error_handling;
zval *writeresult;
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = (php_phongo_writeexception_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
writeresult = zend_read_property(php_phongo_writeexception_ce, getThis(), ZEND_STRL("writeResult"), 0 TSRMLS_CC);
RETURN_ZVAL(writeresult, 1, 0);
}
/* }}} */
/**
* Value object for write concern used in issuing write operations.
*/
/* {{{ MongoDB\WriteException */
ZEND_BEGIN_ARG_INFO_EX(ai_WriteException_getWriteResult, 0, 0, 0)
ZEND_END_ARG_INFO();
static zend_function_entry php_phongo_writeexception_me[] = {
PHP_ME(WriteException, getWriteResult, ai_WriteException_getWriteResult, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};
/* }}} */
/* {{{ php_phongo_writeexception_t object handlers */
static void php_phongo_writeexception_free_object(void *object TSRMLS_DC) /* {{{ */
{
php_phongo_writeexception_t *intern = (php_phongo_writeexception_t*)object;
zend_object_std_dtor(&intern->std TSRMLS_CC);
efree(intern);
} /* }}} */
zend_object_value php_phongo_writeexception_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
zend_object_value retval;
php_phongo_writeexception_t *intern;
intern = (php_phongo_writeexception_t *)emalloc(sizeof(php_phongo_writeexception_t));
memset(intern, 0, sizeof(php_phongo_writeexception_t));
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_writeexception_free_object, NULL TSRMLS_CC);
retval.handlers = phongo_get_std_object_handlers();
return retval;
} /* }}} */
/* }}} */
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(WriteException)
{
(void)type; /* We don't care if we are loaded via dl() or extension= */
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "MongoDB", "WriteException", php_phongo_writeexception_me);
ce.create_object = php_phongo_writeexception_create_object;
php_phongo_writeexception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
php_phongo_writeexception_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
return SUCCESS;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/