Skip to content

Commit a0d0a60

Browse files
author
Dmitry Bolot
committed
when
1 parent 08781be commit a0d0a60

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Illuminate/Support/helpers.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,18 @@ function with($value, callable $callback = null)
377377
return is_null($callback) ? $value : $callback($value);
378378
}
379379
}
380+
381+
if (! function_exists('when')) {
382+
/**
383+
* If condition is true call the given Closure with the condition value then return the result.
384+
*
385+
* @param mixed $condition
386+
* @param callable $callback
387+
* @param mixed|null $otherwise
388+
* @return mixed
389+
*/
390+
function when($condition, callable $callback, $otherwise = null)
391+
{
392+
return $condition ? $callback($condition) : $otherwise;
393+
}
394+
}

0 commit comments

Comments
 (0)