]> granicus.if.org Git - php/commitdiff
Changed ResourceBundle constructor behavior
authorGustavo André dos Santos Lopes <cataphract@php.net>
Thu, 24 May 2012 11:35:28 +0000 (13:35 +0200)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Thu, 24 May 2012 11:50:59 +0000 (13:50 +0200)
null is now accepted for two first (mandatory arguments).

Passing null as the package name causes NULL to be passed to ICU  and
the default ICU data to be loaded.

Passing null as the locale name causes the default locale to be used.

NEWS
UPGRADING
ext/intl/resourcebundle/resourcebundle_class.c
ext/intl/tests/resourcebundle_null_mandatory_args.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1db032ae311d4f9cb730b4c65ecd61abbc905f44..ac4eeb5934e90a5fce6c2553247d459791b5c387 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -62,6 +62,10 @@ PHP                                                                        NEWS
   . Fixed bug #61839 (Unable to cross-compile PHP with --enable-fpm). (fat)
   . Fixed bug #61026 (FPM pools can listen on the same address). (fat)
 
+- Intl
+  . ResourceBundle constructor now accepts NULL for the first two arguments.
+    (Gustavo)
+
 - Libxml:
   . Fixed bug #61617 (Libxml tests failed(ht is already destroyed)).
     (Laruence)
index 3a97b10cbf85a8f668d84d8392c07a3422db3192..15da46e7651bee9b79fdf320cb5b71f67565cf42 100755 (executable)
--- a/UPGRADING
+++ b/UPGRADING
@@ -341,6 +341,8 @@ PHP 5.4 UPGRADE NOTES
 
 - Since 5.4.4, "php://fd" stream syntax is available only in CLI build.
 
+- Since 5.4.5, resourcebundle_create() accepts null for the first two arguments.
+
 ==============================
 5. Changes to existing classes
 ==============================
@@ -373,6 +375,9 @@ PHP 5.4 UPGRADE NOTES
 - FilesystemIterator, GlobIterator and (Recursive)DirectoryIterator now use
   the default stream context.
 
+- Since 5.4.5, the constructor of ResourceBundle accepts NULL for the first two
+  arguments.
+
 ===========================
 7. Deprecated Functionality
 ===========================
index 5471e5b3f6a41b3a62c8237500a2ece1db5faefa..e3f8252b91f49bdaa5c788624e6a4e2ad12c8bb9 100644 (file)
@@ -91,7 +91,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
 
        intl_error_reset( NULL TSRMLS_CC );
 
-       if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", 
+       if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s!s!|b", 
                &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE )
        {
                intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
@@ -101,6 +101,10 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
        }
 
        INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
+       
+       if (locale == NULL) {
+               locale = intl_locale_get_default(TSRMLS_C);
+       }
 
        if (fallback) {
                rb->me = ures_open(bundlename, locale, &INTL_DATA_ERROR_CODE(rb));
@@ -110,13 +114,17 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
 
        INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle");
 
-       if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
-               intl_errors_set_code( NULL, INTL_DATA_ERROR_CODE(rb) TSRMLS_CC );
-               spprintf( &pbuf, 0, "resourcebundle_ctor: Cannot load libICU resource '%s' without fallback from %s to %s",
-                               bundlename, locale, ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb)) );
-               intl_errors_set_custom_msg( INTL_DATA_ERROR_P(rb), pbuf, 1 TSRMLS_CC );
+       if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING ||
+                       INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
+               intl_errors_set_code(NULL, INTL_DATA_ERROR_CODE(rb) TSRMLS_CC);
+               spprintf(&pbuf, 0, "resourcebundle_ctor: Cannot load libICU resource "
+                               "'%s' without fallback from %s to %s",
+                               bundlename ? bundlename : "(default data)", locale,
+                               ures_getLocaleByType(
+                                       rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb)));
+               intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1 TSRMLS_CC);
                efree(pbuf);
-               zval_dtor( return_value );
+               zval_dtor(return_value);
                RETURN_NULL();
        }
 }
diff --git a/ext/intl/tests/resourcebundle_null_mandatory_args.phpt b/ext/intl/tests/resourcebundle_null_mandatory_args.phpt
new file mode 100644 (file)
index 0000000..8fde61b
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+IntlCalendar::setTime() basic test
+--INI--
+date.timezone=Atlantic/Azores
+--SKIPIF--
+<?php
+if (!extension_loaded('intl'))
+       die('skip intl extension not enabled');
+--FILE--
+<?php
+ini_set("intl.error_level", E_WARNING);
+
+$r = new ResourceBundle('en_US', NULL);
+$c = $r->get('calendar')->get('gregorian')->get('DateTimePatterns')->get(0);
+var_dump($c);
+
+ini_set('intl.default_locale', 'pt_PT');
+$r = new ResourceBundle(NULL, NULL);
+$c = $r->get('calendar')->get('gregorian')->get('DateTimePatterns')->get(0);
+var_dump($c);
+?>
+==DONE==
+--EXPECT--
+string(14) "h:mm:ss a zzzz"
+string(12) "H:mm:ss zzzz"
+==DONE==