File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace hidev \exception ;
4+
5+ use Throwable ;
6+
7+ trait HasContext
8+ {
9+ protected array $ context = [];
10+
11+ abstract public function getPrevious (): ?Throwable ;
12+
13+ public function addContext (array $ data ): self
14+ {
15+ $ this ->context = array_merge ($ this ->context , $ data );
16+ return $ this ;
17+ }
18+
19+ public function getContext (): array
20+ {
21+ return $ this ->context ;
22+ }
23+
24+ public static function make (string $ message , array $ context ): self
25+ {
26+ $ exception = new static ($ message );
27+ $ exception ->addContext ($ context );
28+
29+ return $ exception ;
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace hidev \exception ;
4+
5+ interface HasContextInterface extends \Throwable
6+ {
7+ public function addContext (array $ data ): self ;
8+
9+ public function getContext (): array ;
10+ }
You can’t perform that action at this time.
0 commit comments