38 #include <Zend/zend_exceptions.h>
39 #include <Zend/zend_inheritance.h>
75 class_type->default_properties_count = 0;
88 zend_object_std_init(&
intern->std, class_type);
104 zval_dtor(&
intern->arena);
105 zend_object_std_dtor(&
intern->std);
119 zend_throw_exception_ex(NULL, 0,
"No such property %s.",
120 ZSTR_VAL(
msg->desc->class_entry->name));
152 if (!msgval.
map_val)
return false;
175 return val1.bool_val ==
val2.bool_val;
179 return val1.int32_val ==
val2.int32_val;
182 return val1.int64_val ==
val2.int64_val;
184 return val1.float_val ==
val2.float_val;
186 return val1.double_val ==
val2.double_val;
189 return val1.str_val.size ==
val2.str_val.size &&
190 memcmp(
val1.str_val.data,
val2.str_val.data,
val1.str_val.size) == 0;
276 zend_throw_exception_ex(
278 "Cannot call isset() on field %s which does not have presence.",
310 zend_throw_exception_ex(
312 "Cannot call unset() on field %s which does not have presence.",
340 int type,
void **cache_slot, zval *rv) {
344 if (!
f)
return &EG(uninitialized_zval);
376 #if PHP_VERSION_ID < 70400
382 #if PHP_VERSION_ID < 70400
385 return &EG(error_zval);
446 zend_object_std_init(&
intern->std,
desc->class_entry);
460 if (Z_ISREF_P(val)) {
464 if (Z_TYPE_P(val) == IS_OBJECT &&
465 instanceof_function(Z_OBJCE_P(val),
desc->class_entry)) {
471 zend_throw_exception_ex(zend_ce_type_error, 0,
472 "Given value is not an instance of %s.",
473 ZSTR_VAL(
desc->class_entry->name));
509 if (Z_ISREF_P(
init)) {
513 if (Z_TYPE_P(
init) != IS_ARRAY) {
514 zend_throw_exception_ex(NULL, 0,
515 "Initializer for a message %s must be an array.",
520 zend_hash_internal_pointer_reset_ex(
table, &
pos);
528 zend_hash_get_current_key_zval_ex(
table, &
key, &
pos);
529 val = zend_hash_get_current_data_ex(
table, &
pos);
531 if (!val)
return true;
533 if (Z_ISREF_P(val)) {
540 zend_throw_exception_ex(NULL, 0,
541 "No such field %s", Z_STRVAL_P(&
key));
547 if (!msgval.
map_val)
return false;
558 zend_hash_move_forward_ex(
table, &
pos);
578 zend_class_entry *ce = Z_OBJCE_P(getThis());
580 zval *init_arr = NULL;
590 ce->create_object = NULL;
595 zend_throw_exception_ex(
597 "Couldn't find descriptor. Note only generated code may derive from "
598 "\\Google\\Protobuf\\Internal\\Message");
604 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"|a!", &init_arr) == FAILURE) {
649 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"O", &
value,
650 intern->desc->class_entry) == FAILURE) {
665 zend_throw_exception_ex(NULL, 0,
"Max nesting exceeded");
682 char *data_copy = NULL;
687 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"s", &
data, &data_len) ==
697 zend_throw_exception_ex(NULL, 0,
"Error occurred during parsing");
718 zend_throw_exception_ex(NULL, 0,
"Error occurred during serialization");
736 char *data_copy = NULL;
740 zend_bool ignore_json_unknown =
false;
743 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"s|b", &
data, &data_len,
744 &ignore_json_unknown) == FAILURE) {
751 data_copy[data_len] =
'\0';
753 if (ignore_json_unknown) {
761 zend_throw_exception_ex(NULL, 0,
"Error occurred during parsing: %s",
778 zend_bool preserve_proto_fieldnames =
false;
781 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"|b",
782 &preserve_proto_fieldnames) == FAILURE) {
786 if (preserve_proto_fieldnames) {
796 zend_throw_exception_ex(NULL, 0,
797 "Error occurred during JSON serialization: %s",
833 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"s", &
member, &
size) == FAILURE) {
840 zend_throw_exception_ex(NULL, 0,
"Message %s has no field %s",
882 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"sz", &
member, &
size, &val) ==
890 zend_throw_exception_ex(NULL, 0,
"Message %s has no field %s",
895 if (Z_ISREF_P(val)) {
899 if (Z_TYPE_P(val) == IS_NULL) {
930 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"s", &
name, &
len) == FAILURE) {
937 zend_throw_exception_ex(NULL, 0,
"Message %s has no oneof %s",
964 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"l", &field_num) == FAILURE) {
971 php_error_docref(NULL, E_USER_ERROR,
972 "Internal error, no such oneof field %d\n",
998 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"l", &field_num) == FAILURE) {
1005 php_error_docref(NULL, E_USER_ERROR,
1006 "Internal error, no such oneof field %d\n",
1044 zend_long field_num;
1050 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"lz", &field_num, &val) ==
1067 ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 0)
1068 ZEND_ARG_INFO(0,
data)
1071 ZEND_BEGIN_ARG_INFO_EX(arginfo_mergeFrom, 0, 0, 1)
1072 ZEND_ARG_INFO(0,
data)
1075 ZEND_BEGIN_ARG_INFO_EX(arginfo_mergeFromWithArg, 0, 0, 1)
1076 ZEND_ARG_INFO(0,
data)
1077 ZEND_ARG_INFO(0,
arg)
1080 ZEND_BEGIN_ARG_INFO_EX(arginfo_read, 0, 0, 1)
1081 ZEND_ARG_INFO(0,
field)
1084 ZEND_BEGIN_ARG_INFO_EX(arginfo_write, 0, 0, 2)
1085 ZEND_ARG_INFO(0,
field)
1086 ZEND_ARG_INFO(0,
value)
1090 PHP_ME(
Message, clear, arginfo_void, ZEND_ACC_PUBLIC)
1091 PHP_ME(
Message, discardUnknownFields, arginfo_void, ZEND_ACC_PUBLIC)
1092 PHP_ME(
Message, serializeToString, arginfo_void, ZEND_ACC_PUBLIC)
1093 PHP_ME(
Message, mergeFromString, arginfo_mergeFrom, ZEND_ACC_PUBLIC)
1094 PHP_ME(
Message, serializeToJsonString, arginfo_void, ZEND_ACC_PUBLIC)
1095 PHP_ME(
Message, mergeFromJsonString, arginfo_mergeFromWithArg, ZEND_ACC_PUBLIC)
1096 PHP_ME(
Message, mergeFrom, arginfo_mergeFrom, ZEND_ACC_PUBLIC)
1097 PHP_ME(
Message, readWrapperValue, arginfo_read, ZEND_ACC_PROTECTED)
1098 PHP_ME(
Message, writeWrapperValue, arginfo_write, ZEND_ACC_PROTECTED)
1099 PHP_ME(
Message, hasOneof, arginfo_read, ZEND_ACC_PROTECTED)
1100 PHP_ME(
Message, readOneof, arginfo_read, ZEND_ACC_PROTECTED)
1101 PHP_ME(
Message, writeOneof, arginfo_write, ZEND_ACC_PROTECTED)
1102 PHP_ME(
Message, whichOneof, arginfo_read, ZEND_ACC_PROTECTED)
1103 PHP_ME(
Message, __construct, arginfo_construct, ZEND_ACC_PROTECTED)
1156 zend_throw_exception(
1157 NULL,
"Type url needs to be type.googleapis.com/fully-qualified",
1165 zend_throw_exception(
1166 NULL,
"Specified message in any hasn't been added to descriptor pool",
1181 zend_throw_exception_ex(NULL, 0,
"Error occurred during parsing");
1199 const char *full_name;
1202 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"o", &val) ==
1207 if (!instanceof_function(Z_OBJCE_P(val),
message_ce)) {
1208 zend_error(E_USER_ERROR,
"Given value is not an instance of Message.");
1232 zend_class_entry *
klass = NULL;
1235 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"C", &
klass) ==
1253 const char *classname =
"\\DatetimeInterface";
1254 zend_string *classname_str = zend_string_init(classname, strlen(classname), 0);
1255 zend_class_entry *date_interface_ce = zend_lookup_class(classname_str);
1256 zend_string_release(classname_str);
1258 if (date_interface_ce == NULL) {
1259 zend_error(E_ERROR,
"Make sure date extension is enabled.");
1263 if (zend_parse_parameters(ZEND_NUM_ARGS(),
"O", &datetime,
1264 date_interface_ce) == FAILURE) {
1265 zend_error(E_USER_ERROR,
"Expect DatetimeInterface.");
1274 ZVAL_STRING(&function_name,
"date_timestamp_get");
1276 if (call_user_function(EG(function_table), NULL, &function_name, &retval, 1,
1277 datetime) == FAILURE ||
1280 zend_error(E_ERROR,
"Cannot get timestamp from DateTime.");
1285 zval_dtor(&function_name);
1294 ZVAL_STRING(&function_name,
"date_format");
1295 ZVAL_STRING(&format_string,
"u");
1302 if (call_user_function(EG(function_table), NULL, &function_name, &retval, 2,
1303 params) == FAILURE ||
1306 zend_error(E_ERROR,
"Cannot format DateTime.");
1313 zval_dtor(&function_name);
1314 zval_dtor(&format_string);
1329 char formatted_time[32];
1330 snprintf(formatted_time,
sizeof(formatted_time),
"%" PRId64
".%06" PRId32,
1337 zval formatted_time_php;
1339 ZVAL_STRING(&function_name,
"date_create_from_format");
1340 ZVAL_STRING(&format_string,
"U.u");
1341 ZVAL_STRING(&formatted_time_php, formatted_time);
1348 if (call_user_function(EG(function_table), NULL, &function_name, &datetime, 2,
1349 params) == FAILURE) {
1350 zend_error(E_ERROR,
"Cannot create DateTime.");
1354 zval_dtor(&function_name);
1355 zval_dtor(&format_string);
1356 zval_dtor(&formatted_time_php);
1358 ZVAL_OBJ(return_value, Z_OBJ(datetime));
1369 zend_class_entry tmp_ce;
1372 INIT_CLASS_ENTRY(tmp_ce,
"Google\\Protobuf\\Internal\\Message",
1375 message_ce = zend_register_internal_class(&tmp_ce);
1378 memcpy(h, &std_object_handlers,
sizeof(zend_object_handlers));
1380 #if PHP_VERSION_ID < 80000
1393 WellKnownTypes_ModuleInit();