feat(session): add BackedEnum support for session keys #305
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.
feat(session): add BackedEnum support for session keys
Summary
This PR enables using BackedEnums as session keys, building on the
Str::from()andStr::fromAll()helpers merged in #291. Session keys are a prime candidate for enum support since they're frequently used string identifiers prone to typos.Motivation
Using string literals for session keys is error-prone:
BackedEnums solve this with IDE autocomplete and compile-time safety:
Usage Examples
Basic operations:
Checking existence:
Array operations with mixed enums and strings:
Flash data:
Increment/decrement:
Remember pattern:
Interoperability - enum and string access the same data:
Int-backed enums work too:
Methods Updated
get()BackedEnum|string $keyput()array|BackedEnum|string $keypull()BackedEnum|string $keyremove()BackedEnum|string $keyforget()array|BackedEnum|string $keysexists()array|BackedEnum|string $keymissing()array|BackedEnum|string $keyhas()array|BackedEnum|string $keyhasAny()array|BackedEnum|string $keyremember()BackedEnum|string $keypush()BackedEnum|string $keyincrement()BackedEnum|string $keydecrement()BackedEnum|string $keyflash()BackedEnum|string $keynow()BackedEnum|string $keyonly()except()hasOldInput()BackedEnum|string|null $keygetOldInput()BackedEnum|string|null $keyBreaking Changes
None. This is purely additive - existing code using string keys continues to work unchanged.
Tests
Added 41 new tests covering: