Modernize array utilities and JSON validation using PHP 8.4+ functions with polyfills#7523
Conversation
Replaced custom JSON validation logic with direct calls to json_validate in Str and ValidatesAttributes. Updated composer.json files to require symfony/polyfill-php83, php84, and php85 for improved PHP compatibility. Refactored array utility usage in Arr and Collection for consistency and performance.
Replaces array_key_exists with isset in the has and hasAny methods for improved performance and to ensure only non-null keys are considered present.
Simplifies the Arr::first method by delegating to array_first directly. Also corrects the locale string in CollectionTest from 'en_US.utf8' to 'en_US.UTF-8' for consistency.
cec432f to
46a1de3
Compare
# Conflicts: # CHANGELOG-3.2.md # src/collection/tests/ArrTest.php # src/collection/tests/CollectionTest.php
There was a problem hiding this comment.
Pull request overview
This PR updates multiple components to rely on newer PHP built-in array/JSON helper functions and introduces Symfony polyfills so those functions are available on supported runtimes (PHP >= 8.2) without local fallback implementations.
Changes:
- Replace manual JSON validation fallbacks with
json_validate()in validation and string utilities. - Modernize collection/array helpers to use
array_*built-ins (with new Arr helpers and accompanying tests). - Add Symfony polyfill dependencies and adjust CI workflow and changelog entries accordingly.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| run: | | ||
| composer remove friendsofphp/php-cs-fixer --dev --no-update | ||
| # symfony/* | ||
| for package in `cat composer.json|grep "symfony/"| awk -F '"' '{print $2}'`; do composer require "${package}:${{ matrix.symfony-version }}" --dev --no-update; done |
There was a problem hiding this comment.
The # symfony/* loop greps all symfony/ packages from composer.json, which now includes symfony/polyfill-php*. That will attempt composer require symfony/polyfill-php83:^6.0|^7.0 and fail before the later polyfill loop runs. Filter polyfills out of the first loop (e.g., grep '"symfony/"' | grep -v 'symfony/polyfill-php') or build the package list in a way that excludes polyfills.
| for package in `cat composer.json|grep "symfony/"| awk -F '"' '{print $2}'`; do composer require "${package}:${{ matrix.symfony-version }}" --dev --no-update; done | |
| for package in `cat composer.json|grep "symfony/"|grep -v "symfony/polyfill-php"| awk -F '"' '{print $2}'`; do composer require "${package}:${{ matrix.symfony-version }}" --dev --no-update; done |
| // ensure the locale set successfully. | ||
| $this->assertTrue(in_array($locale, $localeArray)); | ||
|
|
||
| setlocale(LC_COLLATE, 'en_US.UTF-8'); |
There was a problem hiding this comment.
setlocale(LC_COLLATE, ...$localeArray) already selects an available locale variant and the test asserts it succeeded. Immediately forcing setlocale(LC_COLLATE, 'en_US.UTF-8') can fail on systems where only en_US.utf8 is installed, potentially breaking subsequent SORT_LOCALE_STRING expectations. Use the $locale returned from the first call (or conditionally set to the available value) instead of hard-coding a specific variant.
| setlocale(LC_COLLATE, 'en_US.UTF-8'); | |
| setlocale(LC_COLLATE, $locale); |
| - [#7615](https://github.com/hyperf/hyperf/pull/7615) Renamed `$queue` property to `$pool` in `ConsumerProcess` for async-queue component. | ||
| - [#7625](https://github.com/hyperf/hyperf/pull/7625) Renamed `getQueueName()` to `getPoolName()` in async-queue component for terminology consistency. | ||
| - [#7714](https://github.com/hyperf/hyperf/pull/7714) Don't support Monolog 2.x, only 3.x is supported. | ||
| - [#7563](https://github.com/hyperf/hyperf/pull/7563) Changed the `logger` configuration structure. No newline at end of file |
There was a problem hiding this comment.
This change removes several existing entries from the ## Changed section (e.g., the async-queue rename and Monolog 2->3 note shown in the diff context), and they are not present elsewhere in the changelog. Unless this is intentional cleanup, it looks like an accidental deletion unrelated to the PR’s purpose; consider restoring the removed bullet items or moving them to the correct section.

No description provided.