Download the PHP package skollro/otherwise without Composer
On this page you can find all versions of the php package skollro/otherwise. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download skollro/otherwise
More information about skollro/otherwise
Files in skollro/otherwise
Package otherwise
Short Description Functional when-otherwise conditionals for PHP.
License MIT
Informations about the package otherwise
Functional when-otherwise conditionals
This package allows to replace PHP conditionals by an easy functional match-when-otherwise syntax.
Install
You can install this package via composer:
Usage
Every conditional match consists out of one or multiple when and one otherwise to provide values for each path.
match($value, ...$params): Match
This package provides a helper function match. The first value is the value to match against. You can pass a variable amount of $params which are passed to every callable that resolves a $result.
when($condition, $result): Match
$condition is a bool, a callable or a value to compare against (using ==). $result takes either some value or a callable for lazy evaluation. More specific conditions have to be defined first because the first match is the final result.
whenInstanceOf($type, $result): Match
This is just a shortcut method for $value instanceof A. $type is anything that can be on the left side of an instanceof operator. $result takes either some value or a callable for lazy evaluation. More specific conditions have to be defined first because the first match is the final result.
whenThrow($condition, $result): Match
$condition is a bool, a callable or a value to compare against (using ==). $result takes either an exception class name, an exception instance or a callable that returns an exception. More specific conditions have to be defined first because the first match throws the exception instantly.
otherwise($value)
$value is of type callable or some value. Supplies the default value if no when has evaluated to true before.
otherwiseThrow($value)
Throws an exception if no when has evaluated to true before. It takes an exception class name, an exception instance or a callable that returns an exception.
License
The MIT License (MIT). Please see License File for more information.