[13.x] Add UnitEnum support to Application and Translator locale methods#59696
Closed
bipinks wants to merge 1 commit into
Closed
[13.x] Add UnitEnum support to Application and Translator locale methods#59696bipinks wants to merge 1 commit into
bipinks wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR extends the recent enum-support pass across the framework's manager classes (#59614, #59637, #59645, #59646, #59389, #59391, #59420) to the application's locale primitives.
Notification::locale()already accepts aUnitEnum(#55922), but the underlying primitives still required a string, forcing users with a typedLocaleenum to call->valueeverywhere.Changes
The following methods now accept
\UnitEnum|stringand normalize via the existingIlluminate\Support\enum_value()helper:Illuminate\Foundation\Application::setLocale()Illuminate\Foundation\Application::setFallbackLocale()Illuminate\Foundation\Application::isLocale()Illuminate\Translation\Translator::setLocale()Illuminate\Translation\Translator::setFallback()Contracts (
Illuminate\Contracts\Foundation\Application,Illuminate\Contracts\Translation\Translator) updated with matching docblocks.Usage
Both
BackedEnum(uses->value) and pureUnitEnum(uses->name) are supported, matching the behavior ofenum_value()used elsewhere in the framework.Tests
Added unit tests covering backed and pure enum inputs for all five methods:
FoundationApplicationTest::testSetLocaleAcceptsBackedEnumFoundationApplicationTest::testSetLocaleAcceptsUnitEnumFoundationApplicationTest::testSetFallbackLocaleAcceptsBackedEnumFoundationApplicationTest::testIsLocaleAcceptsEnumTranslationTranslatorTest::testSetLocaleAcceptsBackedEnumTranslationTranslatorTest::testSetLocaleAcceptsUnitEnumTranslationTranslatorTest::testSetFallbackAcceptsBackedEnumTranslationTranslatorTest::testSetFallbackAcceptsUnitEnumCloses #59667