26 #include <ext/spl/spl_exceptions.h>
27 #include <zend_exceptions.h>
52 zend_object_std_init(&
intern->std, class_type TSRMLS_CC);
53 object_properties_init(&
intern->std, class_type);
60 *metadata_array TSRMLS_DC) {
61 int count = metadata_array->count;
67 HashTable *array_hash;
74 array_hash = Z_ARRVAL_P(
array);
79 str_key = ecalloc(key_len + 1,
sizeof(
char));
86 if (Z_TYPE_P(
data) != IS_ARRAY) {
87 zend_throw_exception(zend_exception_get_default(TSRMLS_C),
88 "Metadata hash somehow contains wrong types.",
100 array_init(inner_array);
103 add_assoc_zval(
array, str_key, inner_array);
115 HashTable *array_hash;
116 HashTable *inner_array_hash;
122 if (Z_TYPE_P(
array) != IS_ARRAY) {
125 array_hash = Z_ARRVAL_P(
array);
131 if (
key_type != HASH_KEY_IS_STRING ||
key == NULL) {
134 if (Z_TYPE_P(inner_array) != IS_ARRAY) {
137 inner_array_hash = Z_ARRVAL_P(inner_array);
138 metadata->capacity += zend_hash_num_elements(inner_array_hash);
147 if (key_type1 != HASH_KEY_IS_STRING) {
153 inner_array_hash = Z_ARRVAL_P(inner_array);
155 if (Z_TYPE_P(
value) != IS_STRING) {
171 if (
array->metadata) {
172 for (
i = 0;
i <
array->count;
i++) {
206 char *host_override = NULL;
212 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"OsO|s", &channel_obj,
215 &host_override_len) == FAILURE) {
216 zend_throw_exception(spl_ce_InvalidArgumentException,
217 "Call expects a Channel, a String, a Timeval and "
218 "an optional String", 1 TSRMLS_CC);
221 wrapped_grpc_channel *
channel =
223 if (
channel->wrapper == NULL) {
224 zend_throw_exception(spl_ce_InvalidArgumentException,
225 "Call cannot be constructed from a closed Channel",
230 if (
channel->wrapper == NULL ||
channel->wrapper->wrapped == NULL) {
231 zend_throw_exception(spl_ce_InvalidArgumentException,
232 "Call cannot be constructed from a closed Channel",
237 add_property_zval(getThis(),
"channel", channel_obj);
238 wrapped_grpc_timeval *deadline =
241 grpc_slice host_slice = host_override != NULL ?
247 host_override != NULL ? &host_slice : NULL,
248 deadline->wrapped, NULL);
275 if (
call->channel->wrapper == NULL ||
276 call->channel->wrapper->wrapped == NULL) {
277 zend_throw_exception(spl_ce_RuntimeException,
278 "startBatch Error. Channel is closed",
286 HashTable *array_hash;
287 HashTable *status_hash;
288 HashTable *message_hash;
301 zend_string* zmessage = NULL;
310 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"a", &
array) ==
312 zend_throw_exception(spl_ce_InvalidArgumentException,
313 "start_batch expects an array", 1 TSRMLS_CC);
322 array_hash = Z_ARRVAL_P(
array);
329 zend_throw_exception(spl_ce_InvalidArgumentException,
330 "batch keys must be integers", 1 TSRMLS_CC);
341 zend_throw_exception(spl_ce_InvalidArgumentException,
342 "Bad metadata value given", 1 TSRMLS_CC);
349 if (Z_TYPE_P(
value) != IS_ARRAY) {
350 zend_throw_exception(spl_ce_InvalidArgumentException,
351 "Expected an array for send message",
355 message_hash = Z_ARRVAL_P(
value);
357 (
void **)&message_flags) ==
SUCCESS) {
358 if (Z_TYPE_P(message_flags) != IS_LONG) {
359 zend_throw_exception(spl_ce_InvalidArgumentException,
360 "Expected an int for message flags",
366 (
void **)&message_value) !=
SUCCESS ||
367 Z_TYPE_P(message_value) != IS_STRING) {
368 zend_throw_exception(spl_ce_InvalidArgumentException,
369 "Expected a string for send message",
375 Z_STRLEN_P(message_value));
380 status_hash = Z_ARRVAL_P(
value);
382 (
void **)&inner_value) ==
SUCCESS) {
384 zend_throw_exception(spl_ce_InvalidArgumentException,
385 "Bad trailing metadata value given",
395 (
void**)&inner_value) ==
SUCCESS) {
396 if (Z_TYPE_P(inner_value) != IS_LONG) {
397 zend_throw_exception(spl_ce_InvalidArgumentException,
398 "Status code must be an integer",
403 Z_LVAL_P(inner_value);
405 zend_throw_exception(spl_ce_InvalidArgumentException,
406 "Integer status code is required",
411 (
void**)&inner_value) ==
SUCCESS) {
412 if (Z_TYPE_P(inner_value) != IS_STRING) {
413 zend_throw_exception(spl_ce_InvalidArgumentException,
414 "Status details must be a string",
419 Z_STRVAL_P(inner_value));
421 &send_status_details;
423 zend_throw_exception(spl_ce_InvalidArgumentException,
424 "String status details is required",
438 &recv_trailing_metadata;
441 &recv_status_details;
447 zend_throw_exception(spl_ce_InvalidArgumentException,
448 "Unrecognized key in batch", 1 TSRMLS_CC);
457 zend_throw_exception(spl_ce_LogicException,
458 "start_batch was called incorrectly",
459 (
long)
error TSRMLS_CC);
465 for (
int i = 0;
i < op_num;
i++) {
468 add_property_bool(
result,
"send_metadata",
true);
471 add_property_bool(
result,
"send_message",
true);
474 add_property_bool(
result,
"send_close",
true);
477 add_property_bool(
result,
"send_status",
true);
481 add_property_zval(
result,
"metadata", recv_md);
482 zval_ptr_dtor(recv_md);
489 if (zmessage == NULL) {
490 add_property_null(
result,
"message");
493 ZVAL_NEW_STR(&zmessage_val, zmessage);
494 add_property_zval(
result,
"message", &zmessage_val);
495 zval_ptr_dtor(&zmessage_val);
500 object_init(recv_status);
502 add_property_zval(recv_status,
"metadata", recv_md);
503 zval_ptr_dtor(recv_md);
506 add_property_long(recv_status,
"code",
status);
511 add_property_zval(
result,
"status", recv_status);
512 zval_ptr_dtor(recv_status);
517 add_property_bool(
result,
"cancelled", cancelled);
531 for (
int i = 0;
i < op_num;
i++) {
574 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"O", &creds_obj,
576 zend_throw_exception(spl_ce_InvalidArgumentException,
577 "setCredentials expects 1 CallCredentials",
582 wrapped_grpc_call_credentials *creds =
592 ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 3)
595 ZEND_ARG_INFO(0, deadline)
596 ZEND_ARG_INFO(0, host_override)
599 ZEND_BEGIN_ARG_INFO_EX(arginfo_startBatch, 0, 0, 1)
600 ZEND_ARG_INFO(0,
ops)
603 ZEND_BEGIN_ARG_INFO_EX(arginfo_getPeer, 0, 0, 0)
606 ZEND_BEGIN_ARG_INFO_EX(arginfo_cancel, 0, 0, 0)
609 ZEND_BEGIN_ARG_INFO_EX(arginfo_setCredentials, 0, 0, 1)
610 ZEND_ARG_INFO(0, credentials)
614 PHP_ME(
Call, __construct, arginfo_construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
615 PHP_ME(
Call, startBatch, arginfo_startBatch, ZEND_ACC_PUBLIC)
616 PHP_ME(
Call, getPeer, arginfo_getPeer, ZEND_ACC_PUBLIC)
617 PHP_ME(
Call,
cancel, arginfo_cancel, ZEND_ACC_PUBLIC)
618 PHP_ME(
Call, setCredentials, arginfo_setCredentials, ZEND_ACC_PUBLIC)
626 grpc_ce_call = zend_register_internal_class(&ce TSRMLS_CC);