-
Notifications
You must be signed in to change notification settings - Fork 38
/
enum.c
135 lines (113 loc) · 4.4 KB
/
enum.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "protocolbuffers.h"
#include "enum.h"
ZEND_BEGIN_ARG_INFO_EX(arginfo_protocolbuffers_enum_is_valid, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_protocolbuffers_enum_get_name, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
/* {{{ proto void ProtocolBuffersEnum::__construct()
*/
PHP_METHOD(protocolbuffers_enum, __construct)
{
}
/* }}} */
/* {{{ proto bool ProtocolBuffersEnum::isValid(long $value)
*/
PHP_METHOD(protocolbuffers_enum, isValid)
{
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3)
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::isValid can't work under PHP 5.3. please consider upgrading your PHP");
return;
#else
long value;
zval *result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &value) == FAILURE) {
return;
}
if (zend_call_method_with_0_params(NULL, EG(called_scope), NULL, "getenumdescriptor", &result)) {
zval *values, **entry;
HashPosition pos;
if (!instanceof_function_ex(Z_OBJCE_P(result), php_protocol_buffers_enum_descriptor_class_entry, 0 TSRMLS_CC)) {
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getEnumDescriptor returns unexpected value.");
zval_ptr_dtor(&result);
return;
}
php_protocolbuffers_read_protected_property(result, ZEND_STRS("values"), &values TSRMLS_CC);
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&entry, &pos) == SUCCESS) {
if (Z_LVAL_PP(entry) == value) {
RETVAL_TRUE;
break;
}
zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos);
}
zval_ptr_dtor(&result);
RETVAL_FALSE;
} else {
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "cannot call ProtocolBuffersEnum::getEnumDescriptor.");
return;
}
#endif
}
/* }}} */
/* {{{ proto string ProtocolBuffersEnum::getName(long $value)
*/
PHP_METHOD(protocolbuffers_enum, getName)
{
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3)
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getName can't work under PHP 5.3. please consider upgrading your PHP");
return;
#else
long value;
zval *result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &value) == FAILURE) {
return;
}
if (zend_call_method_with_0_params(NULL, EG(called_scope), NULL, "getenumdescriptor", &result)) {
zval *values, **entry;
HashPosition pos;
if (!instanceof_function_ex(Z_OBJCE_P(result), php_protocol_buffers_enum_descriptor_class_entry, 0 TSRMLS_CC)) {
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getEnumDescriptor returns unexpected value.");
zval_ptr_dtor(&result);
return;
}
php_protocolbuffers_read_protected_property(result, ZEND_STRS("values"), &values TSRMLS_CC);
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&entry, &pos) == SUCCESS) {
if (Z_LVAL_PP(entry) == value) {
char *key;
uint key_len;
ulong index;
zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &key, &key_len, &index, 0, &pos);
RETURN_STRINGL(key, key_len, 1);
break;
}
zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos);
}
zval_ptr_dtor(&result);
RETVAL_FALSE;
} else {
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "cannot call ProtocolBuffersEnum::getEnumDescriptor.");
return;
}
#endif
}
/* }}} */
static zend_function_entry protocolbuffers_enum_methods[] = {
PHP_ME(protocolbuffers_enum, __construct, NULL, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
PHP_ME(protocolbuffers_enum, isValid, arginfo_protocolbuffers_enum_is_valid, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(protocolbuffers_enum, getName, arginfo_protocolbuffers_enum_get_name, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END
};
void php_protocolbuffers_enum_class(TSRMLS_D)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "ProtocolBuffersEnum", protocolbuffers_enum_methods);
php_protocol_buffers_enum_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
PHP_PROTOCOLBUFFERS_REGISTER_NS_CLASS_ALIAS(PHP_PROTOCOLBUFFERS_NAMESPACE, "Enum", php_protocol_buffers_enum_class_entry);
zend_class_implements(php_protocol_buffers_enum_class_entry TSRMLS_CC, 1, php_protocol_buffers_enum_describable_class_entry);
php_protocol_buffers_enum_class_entry->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
}