natepisarski / unwrap-enums
Safely operate on mixed enums and values
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/natepisarski/unwrap-enums
Requires (Dev)
- phpunit/phpunit: ^11.4
This package is auto-updated.
Last update: 2025-09-24 05:27:44 UTC
README
Provides a function to safely unwrap Enums into their constituent values.
Installation
composer require natepisarski/unwrap-enums
Usage
enum Day: string { case Monday = 'monday'; case Tuesday = 'tuesday'; case Wednesday = 'wednesday'; } unwrap_enums(Day::Monday); // 'monday' unwrap_enums([Day::Monday, Day::Tuesday]); // ['monday', 'tuesday'] unwrap_enums([Day::Monday, [Day::Tuesday, Day::Wednesday]], recursive: true); // ['monday', ['tuesday', 'wednesday']] unwrap_enums('monday'); // 'monday' - already unwrapped unwrap_enums(null); // null - nothing to unwrap
Error Handling
- A
EnumUnwrapException
can be thrown if you attempt to unwrap a non-backed Unit enum.