Skip to content

Add support for direct value comparisons

Compare
Choose a tag to compare
@Jim-Webfox Jim-Webfox released this 27 Feb 20:45
· 37 commits to main since this release
15321a2

Right now if you want to use ->isA or ->isAny or the other comparison methods you must pass in an enum instance, I.e.

$user->role->isA(MyEnum::from('admin'));           // true
$user->role->isA('admin');                         // false

$user->role->isA(MyEnum::from('not-a-value'));     // exception
$user->role->isA('not-a-value');                   // false

$user->role->isAny([MyEnum::from('admin')]);       // true
$user->role->isAny(['admin']);                     // false

$user->role->isAny([MyEnum::from('not-a-value')]); // exception
$user->role->isAny(['not-a-value']);               // false

This release makes it so each pair of methods will act the same whether given a string value or an enum instance.

$user->role->isA(MyEnum::from('admin'));           // true
$user->role->isA('admin');                         // true

$user->role->isA(MyEnum::from('not-a-value'));     // exception
$user->role->isA('not-a-value');                   // exception

$user->role->isAny([MyEnum::from('admin')]);       // true
$user->role->isAny(['admin']);                     // true

$user->role->isAny([MyEnum::from('not-a-value')]); // exception
$user->role->isAny(['not-a-value']);               // exception

This also applies for isAn, isNotA, isNotAn, isNotAny