conditional
conditional copied to clipboard
Additional Operations
Suggestions:
//Switch
Condition::switch($value)
->default(new DefaultStrategy)
->case(1, new StrategyA)
->case(2, new StrategyB)
;
// Higher Order Proxy to Fluent Str
Condition::when($value)
->endsWith('City')->replaceLast(' City', '')->title()
->contains('New York')->uppercase()
->empty(new RandomCity)
;
//Delegate to Object API
Condition::when($obj)
->implements('toArray')
->then('toArray')
->subclassOf(Post::class)
->then('load', ['comments'])
->instanceOf(ViewFactory::class)
->then('render')
->finally(fn($value) => new Response($value))
;
// Literal Types
Condition::when($val)
->is('numeric')->then(fn($val)=> $value)
->is('string')->then(fn($val)=> $value)
->is('empty')->then(fn($val)=> $value)
->is('null')->then(fn($val)=> $value)
These looks great. Thank you for your suggestions.