Skip to content

Commit 3f75452

Browse files
BogdanUngureanudevnexen
authored andcommitted
Intl: Add IntlListFormatter class
Allows to format a list of item with - TYPE_AND/TYPE_OR/TYPE_UNITS operands. - WIDTH_WIDE, WIDTH_SHORT, WIDTH_NARROW. close GH-18519
1 parent 06738fc commit 3f75452

14 files changed

+706
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ PHP NEWS
9696
. Added grapheme_levenshtein() function. (Yuya Hamada)
9797
. Added Locale::addLikelySubtags/Locale::minimizeSubtags to handle
9898
adding/removing likely subtags to a locale. (David Carlier)
99+
. Added IntlListFormatter class to format a list of items with a locale
100+
, operands types and units. (BogdanUngureanu)
99101

100102
- MySQLi:
101103
. Fixed bugs GH-17900 and GH-8084 (calling mysqli::__construct twice).

UPGRADING

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ PHP 8.5 UPGRADE NOTES
180180
number formats.
181181
. Added Locale::addLikelySubtags and Locale::minimizeSubtags to
182182
handle likely tags on a given locale.
183+
. Added IntlListFormatter class to format, order, punctuates
184+
a list of items with a given locale, AND/OR and UNIT operands.
185+
It is supported from icu 67.
183186

184187
- XSL:
185188
. The $namespace argument of XSLTProcessor::getParameter(),
@@ -415,6 +418,12 @@ PHP 8.5 UPGRADE NOTES
415418
- Intl:
416419
. DECIMAL_COMPACT_SHORT.
417420
. DECIMAL_COMPACT_LONG.
421+
. TYPE_AND.
422+
. TYPE_OR.
423+
. TYPE_UNITS.
424+
. WIDTH_WIDE.
425+
. WIDTH_SHORT.
426+
. WIDTH_NARROW.
418427

419428
- POSIX:
420429
. POSIX_SC_OPEN_MAX.

ext/intl/config.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if test "$PHP_INTL" != "no"; then
3939
locale/locale_class.c
4040
locale/locale_methods.c
4141
locale/locale.c
42+
listformatter/listformatter_class.c
4243
msgformat/msgformat_attr.c
4344
msgformat/msgformat_class.c
4445
msgformat/msgformat_data.c
@@ -119,6 +120,7 @@ if test "$PHP_INTL" != "no"; then
119120
$ext_builddir/grapheme
120121
$ext_builddir/idn
121122
$ext_builddir/locale
123+
$ext_builddir/listformatter
122124
$ext_builddir/msgformat
123125
$ext_builddir/normalizer
124126
$ext_builddir/resourcebundle

ext/intl/config.w32

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ if (PHP_INTL != "no") {
3939
formatter_main.c \
4040
formatter_parse.c \
4141
", "intl");
42+
ADD_SOURCES(configure_module_dirname + "/listformatter", "\
43+
listformatter_class.c \
44+
", "intl");
4245
ADD_SOURCES(configure_module_dirname + "/locale", "\
4346
locale.c \
4447
locale_class.c \
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/** @generate-class-entries */
4+
5+
/**
6+
* @not-serializable
7+
* @strict-properties
8+
*/
9+
final class IntlListFormatter {
10+
11+
/** @cvalue ULISTFMT_TYPE_AND */
12+
public const int TYPE_AND = UNKNOWN;
13+
14+
#if U_ICU_VERSION_MAJOR_NUM >= 67
15+
/** @cvalue ULISTFMT_TYPE_OR */
16+
public const int TYPE_OR = UNKNOWN;
17+
18+
/** @cvalue ULISTFMT_TYPE_UNITS */
19+
public const int TYPE_UNITS = UNKNOWN;
20+
#endif
21+
22+
/** @cvalue ULISTFMT_WIDTH_WIDE */
23+
public const int WIDTH_WIDE = UNKNOWN;
24+
25+
#if U_ICU_VERSION_MAJOR_NUM >= 67
26+
/** @cvalue ULISTFMT_WIDTH_SHORT */
27+
public const int WIDTH_SHORT = UNKNOWN;
28+
29+
/** @cvalue ULISTFMT_WIDTH_NARROW */
30+
public const int WIDTH_NARROW = UNKNOWN;
31+
#endif
32+
33+
public function __construct(string $locale, int $type = IntlListFormatter::TYPE_AND, int $width = IntlListFormatter::WIDTH_WIDE) {}
34+
35+
public function format(array $strings): string|false {}
36+
37+
public function getErrorCode(): int {}
38+
39+
public function getErrorMessage(): string {}
40+
}

ext/intl/listformatter/listformatter_arginfo.h

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)