|
| 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 | +#include <mongoc-read-concern-private.h> |
| 31 | + |
| 32 | +/* PHP Core stuff */ |
| 33 | +#include <php.h> |
| 34 | +#include <php_ini.h> |
| 35 | +#include <ext/standard/info.h> |
| 36 | +#include <Zend/zend_interfaces.h> |
| 37 | +#include <ext/spl/spl_iterators.h> |
| 38 | +/* Our Compatability header */ |
| 39 | +#include "phongo_compat.h" |
| 40 | + |
| 41 | +/* Our stuffz */ |
| 42 | +#include "php_phongo.h" |
| 43 | +#include "php_bson.h" |
| 44 | + |
| 45 | + |
| 46 | +PHONGO_API zend_class_entry *php_phongo_readconcern_ce; |
| 47 | + |
| 48 | +zend_object_handlers php_phongo_handler_readconcern; |
| 49 | + |
| 50 | +/* {{{ proto MongoDB\Driver\ReadConcern ReadConcern::__construct([string $level]) |
| 51 | + Constructs a new ReadConcern */ |
| 52 | +PHP_METHOD(ReadConcern, __construct) |
| 53 | +{ |
| 54 | + php_phongo_readconcern_t *intern; |
| 55 | + zend_error_handling error_handling; |
| 56 | + char *level = NULL; |
| 57 | + int level_len = 0; |
| 58 | + |
| 59 | + |
| 60 | + (void)return_value; (void)return_value_ptr; (void)return_value_used; |
| 61 | + |
| 62 | + |
| 63 | + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC); |
| 64 | + intern = (php_phongo_readconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC); |
| 65 | + |
| 66 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &level, &level_len) == FAILURE) { |
| 67 | + zend_restore_error_handling(&error_handling TSRMLS_CC); |
| 68 | + return; |
| 69 | + } |
| 70 | + zend_restore_error_handling(&error_handling TSRMLS_CC); |
| 71 | + |
| 72 | + |
| 73 | + intern->read_concern = mongoc_read_concern_new(); |
| 74 | + |
| 75 | + if (level) { |
| 76 | + mongoc_read_concern_set_level(intern->read_concern, level); |
| 77 | + } |
| 78 | +} |
| 79 | +/* }}} */ |
| 80 | + |
| 81 | +/* {{{ proto string|null ReadConcern::getLevel() |
| 82 | + Returns the ReadConcern "level" option */ |
| 83 | +PHP_METHOD(ReadConcern, getLevel) |
| 84 | +{ |
| 85 | + php_phongo_readconcern_t *intern; |
| 86 | + const char *level; |
| 87 | + (void)return_value_ptr; (void)return_value_used; |
| 88 | + |
| 89 | + intern = (php_phongo_readconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC); |
| 90 | + |
| 91 | + if (zend_parse_parameters_none() == FAILURE) { |
| 92 | + return; |
| 93 | + } |
| 94 | + |
| 95 | + level = mongoc_read_concern_get_level(intern->read_concern); |
| 96 | + |
| 97 | + if (level) { |
| 98 | + RETURN_STRING(level, 1); |
| 99 | + } |
| 100 | + |
| 101 | + RETURN_NULL(); |
| 102 | +} |
| 103 | +/* }}} */ |
| 104 | + |
| 105 | +/** |
| 106 | + * Value object for read concern used in issuing read operations. |
| 107 | + */ |
| 108 | +/* {{{ MongoDB\Driver\ReadConcern */ |
| 109 | + |
| 110 | +ZEND_BEGIN_ARG_INFO_EX(ai_ReadConcern___construct, 0, 0, 1) |
| 111 | + ZEND_ARG_INFO(0, level) |
| 112 | +ZEND_END_ARG_INFO(); |
| 113 | + |
| 114 | +ZEND_BEGIN_ARG_INFO_EX(ai_ReadConcern_getLevel, 0, 0, 0) |
| 115 | +ZEND_END_ARG_INFO(); |
| 116 | + |
| 117 | +static zend_function_entry php_phongo_readconcern_me[] = { |
| 118 | + PHP_ME(ReadConcern, __construct, ai_ReadConcern___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) |
| 119 | + PHP_ME(ReadConcern, getLevel, ai_ReadConcern_getLevel, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) |
| 120 | + PHP_FE_END |
| 121 | +}; |
| 122 | + |
| 123 | +/* }}} */ |
| 124 | + |
| 125 | + |
| 126 | +/* {{{ php_phongo_readconcern_t object handlers */ |
| 127 | +static void php_phongo_readconcern_free_object(void *object TSRMLS_DC) /* {{{ */ |
| 128 | +{ |
| 129 | + php_phongo_readconcern_t *intern = (php_phongo_readconcern_t*)object; |
| 130 | + |
| 131 | + zend_object_std_dtor(&intern->std TSRMLS_CC); |
| 132 | + |
| 133 | + if (intern->read_concern) { |
| 134 | + mongoc_read_concern_destroy(intern->read_concern); |
| 135 | + } |
| 136 | + efree(intern); |
| 137 | +} /* }}} */ |
| 138 | + |
| 139 | +zend_object_value php_phongo_readconcern_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ |
| 140 | +{ |
| 141 | + zend_object_value retval; |
| 142 | + php_phongo_readconcern_t *intern = NULL; |
| 143 | + |
| 144 | + intern = (php_phongo_readconcern_t *)ecalloc(1, sizeof *intern); |
| 145 | + |
| 146 | + zend_object_std_init(&intern->std, class_type TSRMLS_CC); |
| 147 | + object_properties_init(&intern->std, class_type); |
| 148 | + |
| 149 | + retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_readconcern_free_object, NULL TSRMLS_CC); |
| 150 | + retval.handlers = &php_phongo_handler_readconcern; |
| 151 | + |
| 152 | + return retval; |
| 153 | +} /* }}} */ |
| 154 | + |
| 155 | +HashTable *php_phongo_readconcern_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */ |
| 156 | +{ |
| 157 | + zval retval = zval_used_for_init; |
| 158 | + const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(object TSRMLS_CC); |
| 159 | + |
| 160 | + |
| 161 | + *is_temp = 1; |
| 162 | + php_phongo_read_concern_to_zval(&retval, read_concern); |
| 163 | + |
| 164 | + return Z_ARRVAL(retval); |
| 165 | +} /* }}} */ |
| 166 | +/* }}} */ |
| 167 | + |
| 168 | +/* {{{ PHP_MINIT_FUNCTION */ |
| 169 | +PHP_MINIT_FUNCTION(ReadConcern) |
| 170 | +{ |
| 171 | + zend_class_entry ce; |
| 172 | + (void)type;(void)module_number; |
| 173 | + |
| 174 | + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "ReadConcern", php_phongo_readconcern_me); |
| 175 | + php_phongo_readconcern_ce = zend_register_internal_class(&ce TSRMLS_CC); |
| 176 | + php_phongo_readconcern_ce->create_object = php_phongo_readconcern_create_object; |
| 177 | + PHONGO_CE_INIT(php_phongo_readconcern_ce); |
| 178 | + |
| 179 | + memcpy(&php_phongo_handler_readconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); |
| 180 | + php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info; |
| 181 | + |
| 182 | + zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("LOCAL"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_LOCAL) TSRMLS_CC); |
| 183 | + zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("MAJORITY"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_MAJORITY) TSRMLS_CC); |
| 184 | + |
| 185 | + return SUCCESS; |
| 186 | +} |
| 187 | +/* }}} */ |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | +/* |
| 192 | + * Local variables: |
| 193 | + * tab-width: 4 |
| 194 | + * c-basic-offset: 4 |
| 195 | + * End: |
| 196 | + * vim600: noet sw=4 ts=4 fdm=marker |
| 197 | + * vim<600: noet sw=4 ts=4 |
| 198 | + */ |
0 commit comments