-
Notifications
You must be signed in to change notification settings - Fork 38
/
enum_value_descriptor.c
52 lines (42 loc) · 1.99 KB
/
enum_value_descriptor.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
#include "protocolbuffers.h"
#include "enum_value_descriptor.h"
/* {{{ proto void ProtocolBuffersEnumValueDescriptor::__construct()
*/
PHP_METHOD(protocolbuffers_enum_value_descriptor, __construct)
{
zval *instance = getThis();
zval *value, **element, *tmp;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"a", &value) == FAILURE) {
return;
}
if (!(zend_hash_exists(Z_ARRVAL_P(value), ZEND_STRS("name"))
&& zend_hash_exists(Z_ARRVAL_P(value), ZEND_STRS("value")))) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "expects `name` and `value` key");
return;
}
if (zend_hash_find(Z_ARRVAL_P(value), ZEND_STRS("name"), (void **)&element) == SUCCESS) {
MAKE_STD_ZVAL(tmp);
ZVAL_ZVAL(tmp, *element, 1, 0);
php_protocolbuffers_set_protected_property(instance, ZEND_STRS("name"), tmp TSRMLS_CC);
}
if (zend_hash_find(Z_ARRVAL_P(value), ZEND_STRS("value"), (void **)&element) == SUCCESS) {
MAKE_STD_ZVAL(tmp);
ZVAL_ZVAL(tmp, *element, 1, 0);
php_protocolbuffers_set_protected_property(instance, ZEND_STRS("value"), tmp TSRMLS_CC);
}
}
/* }}} */
static zend_function_entry protocolbuffers_enum_value_descriptor_methods[] = {
PHP_ME(protocolbuffers_enum_value_descriptor, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_FE_END
};
void php_protocolbuffers_enum_value_descriptor_class(TSRMLS_D)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "ProtocolBuffersEnumValueDescriptor", protocolbuffers_enum_value_descriptor_methods);
php_protocol_buffers_enum_value_descriptor_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
PHP_PROTOCOLBUFFERS_REGISTER_NS_CLASS_ALIAS(PHP_PROTOCOLBUFFERS_NAMESPACE, "EnumValueDescriptor", php_protocol_buffers_enum_value_descriptor_class_entry);
zend_declare_property_string(php_protocol_buffers_enum_value_descriptor_class_entry, ZEND_STRS("name")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_long(php_protocol_buffers_enum_value_descriptor_class_entry, ZEND_STRS("value")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
}