cataphract Sun, 08 Jan 2012 18:41:53 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=321936
Log:
- Added the ability for the intl exception to throw exceptions when a global
error is set.
Changed paths:
U php/php-src/trunk/ext/intl/intl_error.c
U php/php-src/trunk/ext/intl/intl_error.h
U php/php-src/trunk/ext/intl/php_intl.c
U php/php-src/trunk/ext/intl/php_intl.h
A php/php-src/trunk/ext/intl/tests/ini_use_exceptions_basic.phpt
Modified: php/php-src/trunk/ext/intl/intl_error.c
===================================================================
--- php/php-src/trunk/ext/intl/intl_error.c 2012-01-08 18:22:50 UTC (rev
321935)
+++ php/php-src/trunk/ext/intl/intl_error.c 2012-01-08 18:41:53 UTC (rev
321936)
@@ -21,12 +21,15 @@
#endif
#include <php.h>
+#include <zend_exceptions.h>
#include "php_intl.h"
#include "intl_error.h"
ZEND_EXTERN_MODULE_GLOBALS( intl )
+static zend_class_entry *IntlException_ce_ptr;
+
/* {{{ intl_error* intl_g_error_get()
* Return global error structure.
*/
@@ -102,8 +105,11 @@
if( !msg )
return;
- if(!err && INTL_G(error_level)) {
- php_error_docref(NULL TSRMLS_CC, INTL_G(error_level), "%s",
msg);
+ if( !err ) {
+ if( INTL_G( error_level ) )
+ php_error_docref( NULL TSRMLS_CC, INTL_G( error_level
), "%s", msg );
+ if( INTL_G( use_exceptions ) )
+ zend_throw_exception_ex( IntlException_ce_ptr, 0
TSRMLS_CC, "%s", msg );
}
if( !err && !( err = intl_g_error_get( TSRMLS_C ) ) )
return;
@@ -223,6 +229,21 @@
}
/* }}} */
+void intl_register_IntlException_class( TSRMLS_D )
+{
+ zend_class_entry ce,
+ *default_exception_ce;
+
+ default_exception_ce = zend_exception_get_default( TSRMLS_C );
+
+ /* Create and register 'IntlException' class. */
+ INIT_CLASS_ENTRY_EX( ce, "IntlException", sizeof( "IntlException" ) -
1, NULL );
+ IntlException_ce_ptr = zend_register_internal_class_ex( &ce,
+ default_exception_ce, NULL TSRMLS_CC );
+ IntlException_ce_ptr->create_object =
default_exception_ce->create_object;
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4
Modified: php/php-src/trunk/ext/intl/intl_error.h
===================================================================
--- php/php-src/trunk/ext/intl/intl_error.h 2012-01-08 18:22:50 UTC (rev
321935)
+++ php/php-src/trunk/ext/intl/intl_error.h 2012-01-08 18:41:53 UTC (rev
321936)
@@ -44,4 +44,7 @@
void intl_errors_set_code( intl_error* err, UErrorCode err_code
TSRMLS_DC );
void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int
copyMsg TSRMLS_DC );
+// exported to be called on extension MINIT
+void intl_register_IntlException_class( TSRMLS_D );
+
#endif // INTL_ERROR_H
Modified: php/php-src/trunk/ext/intl/php_intl.c
===================================================================
--- php/php-src/trunk/ext/intl/php_intl.c 2012-01-08 18:22:50 UTC (rev
321935)
+++ php/php-src/trunk/ext/intl/php_intl.c 2012-01-08 18:41:53 UTC (rev
321936)
@@ -545,7 +545,7 @@
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY(LOCALE_INI_NAME, NULL, PHP_INI_ALL,
OnUpdateStringUnempty, default_locale, zend_intl_globals, intl_globals)
STD_PHP_INI_ENTRY("intl.error_level", "0", PHP_INI_ALL, OnUpdateLong,
error_level, zend_intl_globals, intl_globals)
-
+ STD_PHP_INI_ENTRY("intl.use_exceptions", "0", PHP_INI_ALL,
OnUpdateBool, use_exceptions, zend_intl_globals, intl_globals)
PHP_INI_END()
/* }}} */
@@ -653,6 +653,10 @@
/* Expose Spoofchecker constants to PHP scripts */
spoofchecker_register_constants( INIT_FUNC_ARGS_PASSTHRU );
#endif
+
+ /* Register 'IntlException' PHP class */
+ intl_register_IntlException_class( TSRMLS_C );
+
/* Global error handling. */
intl_error_init( NULL TSRMLS_CC );
Modified: php/php-src/trunk/ext/intl/php_intl.h
===================================================================
--- php/php-src/trunk/ext/intl/php_intl.h 2012-01-08 18:22:50 UTC (rev
321935)
+++ php/php-src/trunk/ext/intl/php_intl.h 2012-01-08 18:41:53 UTC (rev
321936)
@@ -46,6 +46,7 @@
UBreakIterator* grapheme_iterator;
intl_error g_error;
long error_level;
+ zend_bool use_exceptions;
ZEND_END_MODULE_GLOBALS(intl)
/* Macro to access request-wide global variables. */
Added: php/php-src/trunk/ext/intl/tests/ini_use_exceptions_basic.phpt
===================================================================
--- php/php-src/trunk/ext/intl/tests/ini_use_exceptions_basic.phpt
(rev 0)
+++ php/php-src/trunk/ext/intl/tests/ini_use_exceptions_basic.phpt
2012-01-08 18:41:53 UTC (rev 321936)
@@ -0,0 +1,21 @@
+--TEST--
+intl.use_exceptions INI setting
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+ini_set("intl.use_exceptions", true);
+$t = transliterator_create('any-hex');
+try {
+ var_dump($t->transliterate('a', 3));
+} catch (IntlException $intlE) {
+ var_dump($intlE->getMessage());
+}
+ini_set("intl.use_exceptions", false);
+ini_set("intl.error_level", E_NOTICE);
+var_dump($t->transliterate('a', 3));
+--EXPECTF--
+string(130) "transliterator_transliterate: Neither "start" nor the "end"
arguments can exceed the number of UTF-16 code units (in this case, 1)"
+
+Notice: Transliterator::transliterate(): transliterator_transliterate: Neither
"start" nor the "end" arguments can exceed the number of UTF-16 code units (in
this case, 1) in %s on line %d
+bool(false)
\ No newline at end of file
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php