Logic
Reference for the Logic module: boolean combinators and callback-based conditionals. Or over two, three or four booleans; If and IfNot; value and callback selection; a switch and case pair; and optional-value helpers that run a callback based on whether a value is null.
This page is a pure reference. For how the framework fits together, see the Guide.
Logic- boolean combinators and callback-based conditionals, selection, switch and optional-value helpers.
Logic
A single class of static helpers. Or, Or3 and Or4 combine booleans. If, IfNot, Select and SelectValue branch on a condition, running a callback or returning a value. Switch and Case form a callback-based switch. Optional and OptionalNot branch on whether a value is null.
Case
Logic::Case(mixed $caseValue, Callable $caseCallback): void
Run the callback when the case value strictly equals the current switch value set by Switch.
| Name | Type | Description |
|---|---|---|
$caseValue | mixed | The value to compare against the current switch value. |
$caseCallback | Callable | The callback run when the values match. |
Returns void
If
Logic::If(bool $condition, Callable $onTrue): void
Run the callback when the condition is true.
| Name | Type | Description |
|---|---|---|
$condition | bool | The condition to test. |
$onTrue | Callable | The callback run when the condition is true. |
Returns void
IfNot
Logic::IfNot(bool $condition, Callable $onFalse): void
Run the callback when the condition is false.
| Name | Type | Description |
|---|---|---|
$condition | bool | The condition to test. |
$onFalse | Callable | The callback run when the condition is false. |
Returns void
Optional
Logic::Optional($optionalValue, Callable $onPresent): void
Run the callback when the value is not null, passing the value to it.
| Name | Type | Description |
|---|---|---|
$optionalValue | mixed | The value that may be null. |
$onPresent | Callable | The callback run with the value when it is not null. |
Returns void
OptionalNot
Logic::OptionalNot($optionalValue, Callable $onNull): void
Run the callback when the value is null.
| Name | Type | Description |
|---|---|---|
$optionalValue | mixed | The value that may be null. |
$onNull | Callable | The callback run when the value is null. |
Returns void
Or
Logic::Or(bool $a, bool $b): bool
True when either of two booleans is true.
| Name | Type | Description |
|---|---|---|
$a | bool | The first value. |
$b | bool | The second value. |
Returns bool True when either value is true.
Or3
Logic::Or3(bool $a, bool $b, bool $c): bool
True when any of three booleans is true.
| Name | Type | Description |
|---|---|---|
$a | bool | The first value. |
$b | bool | The second value. |
$c | bool | The third value. |
Returns bool True when any value is true.
Or4
Logic::Or4(bool $a, bool $b, bool $c, bool $d): bool
True when any of four booleans is true.
| Name | Type | Description |
|---|---|---|
$a | bool | The first value. |
$b | bool | The second value. |
$c | bool | The third value. |
$d | bool | The fourth value. |
Returns bool True when any value is true.
Select
Logic::Select(bool $condition, Callable $onTrue, Callable $onFalse): void
Run one of two callbacks depending on the condition.
| Name | Type | Description |
|---|---|---|
$condition | bool | The condition to test. |
$onTrue | Callable | The callback run when the condition is true. |
$onFalse | Callable | The callback run when the condition is false. |
Returns void
SelectValue
Logic::SelectValue(bool $condition, mixed $onTrue, mixed $onFalse): mixed
Return one of two values depending on the condition.
| Name | Type | Description |
|---|---|---|
$condition | bool | The condition to test. |
$onTrue | mixed | The value returned when the condition is true. |
$onFalse | mixed | The value returned when the condition is false. |
Returns mixed The chosen value.
Switch
Logic::Switch(mixed $value, Callable $casesCallback): void
Set the current switch value, run the callback that declares the cases, then restore the previous switch value.
| Name | Type | Description |
|---|---|---|
$value | mixed | The value the cases are compared against. |
$casesCallback | Callable | The callback that declares the cases, typically calling Case. |
Returns void