Skip to content

[Intl] Add format_list filter using PHP 8.5's IntlListFormatter#4852

Merged
fabpot merged 1 commit into
twigphp:3.xfrom
BreyndotEchse:feature/intl-php8.5-format-list-filter
Jul 8, 2026
Merged

[Intl] Add format_list filter using PHP 8.5's IntlListFormatter#4852
fabpot merged 1 commit into
twigphp:3.xfrom
BreyndotEchse:feature/intl-php8.5-format-list-filter

Conversation

@BreyndotEchse

Copy link
Copy Markdown
Contributor

Adds a new format_list Twig filter to IntlExtension that formats arrays using using PHP 8.5's IntlListFormatter

On PHP < 8.5, using the filter throws a RuntimeError explaining the dependency on IntlListFormatter (Checks if class_exists to allow polyfills).

CI workflow only covered up to PHP 8.4, so I extended it to also run PHPUnit against 8.5.
phpstan's PHP version also bumped to 8.5.

Comment thread extra/intl-extra/IntlExtension.php Outdated
@BreyndotEchse BreyndotEchse requested a review from stof July 1, 2026 17:40

@fabpot fabpot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me.

Can you add a new doc/filters/format_list.rst file (see doc/filters/format_number.rst for an example), update doc/filters/index.rst to add format_list to the list and in extra/intl-extra/README.md?

Also, can you add an entry in CHANGELOG.md?

@BreyndotEchse BreyndotEchse force-pushed the feature/intl-php8.5-format-list-filter branch from 049faf5 to 79b2526 Compare July 6, 2026 10:44
@BreyndotEchse

Copy link
Copy Markdown
Contributor Author
  • rebased on latest 3.x
  • added docs
  • added CHANGELOG

@BreyndotEchse BreyndotEchse requested a review from fabpot July 6, 2026 10:50
@BreyndotEchse BreyndotEchse force-pushed the feature/intl-php8.5-format-list-filter branch from fc7e311 to 3fc0321 Compare July 7, 2026 07:19
Comment thread doc/filters/format_list.rst Outdated
Comment thread extra/intl-extra/README.md Outdated
Comment thread extra/intl-extra/README.md Outdated
Comment thread extra/intl-extra/README.md Outdated
Comment thread doc/filters/format_list.rst
Comment thread doc/filters/format_list.rst Outdated
@BreyndotEchse BreyndotEchse requested a review from fabpot July 8, 2026 20:10
@fabpot fabpot force-pushed the feature/intl-php8.5-format-list-filter branch from c6dc017 to 163f1b6 Compare July 8, 2026 20:22
@fabpot

fabpot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Thank you @BreyndotEchse.

@fabpot fabpot merged commit 5bcd992 into twigphp:3.x Jul 8, 2026
1 check passed
@upsun-dispatch

upsun-dispatch Bot commented Jul 8, 2026

Copy link
Copy Markdown

📋 PR Summary

This PR adds a format_list Twig filter to the IntlExtension that formats an array of strings into a locale-aware list using PHP 8.5's IntlListFormatter. On PHP < 8.5 the filter throws a RuntimeError (guarded by class_exists, allowing polyfills), and the CI matrix plus phpstan are bumped to include PHP 8.5. Documentation, README, CHANGELOG, and two test fixtures (pre-8.5 exception path and 8.5 formatting path) are added.

Changes
Layer / File(s) Summary
filter implementation
extra/intl-extra/IntlExtension.php Adds formatList public filter method, createListFormatter with LRU-style caching, and lazy availableListTypes/availableListWidths helpers mapping string names to IntlListFormatter constants. Registers the format_list filter.
ci
.github/workflows/ci.yml Adds PHP 8.5 to the test matrices and bumps the phpstan job's PHP version from 8.4 to 8.5.
docs
doc/filters/format_list.rst New reference page documenting the filter, its type/width/locale arguments, and examples.
doc/filters/index.rst Adds format_list to the filters index.
extra/intl-extra/README.md Lists the new format_list filter with a link.
CHANGELOG Adds a 3.29.0 entry for the new filter.
tests
extra/intl-extra/Tests/Fixtures/format_list.test Fixture asserting the RuntimeError is thrown on PHP < 8.5.
extra/intl-extra/Tests/Fixtures/format_list_php85.test Fixture asserting formatted output across type/width/locale combinations on PHP >= 8.5.

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: full · 8 files reviewed · 🔵 2 infos

Review details

Commit: Commit 163f1b6
Model: claude-opus-4-8
Panel: correctness · robustness · design

throw new RuntimeError('The "format_list" filter requires the "IntlListFormatter" class, which is available since PHP 8.5.');
}

return $this->createListFormatter($locale, $type, $width)->format($strings);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Info — Docblock may overpromise Stringable support the formatter does not accept.

The @param array<string|\Stringable> annotation on formatList advertises that \Stringable objects may be passed, but $strings is handed directly to \IntlListFormatter::format(). If the underlying formatter does not coerce \Stringable elements to strings, passing objects (which the annotation permits) raises a TypeError rather than formatting them. The test fixtures only cover plain strings, so this path is unverified.

}

$types = [
'and' => \IntlListFormatter::TYPE_AND,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Info — Undocumented lazy pattern invites a refactor that breaks the extension on PHP < 8.5.

availableListTypes()/availableListWidths() reference the PHP 8.5-only constants \IntlListFormatter::TYPE_AND/WIDTH_WIDE etc., and are intentionally lazy methods (evaluated only after the class_exists guard in formatList) rather than const arrays like the sibling TIME_FORMATS/NUMBER_STYLES. Nothing documents that intent, so a maintainer harmonizing them into class constants would move constant evaluation to class-load time and break loading on PHP < 8.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants