Repository navigation
Expand file tree
/
Copy pathExceptionHandler.php
More file actions
54 lines (47 loc) · 1.58 KB
/
Copy pathExceptionHandler.php
File metadata and controls
54 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\ExceptionHandler;
use Swow\Psr7\Message\ResponsePlusInterface;
use Throwable;
abstract class ExceptionHandler
{
/**
* Handle the exception, and return the specified result.
*/
abstract public function handle(Throwable $throwable, ResponsePlusInterface $response);
/**
* Determine if the current exception handler should handle the exception.
*
* @see ExceptionHandler::stopPropagation() if you want to stop propagation after handling
* an exception, as returning `true` in `isValid` does not stop the handlers call loop.
*
* @return bool If return true, then this exception handler will handle the exception and then call the next handler,
* If return false, this handler will be ignored and the next will be called
*/
abstract public function isValid(Throwable $throwable): bool;
/**
* Stop propagate the exception to next handler.
*/
public function stopPropagation(): bool
{
Propagation::instance()->setPropagationStopped(true);
return true;
}
/**
* Is propagation stopped ?
* This will typically only be used by the handler to determine if the
* previous handler halted propagation.
*/
public function isPropagationStopped(): bool
{
return Propagation::instance()->isPropagationStopped();
}
}