OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
79
app/Core/Exceptions/ReportableHandler.php
Normal file
79
app/Core/Exceptions/ReportableHandler.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Exceptions;
|
||||
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use Throwable;
|
||||
|
||||
class ReportableHandler
|
||||
{
|
||||
use ReflectsClosures;
|
||||
|
||||
/**
|
||||
* The underlying callback.
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* Indicates if reporting should stop after invoking this handler.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $shouldStop = false;
|
||||
|
||||
/**
|
||||
* Create a new reportable handler instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(callable $callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the handler.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __invoke(Throwable $e)
|
||||
{
|
||||
$result = call_user_func($this->callback, $e);
|
||||
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! $this->shouldStop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the callback handles the given exception.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handles(Throwable $e)
|
||||
{
|
||||
foreach ($this->firstClosureParameterTypes($this->callback) as $type) {
|
||||
if (is_a($e, $type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that report handling should stop after invoking this callback.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function stop()
|
||||
{
|
||||
$this->shouldStop = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user