forked from chobie/php-protocolbuffers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage_options.c
94 lines (82 loc) · 3.62 KB
/
message_options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Protocol Buffers for PHP
* Copyright 2013 Shuhei Tanuma. All rights reserved.
*
* https://github.com/chobie/php-protocolbuffers
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "protocolbuffers.h"
#include "message_options.h"
int php_protocolbuffers_message_options_init_properties(zval *object TSRMLS_DC)
{
zval tmp;
zend_class_entry *entry = Z_OBJCE_P(object);
array_init(&tmp);
zend_update_property(entry,object ,ZEND_STRL("extensions"),&tmp);
zval_ptr_dtor(&tmp);
return 0;
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_protocolbuffers_message_options_get_options, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
/* {{{ proto ProtocolBuffers_MessageOptions::getExtension(string $name)
*/
PHP_METHOD(protocolbuffers_message_options, getExtension)
{
zval *result = NULL, *options = NULL;
zend_string *name_key = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"S", &name_key) == FAILURE) {
return;
}
// name_key = zend_string_init(name,name_len,0);
options = pb_zend_read_property(php_protocol_buffers_descriptor_builder_class_entry, getThis(), ZEND_STRL("extensions"), 1 TSRMLS_CC);
if ((result=zend_hash_find(Z_ARRVAL_P(options), name_key)) == NULL) {
if (strcmp(ZSTR_VAL(name_key), "php") == 0) {
zval *obj;
// MAKE_STD_ZVAL(obj);
object_init_ex(obj, php_protocol_buffers_php_message_options_class_entry);
zend_hash_update(Z_ARRVAL_P(options), name_key, obj);
result = obj;
} else {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "%s extension does not support. now only supports php extension", ZSTR_VAL(name_key));
return;
}
}
RETURN_ZVAL(result, 1, 0);
}
/* }}} */
static zend_function_entry php_protocolbuffers_message_options_methods[] = {
PHP_ME(protocolbuffers_message_options, getExtension, arginfo_protocolbuffers_message_options_get_options, ZEND_ACC_PUBLIC)
PHP_FE_END
};
void php_protocolbuffers_message_options_class(TSRMLS_D)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "ProtocolBuffersMessageOptions", php_protocolbuffers_message_options_methods);
php_protocol_buffers_message_options_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
//zend_declare_property_null(php_protocol_buffers_message_options_class_entry, ZEND_STRL("extensions"), ZEND_ACC_PUBLIC TSRMLS_CC);
PHP_PROTOCOLBUFFERS_REGISTER_NS_CLASS_ALIAS(PHP_PROTOCOLBUFFERS_NAMESPACE, "MessageOptions", php_protocol_buffers_message_options_class_entry);
}