Ok
Contains the success value.
Instances of this class are immutable and not affected by any method calls.
Static Methods
empty
public static function empty(): self;Returns a successful result containing no value (null).
withValue
public static function withValue(mixed $value): self;Makes a new Ok with the given value.
Methods
andThen
public function andThen(Ok|Error|Closure $result): Ok|Error;Returns the given result.
Note: If the result is a closure, this method will call it and return its output.
exception
public function exception(): null;Returns null, since Ok instances never contain an exception.
hasException
public function hasException(): false;Returns false, since Ok instances never contain an exception.
hasMessage
public function hasMessage(): false;Returns false, since Ok instances never contain a message.
hasValue
public function hasValue(): bool;Returns true if the result contains a value.
isError
public function isError(): false;Returns whether the result is an error.
isOk
public function isOk(): true;Returns whether the result is a success.
message
public function message(): string;Returns an empty string, since Ok instances never contain a message.
onFailure
public function onFailure(Closure $action): self;Returns the original instance without performing the given action.
Parameters:
$action a Closure that receives the error exception.
onSuccess
public function onSuccess(Closure $action): self;Performs the given action on the encapsulated value. Returns the original instance unchanged.
Parameters:
$action a Closure that receives the success value.
or
public function or(mixed $value): mixed;Returns the success value, ignoring the given value.
orDie
public function orDie(int|string $status = null): mixed;Returns the success value.
orElse
public function orElse(Ok|Error|Closure $result): self;Returns the original instance, ignoring the given result.
orFail
public function orFail(): mixed;Returns the success value.
orFalse
public function orFalse(): mixed;Returns the success value.
orNull
public function orNull(): mixed;Returns the success value.
orThrow
public function orThrow(Throwable|Closure $exception): mixed;Returns the success value.
value
public function value(): mixed;Returns the result's value, if any.