/* {{{ clone handler for Transliterator */ static zend_object *Transliterator_clone_obj( zval *object ) { Transliterator_object *to_orig, *to_new; zend_object *ret_val; intl_error_reset( NULL ); to_orig = Z_INTL_TRANSLITERATOR_P( object ); intl_error_reset( INTL_DATA_ERROR_P( to_orig ) ); ret_val = Transliterator_ce_ptr->create_object( Z_OBJCE_P( object ) ); to_new = php_intl_transliterator_fetch_object( ret_val ); zend_objects_clone_members( &to_new->zo, &to_orig->zo ); if( to_orig->utrans != NULL ) { zval tempz; /* dummy zval to pass to transliterator_object_construct */ /* guaranteed to return NULL if it fails */ UTransliterator *utrans = utrans_clone( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to_orig ) ); if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to_orig ) ) ) goto err; ZVAL_OBJ(&tempz, ret_val); transliterator_object_construct( &tempz, utrans, TRANSLITERATOR_ERROR_CODE_P( to_orig ) ); if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to_orig ) ) ) { zend_string *err_msg; err: if( utrans != NULL ) transliterator_object_destroy( to_new ); /* set the error anyway, in case in the future we decide not to * throw an error. It also helps build the error message */ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( to_orig ) ); intl_errors_set_custom_msg( TRANSLITERATOR_ERROR_P( to_orig ), "Could not clone transliterator", 0 ); err_msg = intl_error_get_message( TRANSLITERATOR_ERROR_P( to_orig ) ); zend_throw_error( NULL, "%s", ZSTR_VAL(err_msg) ); zend_string_free( err_msg ); /* if it's changed into a warning */ /* do not destroy tempz; we need to return something */ } } else { /* We shouldn't have unconstructed objects in the first place */ php_error_docref( NULL, E_WARNING, "Cloning unconstructed transliterator." ); } return ret_val; }
U_CFUNC PHP_FUNCTION(intlcal_get_error_message) { zend_string* message = NULL; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, Calendar_ce_ptr) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_error_message: bad arguments", 0 TSRMLS_CC ); RETURN_FALSE; } /* Fetch the object (without resetting its last error code ). */ co = Z_INTL_CALENDAR_P(object); if (co == NULL) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message(CALENDAR_ERROR_P(co) TSRMLS_CC); RETURN_STR(message); }
/* {{{ clone handler for TimeZone */ static zend_object *TimeZone_clone_obj(zval *object) { TimeZone_object *to_orig, *to_new; zend_object *ret_val; intl_error_reset(NULL); to_orig = Z_INTL_TIMEZONE_P(object); intl_error_reset(TIMEZONE_ERROR_P(to_orig)); ret_val = TimeZone_ce_ptr->create_object(Z_OBJCE_P(object)); to_new = php_intl_timezone_fetch_object(ret_val); zend_objects_clone_members(&to_new->zo, &to_orig->zo); if (to_orig->utimezone != NULL) { TimeZone *newTimeZone; newTimeZone = to_orig->utimezone->clone(); to_new->should_delete = 1; if (!newTimeZone) { zend_string *err_msg; intl_errors_set_code(TIMEZONE_ERROR_P(to_orig), U_MEMORY_ALLOCATION_ERROR); intl_errors_set_custom_msg(TIMEZONE_ERROR_P(to_orig), "Could not clone IntlTimeZone", 0); err_msg = intl_error_get_message(TIMEZONE_ERROR_P(to_orig)); zend_throw_exception(NULL, err_msg->val, 0); zend_string_free(err_msg); } else { to_new->utimezone = newTimeZone; } } else { zend_throw_exception(NULL, "Cannot clone unconstructed IntlTimeZone", 0); } return ret_val; }
/* {{{ clone handler for Calendar */ static zend_object *Calendar_clone_obj(zval *object) { Calendar_object *co_orig, *co_new; zend_object *ret_val; intl_error_reset(NULL); co_orig = Z_INTL_CALENDAR_P(object); intl_error_reset(INTL_DATA_ERROR_P(co_orig)); ret_val = Calendar_ce_ptr->create_object(Z_OBJCE_P(object)); co_new = php_intl_calendar_fetch_object(ret_val); zend_objects_clone_members(&co_new->zo, &co_orig->zo); if (co_orig->ucal != NULL) { Calendar *newCalendar; newCalendar = co_orig->ucal->clone(); if (!newCalendar) { zend_string *err_msg; intl_errors_set_code(CALENDAR_ERROR_P(co_orig), U_MEMORY_ALLOCATION_ERROR); intl_errors_set_custom_msg(CALENDAR_ERROR_P(co_orig), "Could not clone IntlCalendar", 0); err_msg = intl_error_get_message(CALENDAR_ERROR_P(co_orig)); zend_throw_exception(NULL, err_msg->val, 0); zend_string_free(err_msg); } else { co_new->ucal = newCalendar; } } else { zend_throw_exception(NULL, "Cannot clone unconstructed IntlCalendar", 0); } return ret_val; }