Commit:    92039fed22cd68405589cf6df3af58b9beaddb16
Author:    Gustavo André dos Santos Lopes <cataphr...@php.net>         Thu, 24 
May 2012 13:35:28 +0200
Parents:   0e12a778df388c85bb8aeb41e8c33a983dd182f1
Branches:  PHP-5.4 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=92039fed22cd68405589cf6df3af58b9beaddb16

Log:
Changed ResourceBundle constructor behavior

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.

Changed paths:
  M  NEWS
  M  UPGRADING
  M  ext/intl/resourcebundle/resourcebundle_class.c
  A  ext/intl/tests/resourcebundle_null_mandatory_args.phpt


Diff:
diff --git a/NEWS b/NEWS
index 1db032a..ac4eeb5 100644
--- 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)
diff --git a/UPGRADING b/UPGRADING
index 3a97b10..15da46e 100755
--- 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
 ===========================
diff --git a/ext/intl/resourcebundle/resourcebundle_class.c 
b/ext/intl/resourcebundle/resourcebundle_class.c
index 5471e5b..e3f8252 100644
--- a/ext/intl/resourcebundle/resourcebundle_class.c
+++ b/ext/intl/resourcebundle/resourcebundle_class.c
@@ -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
index 0000000..8fde61b
--- /dev/null
+++ b/ext/intl/tests/resourcebundle_null_mandatory_args.phpt
@@ -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==


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to