You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The when and unless helpers are incredibly valuable, except that they are limited to only true and false boolean values. Recently I found myself wishing for a PHP match-like construct allowing me to handle additional scenarios without invoking when for each.
I initially thought this could be named whenMatch however I think it will be confusing alongside the existing match and matchAll methods. Instead, maybe Conditionable::when() could be refactored to support an array of closures keyed by the values that would trigger them. I don't think PHP supports dynamic branching so we can't use the actual match function in PHP to implement this, but we could mimic its behavior:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
The
when
andunless
helpers are incredibly valuable, except that they are limited to onlytrue
andfalse
boolean values. Recently I found myself wishing for a PHPmatch
-like construct allowing me to handle additional scenarios without invokingwhen
for each.I initially thought this could be named
whenMatch
however I think it will be confusing alongside the existingmatch
andmatchAll
methods. Instead, maybe Conditionable::when() could be refactored to support an array of closures keyed by the values that would trigger them. I don't think PHP supports dynamic branching so we can't use the actualmatch
function in PHP to implement this, but we could mimic its behavior:In the event the key is not found, the third parameter default closure would be executed.
Perhaps:
Beta Was this translation helpful? Give feedback.
All reactions