You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Idea: Introduce a new class for wrapping up operation results or errors like a sum type.
Old code:
$env = lowebf\Environment::getInstance();
// will throw an exception$posts = $env->posts()->loadPage(null);
// ...
New code:
$env = lowebf\Environment::getInstance();
// throws an exception like previous example$posts = $env->posts()->loadPage(null)->unwrap();
// returns the result if found or exits script if not$posts = $env->posts()->loadPage(null)->unwrapOrExit($env);
// ...$env->listDirectory(null)
->mapOk(function ($folders) {
// ... do something with folders ...return$folders;
});
Mockup
classResult {
constOK_STATE = 1;
constERROR_STATE = 2;
/** @var int */private$state;
private$argument;
privatefunction__construct(int$state, $argument);
publicstaticfunctionok($value) : Result;
publicstaticfunctionerror(Exception$e) : Result;
publicfunctionisOk() : bool;
publicfunctionisError() : bool;
// try to return operations result.// throws exception if result is not successful.publicfunctionunwrap();
// unwrap the result or use defaultpublicfunctionunwrapOr($default);
// clear output buffer and set status codepublicfunctionunwrapOrExit(Environment$env, $statusCode = null);
// if the result is ok -> pass it to $mapper and wrap it in a new result.// returns itself otherwise.publicfunctionmapOk(callable$mapper) : Result;
}
The text was updated successfully, but these errors were encountered:
Idea: Introduce a new class for wrapping up operation results or errors like a sum type.
Old code:
New code:
Mockup
The text was updated successfully, but these errors were encountered: