作者 竞泽

feat:config fn

... ... @@ -16,7 +16,10 @@
"autoload-dev": {
"psr-4": {
"Lackoxygen\\ExceptionPush\\Tests\\": "tests/"
}
},
"files": [
"src/Helper.php"
]
},
"require": {
"php": ">=7.4",
... ...
... ... @@ -12,13 +12,7 @@ class Dispatcher implements CallbackInterface
*/
public function config(): ?\Closure
{
$dispatcher = ExceptionPush::config('callbacks.dispatcher');
if ($dispatcher instanceof \Closure) {
return $dispatcher;
}
return null;
return closure(ExceptionPush::config('callbacks.dispatcher'));
}
/**
... ...
... ... @@ -30,13 +30,7 @@ class Formatter implements CallbackInterface
*/
public function config(): ?\Closure
{
$formatter = ExceptionPush::config('callbacks.formatter');
if ($formatter instanceof \Closure) {
return $formatter;
}
return null;
return closure(ExceptionPush::config('callbacks.formatter'));
}
... ...
<?php
namespace Lackoxygen\ExceptionPush;
if (!function_exists('closure')) {
function closure($closure): ?\Closure
{
if (is_array($closure) && 2 === count($closure)) {
[$class, $method] = $closure;
return function () use ($class, $method) {
$handler = new $class;
return call_user_func_array([$handler, $method], ...func_get_args());
};
}
if (is_string($closure)) {
return function () use ($closure) {
return call_user_func($closure, ...func_get_args());
};
}
return $closure instanceof \Closure ? $closure : null;
}
}
... ...