diff --git a/amqp.c b/amqp.c index ee3557fb..96eb4ed3 100644 --- a/amqp.c +++ b/amqp.c @@ -49,6 +49,7 @@ #include "amqp_queue.h" #include "amqp_exchange.h" #include "amqp_envelope.h" +#include "amqp_basic_properties.h" #include "amqp_connection_resource.h" @@ -118,6 +119,7 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ PHP_MINIT(amqp_channel)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(amqp_queue)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(amqp_exchange)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_basic_properties)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(amqp_envelope)(INIT_FUNC_ARGS_PASSTHRU); /* Class Exceptions */ diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c new file mode 100644 index 00000000..1eb05906 --- /dev/null +++ b/amqp_basic_properties.c @@ -0,0 +1,563 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2007 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | + | Lead: | + | - Pieter de Zwart | + | Maintainers: | + | - Brad Rodriguez | + | - Jonathan Tansavatdi | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "ext/standard/info.h" +#include "zend_exceptions.h" + +#ifdef PHP_WIN32 +# include "win32/php_stdint.h" +# include "win32/signal.h" +#else + +# include +# include + +#endif + +#include +#include + +#ifdef PHP_WIN32 +# include "win32/unistd.h" +#else + +# include + +#endif + +#include "amqp_basic_properties.h" +#include "php_amqp.h" + +zend_class_entry *amqp_basic_properties_class_entry; +#define this_ce amqp_basic_properties_class_entry + + +void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj TSRMLS_DC) +{ + object_init_ex(obj, this_ce); + + php_amqp_basic_properties_extract(props, obj TSRMLS_CC); +} + +void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC) { + PHP5to7_zval_t headers PHP5to7_MAYBE_SET_TO_NULL; + + PHP5to7_MAYBE_INIT(headers); + PHP5to7_ARRAY_INIT(headers); + + zend_update_property(this_ce, obj, ZEND_STRL("headers"), PHP5to7_MAYBE_PTR(headers) TSRMLS_CC); + + PHP5to7_MAYBE_DESTROY(headers); +} + + +/* {{{ proto AMQPBasicProperties::__construct() */ +static PHP_METHOD(AMQPBasicProperties, __construct) { + + char *content_type = NULL; PHP5to7_param_str_len_type_t content_type_len = 0; + char *content_encoding = NULL; PHP5to7_param_str_len_type_t content_encoding_len = 0; + + zval *headers = NULL; + + PHP5to7_param_long_type_t delivery_mode = AMQP_DELIVERY_NONPERSISTENT; + PHP5to7_param_long_type_t priority = 0; + + char *correlation_id = NULL; PHP5to7_param_str_len_type_t correlation_id_len = 0; + char *reply_to = NULL; PHP5to7_param_str_len_type_t reply_to_len = 0; + char *expiration = NULL; PHP5to7_param_str_len_type_t expiration_len = 0; + char *message_id = NULL; PHP5to7_param_str_len_type_t message_id_len = 0; + + PHP5to7_param_long_type_t timestamp = 0; + + char *type = NULL; PHP5to7_param_str_len_type_t type_len = 0; + char *user_id = NULL; PHP5to7_param_str_len_type_t user_id_len = 0; + char *app_id = NULL; PHP5to7_param_str_len_type_t app_id_len = 0; + char *cluster_id = NULL; PHP5to7_param_str_len_type_t cluster_id_len = 0; + + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssallsssslssss", + /* s */ &content_type, &content_type_len, + /* s */ &content_encoding, &content_encoding_len, + /* a */ &headers, + /* l */ &delivery_mode, + /* l */ &priority, + /* s */ &correlation_id, &correlation_id_len, + /* s */ &reply_to, &reply_to_len, + /* s */ &expiration, &expiration_len, + /* s */ &message_id, &message_id_len, + /* l */ ×tamp, + /* s */ &type, &type_len, + /* s */ &user_id, &user_id_len, + /* s */ &app_id, &app_id_len, + /* s */ &cluster_id, &cluster_id_len + ) == FAILURE) { + return; + } + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("content_type"), content_type, content_type_len TSRMLS_CC); + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("content_encoding"), content_encoding, content_encoding_len TSRMLS_CC); + + if (headers != NULL) { + zend_update_property(this_ce, getThis(), ZEND_STRL("headers"), headers TSRMLS_CC); + } else { + php_amqp_basic_properties_set_empty_headers(getThis() TSRMLS_CC); + } + + zend_update_property_long(this_ce, getThis(), ZEND_STRL("delivery_mode"), delivery_mode TSRMLS_CC); + zend_update_property_long(this_ce, getThis(), ZEND_STRL("priority"), priority TSRMLS_CC); + + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("correlation_id"), correlation_id, correlation_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("reply_to"), reply_to, reply_to_len TSRMLS_CC); + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("expiration"), expiration, expiration_len TSRMLS_CC); + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("message_id"), message_id, message_id_len TSRMLS_CC); + + zend_update_property_long(this_ce, getThis(), ZEND_STRL("timestamp"), timestamp TSRMLS_CC); + + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("type"), type, type_len TSRMLS_CC); + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("user_id"), user_id, user_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("app_id"), app_id, app_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("cluster_id"), cluster_id, cluster_id_len TSRMLS_CC); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getContentType() */ +static PHP_METHOD(AMQPBasicProperties, getContentType) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("content_type"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getContentEncoding() */ +static PHP_METHOD(AMQPBasicProperties, getContentEncoding) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("content_encoding"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getCorrelationId() */ +static PHP_METHOD(AMQPBasicProperties, getHeaders) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("headers"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getDeliveryMode() */ +static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("delivery_mode"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getPriority() */ +static PHP_METHOD(AMQPBasicProperties, getPriority) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("priority"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getCorrelationId() */ +static PHP_METHOD(AMQPBasicProperties, getCorrelationId) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("correlation_id"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getReplyTo() */ +static PHP_METHOD(AMQPBasicProperties, getReplyTo) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("reply_to"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getExpiration() +check amqp envelope */ +static PHP_METHOD(AMQPBasicProperties, getExpiration) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("expiration"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getMessageId() */ +static PHP_METHOD(AMQPBasicProperties, getMessageId) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("message_id"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getTimestamp() */ +static PHP_METHOD(AMQPBasicProperties, getTimestamp) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("timestamp"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getType() */ +static PHP_METHOD(AMQPBasicProperties, getType) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("type"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getUserId() */ +static PHP_METHOD(AMQPBasicProperties, getUserId) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("user_id"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getAppId() */ +static PHP_METHOD(AMQPBasicProperties, getAppId) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("app_id"); +} +/* }}} */ + +/* {{{ proto AMQPBasicProperties::getClusterId() */ +static PHP_METHOD(AMQPBasicProperties, getClusterId) { + PHP5to7_READ_PROP_RV_PARAM_DECL; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("cluster_id"); +} +/* }}} */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getContentType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getContentEncoding, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getHeaders, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getDeliveryMode, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getPriority, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getCorrelationId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getReplyTo, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getExpiration, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getMessageId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getTimestamp, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getUserId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getAppId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getClusterId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + + +zend_function_entry amqp_basic_properties_class_functions[] = { + PHP_ME(AMQPBasicProperties, __construct, arginfo_amqp_basic_properties_class__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + + PHP_ME(AMQPBasicProperties, getContentType, arginfo_amqp_basic_properties_class_getContentType, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getContentEncoding, arginfo_amqp_basic_properties_class_getContentEncoding, ZEND_ACC_PUBLIC) + + PHP_ME(AMQPBasicProperties, getHeaders, arginfo_amqp_basic_properties_class_getHeaders, ZEND_ACC_PUBLIC) + + PHP_ME(AMQPBasicProperties, getDeliveryMode, arginfo_amqp_basic_properties_class_getDeliveryMode, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getPriority, arginfo_amqp_basic_properties_class_getPriority, ZEND_ACC_PUBLIC) + + PHP_ME(AMQPBasicProperties, getCorrelationId, arginfo_amqp_basic_properties_class_getCorrelationId, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getReplyTo, arginfo_amqp_basic_properties_class_getReplyTo, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getExpiration, arginfo_amqp_basic_properties_class_getExpiration, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getMessageId, arginfo_amqp_basic_properties_class_getMessageId, ZEND_ACC_PUBLIC) + + PHP_ME(AMQPBasicProperties, getTimestamp, arginfo_amqp_basic_properties_class_getTimestamp, ZEND_ACC_PUBLIC) + + PHP_ME(AMQPBasicProperties, getType, arginfo_amqp_basic_properties_class_getType, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getUserId, arginfo_amqp_basic_properties_class_getUserId, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getAppId, arginfo_amqp_basic_properties_class_getAppId, ZEND_ACC_PUBLIC) + PHP_ME(AMQPBasicProperties, getClusterId, arginfo_amqp_basic_properties_class_getClusterId, ZEND_ACC_PUBLIC) + + {NULL, NULL, NULL} +}; + + +PHP_MINIT_FUNCTION (amqp_basic_properties) { + zend_class_entry ce; + + INIT_CLASS_ENTRY(ce, "AMQPBasicProperties", amqp_basic_properties_class_functions); + this_ce = zend_register_internal_class(&ce TSRMLS_CC); + + zend_declare_property_stringl(this_ce, ZEND_STRL("content_type"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("content_encoding"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + + zend_declare_property_null(this_ce, ZEND_STRL("headers"), ZEND_ACC_PRIVATE TSRMLS_CC); + + zend_declare_property_long(this_ce, ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_long(this_ce, ZEND_STRL("priority"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + + zend_declare_property_stringl(this_ce, ZEND_STRL("correlation_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("reply_to"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("expiration"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("message_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + + zend_declare_property_long(this_ce, ZEND_STRL("timestamp"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + + zend_declare_property_stringl(this_ce, ZEND_STRL("type"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("user_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("app_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("cluster_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + + return SUCCESS; +} + + +void parse_amqp_table(amqp_table_t *table, zval *result) { + int i; + PHP5to7_zval_t value PHP5to7_MAYBE_SET_TO_NULL; + + assert(Z_TYPE_P(result) == IS_ARRAY); + + for (i = 0; i < table->num_entries; i++) { + PHP5to7_MAYBE_INIT(value); + + amqp_table_entry_t *entry = &(table->entries[i]); + switch (entry->value.kind) { + case AMQP_FIELD_KIND_BOOLEAN: + ZVAL_BOOL(PHP5to7_MAYBE_PTR(value), entry->value.value.boolean); + break; + case AMQP_FIELD_KIND_I8: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i8); + break; + case AMQP_FIELD_KIND_U8: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u8); + break; + case AMQP_FIELD_KIND_I16: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i16); + break; + case AMQP_FIELD_KIND_U16: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u16); + break; + case AMQP_FIELD_KIND_I32: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i32); + break; + case AMQP_FIELD_KIND_U32: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u32); + break; + case AMQP_FIELD_KIND_I64: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i64); + break; + case AMQP_FIELD_KIND_U64: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i64); + break; + case AMQP_FIELD_KIND_F32: ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.f32); + break; + case AMQP_FIELD_KIND_F64: ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.f64); + break; + case AMQP_FIELD_KIND_UTF8: + case AMQP_FIELD_KIND_BYTES: + PHP5to7_ZVAL_STRINGL_DUP(PHP5to7_MAYBE_PTR(value), entry->value.value.bytes.bytes, entry->value.value.bytes.len); + break; + case AMQP_FIELD_KIND_ARRAY: { + int j; + array_init(PHP5to7_MAYBE_PTR(value)); + for (j = 0; j < entry->value.value.array.num_entries; ++j) { + switch (entry->value.value.array.entries[j].kind) { + case AMQP_FIELD_KIND_UTF8: + PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP( + PHP5to7_MAYBE_PTR(value), + entry->value.value.array.entries[j].value.bytes.bytes, + (uint) entry->value.value.array.entries[j].value.bytes.len + ); + break; + case AMQP_FIELD_KIND_TABLE: { + PHP5to7_zval_t subtable PHP5to7_MAYBE_SET_TO_NULL; + PHP5to7_MAYBE_INIT(subtable); + PHP5to7_ARRAY_INIT(subtable); + + parse_amqp_table( + &(entry->value.value.array.entries[j].value.table), + PHP5to7_MAYBE_PTR(subtable) + ); + add_next_index_zval(PHP5to7_MAYBE_PTR(value), PHP5to7_MAYBE_PTR(subtable)); + } + break; + default: + break; + } + } + } + break; + case AMQP_FIELD_KIND_TABLE: + PHP5to7_ARRAY_INIT(value); + parse_amqp_table(&(entry->value.value.table), PHP5to7_MAYBE_PTR(value)); + break; + case AMQP_FIELD_KIND_TIMESTAMP: ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.u64); + break; + case AMQP_FIELD_KIND_VOID: + case AMQP_FIELD_KIND_DECIMAL: + default: ZVAL_NULL(PHP5to7_MAYBE_PTR(value)); + break; + } + + if (Z_TYPE_P(PHP5to7_MAYBE_PTR(value)) != IS_NULL) { + char *key = estrndup(entry->key.bytes, (uint) entry->key.len); + add_assoc_zval(result, key, PHP5to7_MAYBE_PTR(value)); + efree(key); + } else { + PHP5to7_MAYBE_DESTROY(value); + } + } + return; +} + +void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSRMLS_DC) +{ + PHP5to7_zval_t headers PHP5to7_MAYBE_SET_TO_NULL; + + PHP5to7_MAYBE_INIT(headers); + PHP5to7_ARRAY_INIT(headers); + + if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("content_type"), (const char *) p->content_type.bytes, (PHP5to7_param_str_len_type_t) p->content_type.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("content_type"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("content_encoding"), (const char *) p->content_encoding.bytes, (PHP5to7_param_str_len_type_t) p->content_encoding.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("content_encoding"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { + parse_amqp_table(&(p->headers), PHP5to7_MAYBE_PTR(headers)); + } + + zend_update_property(this_ce, obj, ZEND_STRL("headers"), PHP5to7_MAYBE_PTR(headers) TSRMLS_CC); + + if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { + zend_update_property_long(this_ce, obj, ZEND_STRL("delivery_mode"), (PHP5to7_param_long_type_t) p->delivery_mode TSRMLS_CC); + } else { + /* BC */ + zend_update_property_long(this_ce, obj, ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) { + zend_update_property_long(this_ce, obj, ZEND_STRL("priority"), (PHP5to7_param_long_type_t) p->priority TSRMLS_CC); + } else { + /* BC */ + zend_update_property_long(this_ce, obj, ZEND_STRL("priority"), 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("correlation_id"), (const char *) p->correlation_id.bytes, (PHP5to7_param_str_len_type_t) p->correlation_id.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("correlation_id"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("reply_to"), (const char *) p->reply_to.bytes, (PHP5to7_param_str_len_type_t) p->reply_to.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("reply_to"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("expiration"), (const char *) p->expiration.bytes, (PHP5to7_param_str_len_type_t) p->expiration.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("expiration"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("message_id"), (const char *) p->message_id.bytes, (PHP5to7_param_str_len_type_t) p->message_id.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("message_id"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { + zend_update_property_long(this_ce, obj, ZEND_STRL("timestamp"), (PHP5to7_param_long_type_t) p->timestamp TSRMLS_CC); + } else { + /* BC */ + zend_update_property_long(this_ce, obj, ZEND_STRL("timestamp"), 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_TYPE_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("type"), (const char *) p->type.bytes, (PHP5to7_param_str_len_type_t) p->type.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("type"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_USER_ID_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("user_id"), (const char *) p->user_id.bytes, (PHP5to7_param_str_len_type_t) p->user_id.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("user_id"), "", 0 TSRMLS_CC); + } + + if (p->_flags & AMQP_BASIC_APP_ID_FLAG) { + zend_update_property_stringl(this_ce, obj, ZEND_STRL("app_id"), (const char *) p->app_id.bytes, (PHP5to7_param_str_len_type_t) p->app_id.len TSRMLS_CC); + } else { + /* BC */ + zend_update_property_stringl(this_ce, obj, ZEND_STRL("app_id"), "", 0 TSRMLS_CC); + } + + PHP5to7_MAYBE_DESTROY(headers); +} + + +/* +*Local variables: +*tab-width: 4 +*c-basic-offset: 4 +*End: +*vim600: noet sw=4 ts=4 fdm=marker +*vim<600: noet sw=4 ts=4 +*/ diff --git a/amqp_basic_properties.h b/amqp_basic_properties.h new file mode 100644 index 00000000..a66fa17b --- /dev/null +++ b/amqp_basic_properties.h @@ -0,0 +1,47 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2007 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | + | Lead: | + | - Pieter de Zwart | + | Maintainers: | + | - Brad Rodriguez | + | - Jonathan Tansavatdi | + +----------------------------------------------------------------------+ +*/ + +#include "php.h" +#include "php_amqp.h" + +extern zend_class_entry *amqp_basic_properties_class_entry; + +void parse_amqp_table(amqp_table_t *table, zval *result); +void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSRMLS_DC); + + +void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj TSRMLS_DC); +void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC); + + +PHP_MINIT_FUNCTION(amqp_basic_properties); + + +/* +*Local variables: +*tab-width: 4 +*c-basic-offset: 4 +*End: +*vim600: noet sw=4 ts=4 fdm=marker +*vim<600: noet sw=4 ts=4 +*/ diff --git a/amqp_envelope.c b/amqp_envelope.c index 2e254e7a..e0922b31 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -53,23 +53,19 @@ #endif -#include "php_amqp.h" #include "amqp_envelope.h" +#include "amqp_basic_properties.h" +#include "php_amqp.h" zend_class_entry *amqp_envelope_class_entry; #define this_ce amqp_envelope_class_entry -void parse_amqp_table(amqp_table_t *table, zval *result); void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelope TSRMLS_DC) { - PHP5to7_zval_t headers PHP5to7_MAYBE_SET_TO_NULL; - /* Build the envelope */ object_init_ex(envelope, this_ce); - PHP5to7_MAYBE_INIT(headers); - PHP5to7_ARRAY_INIT(headers); amqp_basic_properties_t *p = &amqp_envelope->message.properties; amqp_message_t *message = &amqp_envelope->message; @@ -81,140 +77,21 @@ void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelop zend_update_property_stringl(this_ce, envelope, ZEND_STRL("exchange_name"), (const char *) amqp_envelope->exchange.bytes, (PHP5to7_param_str_len_type_t) amqp_envelope->exchange.len TSRMLS_CC); zend_update_property_stringl(this_ce, envelope, ZEND_STRL("routing_key"), (const char *) amqp_envelope->routing_key.bytes, (PHP5to7_param_str_len_type_t) amqp_envelope->routing_key.len TSRMLS_CC); - - - if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("content_type"), (const char *) p->content_type.bytes, (PHP5to7_param_str_len_type_t) p->content_type.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("content_type"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("content_encoding"), (const char *) p->content_encoding.bytes, (PHP5to7_param_str_len_type_t) p->content_encoding.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("content_encoding"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { - parse_amqp_table(&(p->headers), PHP5to7_MAYBE_PTR(headers)); - } - - zend_update_property(this_ce, envelope, ZEND_STRL("headers"), PHP5to7_MAYBE_PTR(headers) TSRMLS_CC); - - if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { - zend_update_property_long(this_ce, envelope, ZEND_STRL("delivery_mode"), (PHP5to7_param_long_type_t) p->delivery_mode TSRMLS_CC); - } else { - /* BC */ - zend_update_property_long(this_ce, envelope, ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) { - zend_update_property_long(this_ce, envelope, ZEND_STRL("priority"), (PHP5to7_param_long_type_t) p->priority TSRMLS_CC); - } else { - /* BC */ - zend_update_property_long(this_ce, envelope, ZEND_STRL("priority"), 0 TSRMLS_CC); - } - - - if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("correlation_id"), (const char *) p->correlation_id.bytes, (PHP5to7_param_str_len_type_t) p->correlation_id.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("correlation_id"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("reply_to"), (const char *) p->reply_to.bytes, (PHP5to7_param_str_len_type_t) p->reply_to.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("reply_to"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("expiration"), (const char *) p->expiration.bytes, (PHP5to7_param_str_len_type_t) p->expiration.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("expiration"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("message_id"), (const char *) p->message_id.bytes, (PHP5to7_param_str_len_type_t) p->message_id.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("message_id"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { - zend_update_property_long(this_ce, envelope, ZEND_STRL("timestamp"), (PHP5to7_param_long_type_t) p->timestamp TSRMLS_CC); - } else { - /* BC */ - zend_update_property_long(this_ce, envelope, ZEND_STRL("timestamp"), 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_TYPE_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("type"), (const char *) p->type.bytes, (PHP5to7_param_str_len_type_t) p->type.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("type"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_USER_ID_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("user_id"), (const char *) p->user_id.bytes, (PHP5to7_param_str_len_type_t) p->user_id.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("user_id"), "", 0 TSRMLS_CC); - } - - if (p->_flags & AMQP_BASIC_APP_ID_FLAG) { - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("app_id"), (const char *) p->app_id.bytes, (PHP5to7_param_str_len_type_t) p->app_id.len TSRMLS_CC); - } else { - /* BC */ - zend_update_property_stringl(this_ce, envelope, ZEND_STRL("app_id"), "", 0 TSRMLS_CC); - } - - PHP5to7_MAYBE_DESTROY(headers); + php_amqp_basic_properties_extract(p, envelope TSRMLS_CC); } - /* {{{ proto AMQPEnvelope::__construct() */ -PHP_METHOD (amqp_envelope_class, __construct) { +static PHP_METHOD(amqp_envelope_class, __construct) { PHP_AMQP_NOPARAMS(); /* BC */ - PHP5to7_zval_t headers PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_MAYBE_INIT(headers); - PHP5to7_ARRAY_INIT(headers); - - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("body"), "", 0 TSRMLS_CC); - - zend_update_property_long(this_ce, getThis(), ZEND_STRL("delivery_tag"), 0 TSRMLS_CC); - zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_redelivery"), 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("exchange_name"), "", 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("routing_key"), "", 0 TSRMLS_CC); - - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("content_type"), "", 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("content_encoding"), "", 0 TSRMLS_CC); - zend_update_property(this_ce, getThis(), ZEND_STRL("headers"), PHP5to7_MAYBE_PTR(headers) TSRMLS_CC); - zend_update_property_long(this_ce, getThis(), ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC); - zend_update_property_long(this_ce, getThis(), ZEND_STRL("priority"), 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("correlation_id"), "", 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("reply_to"), "", 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("expiration"), "", 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("message_id"), "", 0 TSRMLS_CC); - zend_update_property_long(this_ce, getThis(), ZEND_STRL("timestamp"), 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("type"), "", 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("user_id"), "", 0 TSRMLS_CC); - zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("app_id"), "", 0 TSRMLS_CC); - - PHP5to7_MAYBE_DESTROY(headers); + php_amqp_basic_properties_set_empty_headers(getThis() TSRMLS_CC); } /* }}} */ /* {{{ proto AMQPEnvelope::getBody()*/ -PHP_METHOD (amqp_envelope_class, getBody) { +static PHP_METHOD(amqp_envelope_class, getBody) { PHP5to7_READ_PROP_RV_PARAM_DECL; PHP_AMQP_NOPARAMS(); @@ -231,24 +108,15 @@ PHP_METHOD (amqp_envelope_class, getBody) { /* }}} */ /* {{{ proto AMQPEnvelope::getRoutingKey() */ -PHP_METHOD (amqp_envelope_class, getRoutingKey) { +static PHP_METHOD(amqp_envelope_class, getRoutingKey) { PHP5to7_READ_PROP_RV_PARAM_DECL; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("routing_key"); } /* }}} */ -/* {{{ proto AMQPEnvelope::getDeliveryMode() */ -PHP_METHOD (amqp_envelope_class, getDeliveryMode) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("delivery_mode"); -} -/* }}} */ - - /* {{{ proto AMQPEnvelope::getDeliveryTag() */ -PHP_METHOD (amqp_envelope_class, getDeliveryTag) { +static PHP_METHOD(amqp_envelope_class, getDeliveryTag) { PHP5to7_READ_PROP_RV_PARAM_DECL; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("delivery_tag"); @@ -256,7 +124,7 @@ PHP_METHOD (amqp_envelope_class, getDeliveryTag) { /* }}} */ /* {{{ proto AMQPEnvelope::getExchangeName() */ -PHP_METHOD (amqp_envelope_class, getExchangeName) { +static PHP_METHOD(amqp_envelope_class, getExchangeName) { PHP5to7_READ_PROP_RV_PARAM_DECL; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("exchange_name"); @@ -264,105 +132,16 @@ PHP_METHOD (amqp_envelope_class, getExchangeName) { /* }}} */ /* {{{ proto AMQPEnvelope::isRedelivery() */ -PHP_METHOD (amqp_envelope_class, isRedelivery) { +static PHP_METHOD(amqp_envelope_class, isRedelivery) { PHP5to7_READ_PROP_RV_PARAM_DECL; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("is_redelivery"); } /* }}} */ -/* {{{ proto AMQPEnvelope::getContentType() */ -PHP_METHOD (amqp_envelope_class, getContentType) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("content_type"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getContentEncoding() */ -PHP_METHOD (amqp_envelope_class, getContentEncoding) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("content_encoding"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getType() */ -PHP_METHOD (amqp_envelope_class, getType) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("type"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getTimestamp() */ -PHP_METHOD (amqp_envelope_class, getTimestamp) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("timestamp"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getPriority() */ -PHP_METHOD (amqp_envelope_class, getPriority) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("priority"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getExpiration() -check amqp envelope */ -PHP_METHOD (amqp_envelope_class, getExpiration) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("expiration"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getUserId() */ -PHP_METHOD (amqp_envelope_class, getUserId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("user_id"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getAppId() */ -PHP_METHOD (amqp_envelope_class, getAppId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("app_id"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getMessageId() */ -PHP_METHOD (amqp_envelope_class, getMessageId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("message_id"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getReplyTo() */ -PHP_METHOD (amqp_envelope_class, getReplyTo) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("reply_to"); -} -/* }}} */ - -/* {{{ proto AMQPEnvelope::getCorrelationId() */ -PHP_METHOD (amqp_envelope_class, getCorrelationId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("correlation_id"); -} -/* }}} */ - /* {{{ proto AMQPEnvelope::getHeader(string name) */ -PHP_METHOD (amqp_envelope_class, getHeader) { +static PHP_METHOD(amqp_envelope_class, getHeader) { PHP5to7_READ_PROP_RV_PARAM_DECL; char *key; PHP5to7_param_str_len_type_t key_len; @@ -372,7 +151,8 @@ PHP_METHOD (amqp_envelope_class, getHeader) { return; } - zval* zv = PHP_AMQP_READ_THIS_PROP("headers"); + zval* zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); + //zval* zv = PHP_AMQP_READ_THIS_PROP("headers"); /* Look for the hash key */ if (!PHP5to7_ZEND_HASH_FIND(HASH_OF(zv), key, key_len + 1, tmp)) { @@ -385,7 +165,7 @@ PHP_METHOD (amqp_envelope_class, getHeader) { /* {{{ proto AMQPEnvelope::hasHeader(string name) */ -PHP_METHOD (amqp_envelope_class, hasHeader) { +static PHP_METHOD(amqp_envelope_class, hasHeader) { PHP5to7_READ_PROP_RV_PARAM_DECL; char *key; PHP5to7_param_str_len_type_t key_len; @@ -395,7 +175,8 @@ PHP_METHOD (amqp_envelope_class, hasHeader) { return; } - zval* zv = PHP_AMQP_READ_THIS_PROP("headers"); + zval* zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); + //zval* zv = PHP_AMQP_READ_THIS_PROP("headers"); /* Look for the hash key */ if (!PHP5to7_ZEND_HASH_FIND(HASH_OF(zv), key, key_len + 1, tmp)) { @@ -406,13 +187,6 @@ PHP_METHOD (amqp_envelope_class, hasHeader) { } /* }}} */ -/* {{{ proto AMQPEnvelope::getHeaders() */ -PHP_METHOD (amqp_envelope_class, getHeaders) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("headers"); -} -/* }}} */ /* amqp_envelope_class ARG_INFO definition */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -427,51 +201,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getDeliveryTag, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getDeliveryMode, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getExchangeName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_isRedelivery, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getContentType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getContentEncoding, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getTimestamp, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getPriority, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getExpiration, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getUserId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getAppId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getMessageId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getReplyTo, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getCorrelationId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getHeaders, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getHeader, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() @@ -480,26 +215,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_hasHeader, ZEND_SEND_BY_VAL, ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() + zend_function_entry amqp_envelope_class_functions[] = { - PHP_ME(amqp_envelope_class, __construct, arginfo_amqp_envelope_class__construct, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, __construct, arginfo_amqp_envelope_class__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(amqp_envelope_class, getBody, arginfo_amqp_envelope_class_getBody, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getRoutingKey, arginfo_amqp_envelope_class_getRoutingKey, ZEND_ACC_PUBLIC) PHP_ME(amqp_envelope_class, getDeliveryTag, arginfo_amqp_envelope_class_getDeliveryTag, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getDeliveryMode, arginfo_amqp_envelope_class_getDeliveryMode, ZEND_ACC_PUBLIC) PHP_ME(amqp_envelope_class, getExchangeName, arginfo_amqp_envelope_class_getExchangeName, ZEND_ACC_PUBLIC) PHP_ME(amqp_envelope_class, isRedelivery, arginfo_amqp_envelope_class_isRedelivery, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getContentType, arginfo_amqp_envelope_class_getContentType, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getContentEncoding, arginfo_amqp_envelope_class_getContentEncoding, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getType, arginfo_amqp_envelope_class_getType, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getTimestamp, arginfo_amqp_envelope_class_getTimestamp, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getPriority, arginfo_amqp_envelope_class_getPriority, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getExpiration, arginfo_amqp_envelope_class_getExpiration, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getUserId, arginfo_amqp_envelope_class_getUserId, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getAppId, arginfo_amqp_envelope_class_getAppId, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getMessageId, arginfo_amqp_envelope_class_getMessageId, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getReplyTo, arginfo_amqp_envelope_class_getReplyTo, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getCorrelationId, arginfo_amqp_envelope_class_getCorrelationId, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getHeaders, arginfo_amqp_envelope_class_getHeaders, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getHeader, arginfo_amqp_envelope_class_getHeader, ZEND_ACC_PUBLIC) PHP_ME(amqp_envelope_class, hasHeader, arginfo_amqp_envelope_class_hasHeader, ZEND_ACC_PUBLIC) @@ -511,153 +237,19 @@ PHP_MINIT_FUNCTION (amqp_envelope) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPEnvelope", amqp_envelope_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); - + this_ce = zend_register_internal_class_ex(&ce, amqp_basic_properties_class_entry PHP5to7_PARENT_CLASS_NAME_C(NULL) TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("body"), ZEND_ACC_PRIVATE TSRMLS_CC); - /* - deliver(consumer-tag consumer-tag, - delivery-tag delivery-tag, - redelivered redelivered, - exchange-name exchange, - shortstr routing-key) - - get-ok(delivery-tag delivery-tag, - redelivered redelivered, - exchange-name exchange, - shortstr routing-key, - message-count message-count) - */ zend_declare_property_null(this_ce, ZEND_STRL("delivery_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("is_redelivery"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("exchange_name"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("routing_key"), ZEND_ACC_PRIVATE TSRMLS_CC); - /* - shortstr content-type MIME content type. - shortstr content-encoding MIME content encoding. - table headers Message header field table. - octet delivery-mode Non-persistent (1) or persistent (2). - octet priority Message priority, 0 to 9. - shortstr correlation-id Application correlation identifier. - shortstr reply-to Address to reply to. - shortstr expiration Message expiration specification. - shortstr message-id Application message identifier. - timestamp timestamp Message timestamp. - shortstr type Message type name. - shortstr user-id Creating user id. - shortstr app-id Creating application id. - */ - zend_declare_property_null(this_ce, ZEND_STRL("content_type"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("content_encoding"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("headers"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("delivery_mode"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("priority"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("correlation_id"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("reply_to"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("expiration"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("message_id"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("timestamp"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("type"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("user_id"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("app_id"), ZEND_ACC_PRIVATE TSRMLS_CC); - return SUCCESS; } -void parse_amqp_table(amqp_table_t *table, zval *result) { - int i; - PHP5to7_zval_t value PHP5to7_MAYBE_SET_TO_NULL; - - assert(Z_TYPE_P(result) == IS_ARRAY); - - for (i = 0; i < table->num_entries; i++) { - PHP5to7_MAYBE_INIT(value); - - amqp_table_entry_t *entry = &(table->entries[i]); - switch (entry->value.kind) { - case AMQP_FIELD_KIND_BOOLEAN: - ZVAL_BOOL(PHP5to7_MAYBE_PTR(value), entry->value.value.boolean); - break; - case AMQP_FIELD_KIND_I8: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i8); - break; - case AMQP_FIELD_KIND_U8: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u8); - break; - case AMQP_FIELD_KIND_I16: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i16); - break; - case AMQP_FIELD_KIND_U16: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u16); - break; - case AMQP_FIELD_KIND_I32: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i32); - break; - case AMQP_FIELD_KIND_U32: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u32); - break; - case AMQP_FIELD_KIND_I64: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i64); - break; - case AMQP_FIELD_KIND_U64: ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i64); - break; - case AMQP_FIELD_KIND_F32: ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.f32); - break; - case AMQP_FIELD_KIND_F64: ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.f64); - break; - case AMQP_FIELD_KIND_UTF8: - case AMQP_FIELD_KIND_BYTES: - PHP5to7_ZVAL_STRINGL_DUP(PHP5to7_MAYBE_PTR(value), entry->value.value.bytes.bytes, entry->value.value.bytes.len); - break; - case AMQP_FIELD_KIND_ARRAY: { - int j; - array_init(PHP5to7_MAYBE_PTR(value)); - for (j = 0; j < entry->value.value.array.num_entries; ++j) { - switch (entry->value.value.array.entries[j].kind) { - case AMQP_FIELD_KIND_UTF8: - PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP( - PHP5to7_MAYBE_PTR(value), - entry->value.value.array.entries[j].value.bytes.bytes, - (uint) entry->value.value.array.entries[j].value.bytes.len - ); - break; - case AMQP_FIELD_KIND_TABLE: { - PHP5to7_zval_t subtable PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_MAYBE_INIT(subtable); - PHP5to7_ARRAY_INIT(subtable); - - parse_amqp_table( - &(entry->value.value.array.entries[j].value.table), - PHP5to7_MAYBE_PTR(subtable) - ); - add_next_index_zval(PHP5to7_MAYBE_PTR(value), PHP5to7_MAYBE_PTR(subtable)); - } - break; - default: - break; - } - } - } - break; - case AMQP_FIELD_KIND_TABLE: - PHP5to7_ARRAY_INIT(value); - parse_amqp_table(&(entry->value.value.table), PHP5to7_MAYBE_PTR(value)); - break; - case AMQP_FIELD_KIND_TIMESTAMP: ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.u64); - break; - case AMQP_FIELD_KIND_VOID: - case AMQP_FIELD_KIND_DECIMAL: - default: ZVAL_NULL(PHP5to7_MAYBE_PTR(value)); - break; - } - - if (Z_TYPE_P(PHP5to7_MAYBE_PTR(value)) != IS_NULL) { - char *key = estrndup(entry->key.bytes, (uint) entry->key.len); - add_assoc_zval(result, key, PHP5to7_MAYBE_PTR(value)); - efree(key); - } else { - PHP5to7_MAYBE_DESTROY(value); - } - } - return; -} - /* *Local variables: *tab-width: 4 diff --git a/amqp_envelope.h b/amqp_envelope.h index c930b9a5..634f800e 100644 --- a/amqp_envelope.h +++ b/amqp_envelope.h @@ -27,28 +27,6 @@ extern zend_class_entry *amqp_envelope_class_entry; void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelope TSRMLS_DC); -PHP_METHOD(amqp_envelope_class, __construct); -PHP_METHOD(amqp_envelope_class, getBody); -PHP_METHOD(amqp_envelope_class, getRoutingKey); -PHP_METHOD(amqp_envelope_class, getDeliveryTag); -PHP_METHOD(amqp_envelope_class, getDeliveryMode); -PHP_METHOD(amqp_envelope_class, getExchangeName); -PHP_METHOD(amqp_envelope_class, isRedelivery); -PHP_METHOD(amqp_envelope_class, getContentType); -PHP_METHOD(amqp_envelope_class, getContentEncoding); -PHP_METHOD(amqp_envelope_class, getType); -PHP_METHOD(amqp_envelope_class, getTimestamp); -PHP_METHOD(amqp_envelope_class, getPriority); -PHP_METHOD(amqp_envelope_class, getExpiration); -PHP_METHOD(amqp_envelope_class, getUserId); -PHP_METHOD(amqp_envelope_class, getAppId); -PHP_METHOD(amqp_envelope_class, getMessageId); -PHP_METHOD(amqp_envelope_class, getReplyTo); -PHP_METHOD(amqp_envelope_class, getCorrelationId); -PHP_METHOD(amqp_envelope_class, getHeaders); -PHP_METHOD(amqp_envelope_class, getHeader); -PHP_METHOD(amqp_envelope_class, hasHeader); - PHP_MINIT_FUNCTION(amqp_envelope); diff --git a/config.m4 b/config.m4 index a6f7a1f1..280a686a 100644 --- a/config.m4 +++ b/config.m4 @@ -125,7 +125,7 @@ if test "$PHP_AMQP" != "no"; then fi fi - AMQP_SOURCES="amqp.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c" + AMQP_SOURCES="amqp.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c" PHP_NEW_EXTENSION(amqp, $AMQP_SOURCES, $ext_shared) fi diff --git a/config.w32 b/config.w32 index a6b0f67d..734c2753 100644 --- a/config.w32 +++ b/config.w32 @@ -4,7 +4,7 @@ if (PHP_AMQP != "no") { if (CHECK_HEADER_ADD_INCLUDE("amqp.h", "CFLAGS_AMQP", PHP_PHP_BUILD + "\\include;" + PHP_AMQP) && CHECK_LIB("rabbinmq_a.lib;rabbitmq.lib;rabbitmq.1.lib", "amqp", PHP_PHP_BUILD + "\\lib;" + PHP_AMQP)) { // ADD_FLAG("CFLAGS_AMQP", "/D HAVE_AMQP_GETSOCKOPT"); - EXTENSION('amqp', 'amqp.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c'); + EXTENSION('amqp', 'amqp.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c'); AC_DEFINE('HAVE_AMQP', 1); } else { WARNING("amqp not enabled; libraries and headers not found"); diff --git a/php5_support.h b/php5_support.h index fbd2c5c2..4fef101f 100644 --- a/php5_support.h +++ b/php5_support.h @@ -101,6 +101,7 @@ typedef zend_rsrc_list_entry PHP5to7_zend_resource_le_t; #define PHP5to7_ZEND_RSRC_TYPE_P(le) Z_TYPE_P(le) #define PHP5to7_ZEND_REGISTER_RESOURCE(rsrc_pointer, rsrc_type) ZEND_REGISTER_RESOURCE(NULL, (rsrc_pointer), (rsrc_type)) +#define PHP5to7_PARENT_CLASS_NAME_C(name) , (name) #endif //PHP_AMQP_PHP5_SUPPORT_H diff --git a/php7_support.h b/php7_support.h index 5fb01511..02e8397e 100644 --- a/php7_support.h +++ b/php7_support.h @@ -94,6 +94,8 @@ typedef zval PHP5to7_zend_resource_le_t; #define PHP5to7_ZEND_RSRC_TYPE_P(le) (le)->type #define PHP5to7_ZEND_REGISTER_RESOURCE(rsrc_pointer, rsrc_type) zend_register_resource((rsrc_pointer), (rsrc_type)) +#define PHP5to7_PARENT_CLASS_NAME_C(name) + #endif //PHP_AMQP_PHP7_SUPPORT_H /* diff --git a/php_amqp.h b/php_amqp.h index 6bcd2ff6..1bf1f8a2 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -198,6 +198,7 @@ struct _amqp_connection_object { #define PHP_AMQP_READ_OBJ_PROP(cls, obj, name) zend_read_property((cls), (obj), ZEND_STRL(name), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC) #define PHP_AMQP_READ_OBJ_PROP_DOUBLE(cls, obj, name) Z_DVAL_P(PHP_AMQP_READ_OBJ_PROP((cls), (obj), (name))) +#define PHP_AMQP_READ_THIS_PROP_CE(name, ce) zend_read_property((ce), getThis(), ZEND_STRL(name), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC) #define PHP_AMQP_READ_THIS_PROP(name) zend_read_property(this_ce, getThis(), ZEND_STRL(name), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC) #define PHP_AMQP_READ_THIS_PROP_BOOL(name) Z_BVAL_P(PHP_AMQP_READ_THIS_PROP(name)) #define PHP_AMQP_READ_THIS_PROP_STR(name) Z_STRVAL_P(PHP_AMQP_READ_THIS_PROP(name)) diff --git a/stubs/AMQPBasicProperties.php b/stubs/AMQPBasicProperties.php new file mode 100644 index 00000000..947db8b9 --- /dev/null +++ b/stubs/AMQPBasicProperties.php @@ -0,0 +1,167 @@ +$m()); + } +} + function dump_message($msg) { if (!$msg) { var_dump($msg); diff --git a/tests/amqpbasicproperties.phpt b/tests/amqpbasicproperties.phpt new file mode 100644 index 00000000..dc3153a6 --- /dev/null +++ b/tests/amqpbasicproperties.phpt @@ -0,0 +1,163 @@ +--TEST-- +AMQPBasicProperties +--SKIPIF-- + +--FILE-- + 'headers'), + 42, + 24, + "correlation_id", + "reply_to", + "expiration", + "message_id", + 99999, + "type", + "user_id", + "app_id", + "cluster_id" +); +var_dump($props); +dump_methods($props); + + +?> +--EXPECT-- +object(AMQPBasicProperties)#1 (14) { + ["content_type":"AMQPBasicProperties":private]=> + string(0) "" + ["content_encoding":"AMQPBasicProperties":private]=> + string(0) "" + ["headers":"AMQPBasicProperties":private]=> + array(0) { + } + ["delivery_mode":"AMQPBasicProperties":private]=> + int(1) + ["priority":"AMQPBasicProperties":private]=> + int(0) + ["correlation_id":"AMQPBasicProperties":private]=> + string(0) "" + ["reply_to":"AMQPBasicProperties":private]=> + string(0) "" + ["expiration":"AMQPBasicProperties":private]=> + string(0) "" + ["message_id":"AMQPBasicProperties":private]=> + string(0) "" + ["timestamp":"AMQPBasicProperties":private]=> + int(0) + ["type":"AMQPBasicProperties":private]=> + string(0) "" + ["user_id":"AMQPBasicProperties":private]=> + string(0) "" + ["app_id":"AMQPBasicProperties":private]=> + string(0) "" + ["cluster_id":"AMQPBasicProperties":private]=> + string(0) "" +} +AMQPBasicProperties + getContentType(): + string(0) "" + getContentEncoding(): + string(0) "" + getHeaders(): + array(0) { +} + getDeliveryMode(): + int(1) + getPriority(): + int(0) + getCorrelationId(): + string(0) "" + getReplyTo(): + string(0) "" + getExpiration(): + string(0) "" + getMessageId(): + string(0) "" + getTimestamp(): + int(0) + getType(): + string(0) "" + getUserId(): + string(0) "" + getAppId(): + string(0) "" + getClusterId(): + string(0) "" + +object(AMQPBasicProperties)#2 (14) { + ["content_type":"AMQPBasicProperties":private]=> + string(12) "content_type" + ["content_encoding":"AMQPBasicProperties":private]=> + string(16) "content_encoding" + ["headers":"AMQPBasicProperties":private]=> + array(1) { + ["test"]=> + string(7) "headers" + } + ["delivery_mode":"AMQPBasicProperties":private]=> + int(42) + ["priority":"AMQPBasicProperties":private]=> + int(24) + ["correlation_id":"AMQPBasicProperties":private]=> + string(14) "correlation_id" + ["reply_to":"AMQPBasicProperties":private]=> + string(8) "reply_to" + ["expiration":"AMQPBasicProperties":private]=> + string(10) "expiration" + ["message_id":"AMQPBasicProperties":private]=> + string(10) "message_id" + ["timestamp":"AMQPBasicProperties":private]=> + int(99999) + ["type":"AMQPBasicProperties":private]=> + string(4) "type" + ["user_id":"AMQPBasicProperties":private]=> + string(7) "user_id" + ["app_id":"AMQPBasicProperties":private]=> + string(6) "app_id" + ["cluster_id":"AMQPBasicProperties":private]=> + string(10) "cluster_id" +} +AMQPBasicProperties + getContentType(): + string(12) "content_type" + getContentEncoding(): + string(16) "content_encoding" + getHeaders(): + array(1) { + ["test"]=> + string(7) "headers" +} + getDeliveryMode(): + int(42) + getPriority(): + int(24) + getCorrelationId(): + string(14) "correlation_id" + getReplyTo(): + string(8) "reply_to" + getExpiration(): + string(10) "expiration" + getMessageId(): + string(10) "message_id" + getTimestamp(): + int(99999) + getType(): + string(4) "type" + getUserId(): + string(7) "user_id" + getAppId(): + string(6) "app_id" + getClusterId(): + string(10) "cluster_id" diff --git a/tests/amqpenvelope_construct.phpt b/tests/amqpenvelope_construct.phpt index 4066f63f..d6743fdf 100644 --- a/tests/amqpenvelope_construct.phpt +++ b/tests/amqpenvelope_construct.phpt @@ -10,42 +10,44 @@ if (!extension_loaded("amqp") || version_compare(PHP_VERSION, '5.3', '<')) { var_dump(new AMQPEnvelope()); ?> --EXPECT-- -object(AMQPEnvelope)#1 (18) { - ["body":"AMQPEnvelope":private]=> - string(0) "" - ["delivery_tag":"AMQPEnvelope":private]=> - int(0) - ["is_redelivery":"AMQPEnvelope":private]=> - bool(false) - ["exchange_name":"AMQPEnvelope":private]=> - string(0) "" - ["routing_key":"AMQPEnvelope":private]=> +object(AMQPEnvelope)#1 (19) { + ["content_type":"AMQPBasicProperties":private]=> string(0) "" - ["content_type":"AMQPEnvelope":private]=> + ["content_encoding":"AMQPBasicProperties":private]=> string(0) "" - ["content_encoding":"AMQPEnvelope":private]=> - string(0) "" - ["headers":"AMQPEnvelope":private]=> + ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPEnvelope":private]=> + ["delivery_mode":"AMQPBasicProperties":private]=> int(1) - ["priority":"AMQPEnvelope":private]=> + ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPEnvelope":private]=> + ["correlation_id":"AMQPBasicProperties":private]=> string(0) "" - ["reply_to":"AMQPEnvelope":private]=> + ["reply_to":"AMQPBasicProperties":private]=> string(0) "" - ["expiration":"AMQPEnvelope":private]=> + ["expiration":"AMQPBasicProperties":private]=> string(0) "" - ["message_id":"AMQPEnvelope":private]=> + ["message_id":"AMQPBasicProperties":private]=> string(0) "" - ["timestamp":"AMQPEnvelope":private]=> + ["timestamp":"AMQPBasicProperties":private]=> int(0) - ["type":"AMQPEnvelope":private]=> + ["type":"AMQPBasicProperties":private]=> + string(0) "" + ["user_id":"AMQPBasicProperties":private]=> string(0) "" - ["user_id":"AMQPEnvelope":private]=> + ["app_id":"AMQPBasicProperties":private]=> string(0) "" - ["app_id":"AMQPEnvelope":private]=> + ["cluster_id":"AMQPBasicProperties":private]=> string(0) "" -} \ No newline at end of file + ["body":"AMQPEnvelope":private]=> + NULL + ["delivery_tag":"AMQPEnvelope":private]=> + NULL + ["is_redelivery":"AMQPEnvelope":private]=> + NULL + ["exchange_name":"AMQPEnvelope":private]=> + NULL + ["routing_key":"AMQPEnvelope":private]=> + NULL +} diff --git a/tests/amqpenvelope_get_accessors.phpt b/tests/amqpenvelope_get_accessors.phpt index 9a99a1c8..995da4da 100644 --- a/tests/amqpenvelope_get_accessors.phpt +++ b/tests/amqpenvelope_get_accessors.phpt @@ -25,6 +25,7 @@ $ex->publish('message', 'routing.1', AMQP_NOPARAM, array('headers' => array('foo // Read from the queue $msg = $q->get(); +var_dump($msg); dump_message($msg); $header = $msg->getHeader('foo'); @@ -35,6 +36,49 @@ var_dump($header); ?> --EXPECTF-- +object(AMQPEnvelope)#5 (19) { + ["content_type":"AMQPBasicProperties":private]=> + string(10) "text/plain" + ["content_encoding":"AMQPBasicProperties":private]=> + string(0) "" + ["headers":"AMQPBasicProperties":private]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["delivery_mode":"AMQPBasicProperties":private]=> + int(1) + ["priority":"AMQPBasicProperties":private]=> + int(0) + ["correlation_id":"AMQPBasicProperties":private]=> + string(0) "" + ["reply_to":"AMQPBasicProperties":private]=> + string(0) "" + ["expiration":"AMQPBasicProperties":private]=> + string(0) "" + ["message_id":"AMQPBasicProperties":private]=> + string(0) "" + ["timestamp":"AMQPBasicProperties":private]=> + int(0) + ["type":"AMQPBasicProperties":private]=> + string(0) "" + ["user_id":"AMQPBasicProperties":private]=> + string(0) "" + ["app_id":"AMQPBasicProperties":private]=> + string(0) "" + ["cluster_id":"AMQPBasicProperties":private]=> + string(0) "" + ["body":"AMQPEnvelope":private]=> + string(7) "message" + ["delivery_tag":"AMQPEnvelope":private]=> + int(1) + ["is_redelivery":"AMQPEnvelope":private]=> + bool(false) + ["exchange_name":"AMQPEnvelope":private]=> + string(%d) "exchange-%f" + ["routing_key":"AMQPEnvelope":private]=> + string(9) "routing.1" +} AMQPEnvelope getBody: string(7) "message" @@ -76,4 +120,4 @@ AMQPEnvelope string(3) "bar" } string(3) "bar" -string(3) "bar" \ No newline at end of file +string(3) "bar" diff --git a/tests/amqpenvelope_var_dump.phpt b/tests/amqpenvelope_var_dump.phpt index bb22fd67..2fcaade0 100644 --- a/tests/amqpenvelope_var_dump.phpt +++ b/tests/amqpenvelope_var_dump.phpt @@ -31,84 +31,88 @@ $ex->publish('message', 'routing.1', AMQP_NOPARAM, array("headers" => array("tes $q->consume("consumeThings"); $q->consume("consumeThings"); ?> ---EXPECTF-- -object(AMQPEnvelope)#5 (18) { - ["body":"AMQPEnvelope":private]=> - string(7) "message" - ["delivery_tag":"AMQPEnvelope":private]=> - int(1) - ["is_redelivery":"AMQPEnvelope":private]=> - bool(false) - ["exchange_name":"AMQPEnvelope":private]=> - string(9) "exchange1" - ["routing_key":"AMQPEnvelope":private]=> - string(9) "routing.1" - ["content_type":"AMQPEnvelope":private]=> +--EXPECT-- +object(AMQPEnvelope)#5 (19) { + ["content_type":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPEnvelope":private]=> + ["content_encoding":"AMQPBasicProperties":private]=> string(0) "" - ["headers":"AMQPEnvelope":private]=> + ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPEnvelope":private]=> + ["delivery_mode":"AMQPBasicProperties":private]=> int(1) - ["priority":"AMQPEnvelope":private]=> + ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPEnvelope":private]=> + ["correlation_id":"AMQPBasicProperties":private]=> string(0) "" - ["reply_to":"AMQPEnvelope":private]=> + ["reply_to":"AMQPBasicProperties":private]=> string(0) "" - ["expiration":"AMQPEnvelope":private]=> + ["expiration":"AMQPBasicProperties":private]=> string(0) "" - ["message_id":"AMQPEnvelope":private]=> + ["message_id":"AMQPBasicProperties":private]=> string(0) "" - ["timestamp":"AMQPEnvelope":private]=> + ["timestamp":"AMQPBasicProperties":private]=> int(0) - ["type":"AMQPEnvelope":private]=> + ["type":"AMQPBasicProperties":private]=> string(0) "" - ["user_id":"AMQPEnvelope":private]=> + ["user_id":"AMQPBasicProperties":private]=> string(0) "" - ["app_id":"AMQPEnvelope":private]=> + ["app_id":"AMQPBasicProperties":private]=> + string(0) "" + ["cluster_id":"AMQPBasicProperties":private]=> string(0) "" -} -object(AMQPEnvelope)#%d (18) { ["body":"AMQPEnvelope":private]=> string(7) "message" ["delivery_tag":"AMQPEnvelope":private]=> - int(2) + int(1) ["is_redelivery":"AMQPEnvelope":private]=> bool(false) ["exchange_name":"AMQPEnvelope":private]=> string(9) "exchange1" ["routing_key":"AMQPEnvelope":private]=> string(9) "routing.1" - ["content_type":"AMQPEnvelope":private]=> +} +object(AMQPEnvelope)#5 (19) { + ["content_type":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPEnvelope":private]=> + ["content_encoding":"AMQPBasicProperties":private]=> string(0) "" - ["headers":"AMQPEnvelope":private]=> + ["headers":"AMQPBasicProperties":private]=> array(1) { ["test"]=> string(6) "passed" } - ["delivery_mode":"AMQPEnvelope":private]=> + ["delivery_mode":"AMQPBasicProperties":private]=> int(1) - ["priority":"AMQPEnvelope":private]=> + ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPEnvelope":private]=> + ["correlation_id":"AMQPBasicProperties":private]=> string(0) "" - ["reply_to":"AMQPEnvelope":private]=> + ["reply_to":"AMQPBasicProperties":private]=> string(0) "" - ["expiration":"AMQPEnvelope":private]=> + ["expiration":"AMQPBasicProperties":private]=> string(0) "" - ["message_id":"AMQPEnvelope":private]=> + ["message_id":"AMQPBasicProperties":private]=> string(0) "" - ["timestamp":"AMQPEnvelope":private]=> + ["timestamp":"AMQPBasicProperties":private]=> int(0) - ["type":"AMQPEnvelope":private]=> + ["type":"AMQPBasicProperties":private]=> + string(0) "" + ["user_id":"AMQPBasicProperties":private]=> string(0) "" - ["user_id":"AMQPEnvelope":private]=> + ["app_id":"AMQPBasicProperties":private]=> string(0) "" - ["app_id":"AMQPEnvelope":private]=> + ["cluster_id":"AMQPBasicProperties":private]=> string(0) "" -} \ No newline at end of file + ["body":"AMQPEnvelope":private]=> + string(7) "message" + ["delivery_tag":"AMQPEnvelope":private]=> + int(2) + ["is_redelivery":"AMQPEnvelope":private]=> + bool(false) + ["exchange_name":"AMQPEnvelope":private]=> + string(9) "exchange1" + ["routing_key":"AMQPEnvelope":private]=> + string(9) "routing.1" +}