Update Composer packages
This commit is contained in:
parent
0320235f6c
commit
a8b68fb61b
378 changed files with 28466 additions and 28852 deletions
|
@ -44,7 +44,18 @@ class Helpers
|
|||
public static function dump($variable, bool $echo = true): string
|
||||
{
|
||||
$kirby = App::instance();
|
||||
return ($kirby->component('dump'))($kirby, $variable, $echo);
|
||||
|
||||
if ($kirby->environment()->cli() === true) {
|
||||
$output = print_r($variable, true) . PHP_EOL;
|
||||
} else {
|
||||
$output = '<pre>' . print_r($variable, true) . '</pre>';
|
||||
}
|
||||
|
||||
if ($echo === true) {
|
||||
echo $output;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,29 +64,38 @@ class Helpers
|
|||
* @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`
|
||||
* @param \Closure $condition Closure that returns bool to determine if to
|
||||
* suppress an error, receives arguments for
|
||||
* `set_error_handler()`
|
||||
* @param mixed $fallback Value to return when error is suppressed
|
||||
* @return mixed Return value of the `$action` closure,
|
||||
* possibly overridden by `$fallback`
|
||||
*/
|
||||
public static function handleErrors(Closure $action, Closure $handler)
|
||||
public static function handleErrors(Closure $action, Closure $condition, $fallback = null)
|
||||
{
|
||||
$override = $oldHandler = null;
|
||||
$oldHandler = set_error_handler(function () use (&$override, &$oldHandler, $handler) {
|
||||
$handlerResult = $handler($override, ...func_get_args());
|
||||
$override = null;
|
||||
|
||||
if ($handlerResult === false) {
|
||||
$handler = set_error_handler(function () use (&$override, &$handler, $condition, $fallback) {
|
||||
// check if suppress condition is met
|
||||
$suppress = $condition(...func_get_args());
|
||||
|
||||
if ($suppress !== true) {
|
||||
// handle other warnings with Whoops if loaded
|
||||
if (is_callable($oldHandler) === true) {
|
||||
return $oldHandler(...func_get_args());
|
||||
if (is_callable($handler) === true) {
|
||||
return $handler(...func_get_args());
|
||||
}
|
||||
|
||||
// otherwise use the standard error handler
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// use fallback to override return for suppressed errors
|
||||
$override = $fallback;
|
||||
|
||||
if (is_callable($override) === true) {
|
||||
$override = $override();
|
||||
}
|
||||
|
||||
// no additional error handling
|
||||
return true;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue