update lock clucknut
All checks were successful
All checks were successful
This commit is contained in:
19
vendor/nette/utils/src/Utils/Callback.php
vendored
19
vendor/nette/utils/src/Utils/Callback.php
vendored
@@ -22,21 +22,24 @@ final class Callback
|
||||
|
||||
/**
|
||||
* Invokes internal PHP function with own error handler.
|
||||
* @param callable-string $function
|
||||
* @param list<mixed> $args
|
||||
* @param callable(string, int): (bool|void|null) $onError
|
||||
*/
|
||||
public static function invokeSafe(string $function, array $args, callable $onError): mixed
|
||||
{
|
||||
$prev = set_error_handler(function ($severity, $message, $file) use ($onError, &$prev, $function): ?bool {
|
||||
$prev = set_error_handler(function (int $severity, string $message, string $file, int $line) use ($onError, &$prev, $function): bool {
|
||||
if ($file === __FILE__) {
|
||||
$msg = ini_get('html_errors')
|
||||
? Html::htmlToText($message)
|
||||
: $message;
|
||||
$msg = preg_replace("#^$function\\(.*?\\): #", '', $msg);
|
||||
$msg = (string) preg_replace("#^$function\\(.*?\\): #", '', $msg);
|
||||
if ($onError($msg, $severity) !== false) {
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $prev ? $prev(...func_get_args()) : false;
|
||||
return $prev ? $prev(...func_get_args()) !== false : false;
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -53,7 +56,7 @@ public static function invokeSafe(string $function, array $args, callable $onErr
|
||||
* @return callable
|
||||
* @throws Nette\InvalidArgumentException
|
||||
*/
|
||||
public static function check(mixed $callable, bool $syntax = false)
|
||||
public static function check(mixed $callable, bool $syntax = false): mixed
|
||||
{
|
||||
if (!is_callable($callable, $syntax)) {
|
||||
throw new Nette\InvalidArgumentException(
|
||||
@@ -87,7 +90,7 @@ public static function toString(mixed $callable): string
|
||||
* @param callable $callable type check is escalated to ReflectionException
|
||||
* @throws \ReflectionException if callback is not valid
|
||||
*/
|
||||
public static function toReflection($callable): \ReflectionMethod|\ReflectionFunction
|
||||
public static function toReflection(mixed $callable): \ReflectionMethod|\ReflectionFunction
|
||||
{
|
||||
if ($callable instanceof \Closure) {
|
||||
$callable = self::unwrap($callable);
|
||||
@@ -100,6 +103,7 @@ public static function toReflection($callable): \ReflectionMethod|\ReflectionFun
|
||||
} elseif (is_object($callable) && !$callable instanceof \Closure) {
|
||||
return new ReflectionMethod($callable, '__invoke');
|
||||
} else {
|
||||
assert($callable instanceof \Closure || is_string($callable));
|
||||
return new \ReflectionFunction($callable);
|
||||
}
|
||||
}
|
||||
@@ -116,8 +120,9 @@ public static function isStatic(callable $callable): bool
|
||||
|
||||
/**
|
||||
* Unwraps closure created by Closure::fromCallable().
|
||||
* @return callable|array{object|class-string, string}|string
|
||||
*/
|
||||
public static function unwrap(\Closure $closure): callable|array
|
||||
public static function unwrap(\Closure $closure): callable|array|string
|
||||
{
|
||||
$r = new \ReflectionFunction($closure);
|
||||
$class = $r->getClosureScopeClass()?->name;
|
||||
|
||||
Reference in New Issue
Block a user