Update Kirby to 3.7.4

This commit is contained in:
Lukas Bestle
2022-08-23 21:36:13 +02:00
parent 435b9f4541
commit d89a0a647c
674 changed files with 212 additions and 61 deletions

41
kirby/src/Cms/Helpers.php Executable file → Normal file
View File

@@ -2,6 +2,7 @@
namespace Kirby\Cms;
use Closure;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\Str;
@@ -46,6 +47,46 @@ class Helpers
return ($kirby->component('dump'))($kirby, $variable, $echo);
}
/**
* Performs an action with custom handling
* for all PHP errors and warnings
* @since 3.7.4
*
* @param \Closure $action Any action that may cause an error or warning
* @param \Closure $handler Custom callback like for `set_error_handler()`;
* the first argument is a return value override passed
* by reference, the additional arguments come from
* `set_error_handler()`; returning `false` activates
* error handling by Whoops and/or PHP
* @return mixed Return value of the `$action` closure, possibly overridden by `$handler`
*/
public static function handleErrors(Closure $action, Closure $handler)
{
$override = $oldHandler = null;
$oldHandler = set_error_handler(function () use (&$override, &$oldHandler, $handler) {
$handlerResult = $handler($override, ...func_get_args());
if ($handlerResult === false) {
// handle other warnings with Whoops if loaded
if (is_callable($oldHandler) === true) {
return $oldHandler(...func_get_args());
}
// otherwise use the standard error handler
return false; // @codeCoverageIgnore
}
// no additional error handling
return true;
});
$result = $action();
restore_error_handler();
return $override ?? $result;
}
/**
* Checks if a helper was overridden by the user
* by setting the `KIRBY_HELPER_*` constant