From 99dae96dc0041f856ae066b3f572495da609d28e Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 15 Mar 2015 13:59:48 +0000 Subject: Converted intl extension to use IntlException in constructors. --- ext/intl/intl_error.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'ext/intl/intl_error.c') diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c index 28a2a244e2..8ea5e7b4cf 100644 --- a/ext/intl/intl_error.c +++ b/ext/intl/intl_error.c @@ -29,7 +29,7 @@ ZEND_EXTERN_MODULE_GLOBALS( intl ) -static zend_class_entry *IntlException_ce_ptr; +zend_class_entry *IntlException_ce_ptr; /* {{{ intl_error* intl_g_error_get() * Return global error structure. @@ -102,15 +102,26 @@ void intl_error_reset( intl_error* err ) * Set last error message to msg copying it if needed. */ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ) +{ + intl_error_set_custom_msg_ex( err, msg, copyMsg, 0 ); +} +/* }}} */ + + +/* {{{ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ) + * Set last error message to msg copying it if needed. + */ +void intl_error_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ) { if( !msg ) return; if( !err ) { - if( INTL_G( error_level ) ) - php_error_docref( NULL, INTL_G( error_level ), "%s", msg ); - if( INTL_G( use_exceptions ) ) + if ( forceException || INTL_G( use_exceptions ) ) { zend_throw_exception_ex( IntlException_ce_ptr, 0, "%s", msg ); + } else if( INTL_G( error_level ) ) { + php_error_docref( NULL, INTL_G( error_level ), "%s", msg ); + } } if( !err && !( err = intl_g_error_get( ) ) ) return; @@ -181,19 +192,39 @@ UErrorCode intl_error_get_code( intl_error* err ) * Set error code and message. */ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) +{ + intl_error_set_ex( err, code, msg, copyMsg, 0 ); +} +/* }}} */ + + +/* {{{ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) + * Set error code and message. + */ +void intl_error_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ) { intl_error_set_code( err, code ); - intl_error_set_custom_msg( err, msg, copyMsg ); + intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); } /* }}} */ + /* {{{ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) * Set error code and message. */ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) +{ + intl_errors_set_ex( err, code, msg, copyMsg, 0 ); +} +/* }}} */ + +/* {{{ void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg ) + * Set error code and message. + */ +void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ) { intl_errors_set_code( err, code ); - intl_errors_set_custom_msg( err, msg, copyMsg ); + intl_errors_set_custom_msg_ex( err, msg, copyMsg, forceException ); } /* }}} */ @@ -211,14 +242,24 @@ void intl_errors_reset( intl_error* err ) /* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) */ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) +{ + intl_errors_set_custom_msg_ex( err, msg, copyMsg, 0 ); +} +/* }}} */ + + +/* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) + */ +void intl_errors_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ) { if(err) { - intl_error_set_custom_msg( err, msg, copyMsg ); + intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); } - intl_error_set_custom_msg( NULL, msg, copyMsg ); + intl_error_set_custom_msg_ex( NULL, msg, copyMsg, forceException ); } /* }}} */ + /* {{{ intl_errors_set_code( intl_error* err, UErrorCode err_code ) */ void intl_errors_set_code( intl_error* err, UErrorCode err_code ) -- cgit v1.2.1