1 /**
2 * Copyright 2016-2017 Couchbase, 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 "couchbase.h"
18
19 zend_class_entry *pcbc_document_fragment_ce;
20
21 // clang-format off
22 zend_function_entry docfrag_methods[] = {
23 PHP_FE_END
24 };
25 // clang-format on
26
pcbc_document_fragment_init(zval * return_value,zval * value,zval * cas,zval * token TSRMLS_DC)27 int pcbc_document_fragment_init(zval *return_value, zval *value, zval *cas, zval *token TSRMLS_DC)
28 {
29 object_init_ex(return_value, pcbc_document_fragment_ce);
30
31 if (value) {
32 zend_update_property(pcbc_document_fragment_ce, return_value, "value", sizeof("value") - 1, value TSRMLS_CC);
33 }
34 if (cas && !Z_ISUNDEF_P(cas)) {
35 zend_update_property(pcbc_document_fragment_ce, return_value, "cas", sizeof("cas") - 1, cas TSRMLS_CC);
36 }
37 if (token && !Z_ISUNDEF_P(token)) {
38 zend_update_property(pcbc_document_fragment_ce, return_value, "token", sizeof("token") - 1, token TSRMLS_CC);
39 }
40
41 return SUCCESS;
42 }
43
pcbc_document_fragment_init_error(zval * return_value,opcookie_res * header,zval * value TSRMLS_DC)44 int pcbc_document_fragment_init_error(zval *return_value, opcookie_res *header, zval *value TSRMLS_DC)
45 {
46 PCBC_ZVAL error;
47
48 object_init_ex(return_value, pcbc_document_fragment_ce);
49 PCBC_ZVAL_ALLOC(error);
50 pcbc_exception_init_lcb(PCBC_P(error), header->err, NULL, header->err_ctx, header->err_ref TSRMLS_CC);
51 zend_update_property(pcbc_document_fragment_ce, return_value, "error", sizeof("error") - 1,
52 PCBC_P(error) TSRMLS_CC);
53 if (value) {
54 zend_update_property(pcbc_document_fragment_ce, return_value, "value", sizeof("value") - 1, value TSRMLS_CC);
55 }
56
57 zval_ptr_dtor(&error);
58 return SUCCESS;
59 }
60
PHP_MINIT_FUNCTION(DocumentFragment)61 PHP_MINIT_FUNCTION(DocumentFragment)
62 {
63 zend_class_entry ce;
64
65 INIT_NS_CLASS_ENTRY(ce, "Couchbase", "DocumentFragment", docfrag_methods);
66 pcbc_document_fragment_ce = zend_register_internal_class(&ce TSRMLS_CC);
67
68 zend_declare_property_null(pcbc_document_fragment_ce, "error", strlen("error"), ZEND_ACC_PUBLIC TSRMLS_CC);
69 zend_declare_property_null(pcbc_document_fragment_ce, "cas", strlen("cas"), ZEND_ACC_PUBLIC TSRMLS_CC);
70 zend_declare_property_null(pcbc_document_fragment_ce, "value", strlen("value"), ZEND_ACC_PUBLIC TSRMLS_CC);
71 zend_declare_property_null(pcbc_document_fragment_ce, "token", strlen("token"), ZEND_ACC_PUBLIC TSRMLS_CC);
72
73 zend_register_class_alias("\\CouchbaseDocumentFragment", pcbc_document_fragment_ce);
74 return SUCCESS;
75 }
76