#include <unicode/unum.h>
#include "msgformat_class.h"
#include "php_intl.h"
#include "msgformat_data.h"
#include "msgformat_format.h"
#include "msgformat_parse.h"
#include "msgformat.h"
#include "msgformat_attr.h"
#include <zend_exceptions.h>
zend_class_entry *MessageFormatter_ce_ptr = NULL;
static zend_object_handlers MessageFormatter_handlers;
void MessageFormatter_object_free( zend_object *object )
{
MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object);
zend_object_std_dtor( &mfo->zo );
msgformat_data_free( &mfo->mf_data );
}
zend_object *MessageFormatter_object_create(zend_class_entry *ce)
{
MessageFormatter_object* intern;
intern = zend_object_alloc(sizeof(MessageFormatter_object), ce);
msgformat_data_init( &intern->mf_data );
zend_object_std_init( &intern->zo, ce );
object_properties_init(&intern->zo, ce);
intern->zo.handlers = &MessageFormatter_handlers;
return &intern->zo;
}
zend_object *MessageFormatter_object_clone(zval *object)
{
MessageFormatter_object *mfo, *new_mfo;
zend_object *new_obj;
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
new_obj = MessageFormatter_ce_ptr->create_object(Z_OBJCE_P(object));
new_mfo = php_intl_messageformatter_fetch_object(new_obj);
zend_objects_clone_members(&new_mfo->zo, &mfo->zo);
if (MSG_FORMAT_OBJECT(mfo) != NULL) {
MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo),
&INTL_DATA_ERROR_CODE(mfo));
if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo),
"Failed to clone MessageFormatter object", 0);
zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object");
}
} else {
zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter");
}
return new_obj;
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter___construct, 0, 0, 2)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_messageformatter_geterrormessage, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_formatmessage, 0, 0, 3)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_format, 0, 0, 1)
ZEND_ARG_INFO(0, args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_setpattern, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_parse, 0, 0, 1)
ZEND_ARG_INFO(0, source)
ZEND_END_ARG_INFO()
static const zend_function_entry MessageFormatter_class_functions[] = {
PHP_ME( MessageFormatter, __construct, arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
ZEND_FENTRY( create, ZEND_FN( msgfmt_create ), arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( format, ZEND_FN( msgfmt_format ), arginfo_messageformatter_format )
ZEND_FENTRY( formatMessage, ZEND_FN( msgfmt_format_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( parse, ZEND_FN( msgfmt_parse ), arginfo_messageformatter_parse )
ZEND_FENTRY( parseMessage, ZEND_FN( msgfmt_parse_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( setPattern, ZEND_FN( msgfmt_set_pattern ), arginfo_messageformatter_setpattern )
PHP_NAMED_FE( getPattern, ZEND_FN( msgfmt_get_pattern ), arginfo_messageformatter_geterrormessage )
PHP_NAMED_FE( getLocale, ZEND_FN( msgfmt_get_locale ), arginfo_messageformatter_geterrormessage )
PHP_NAMED_FE( getErrorCode, ZEND_FN( msgfmt_get_error_code ), arginfo_messageformatter_geterrormessage )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( msgfmt_get_error_message ), arginfo_messageformatter_geterrormessage )
PHP_FE_END
};
void msgformat_register_class( void )
{
zend_class_entry ce;
INIT_CLASS_ENTRY( ce, "MessageFormatter", MessageFormatter_class_functions );
ce.create_object = MessageFormatter_object_create;
MessageFormatter_ce_ptr = zend_register_internal_class( &ce );
memcpy(&MessageFormatter_handlers, &std_object_handlers,
sizeof MessageFormatter_handlers);
MessageFormatter_handlers.offset = XtOffsetOf(MessageFormatter_object, zo);
MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone;
MessageFormatter_handlers.free_obj = MessageFormatter_object_free;
}