Skip to content

Commit df418cc

Browse files
authored
Merge pull request #12 from VadymHrechukha/HP-1900_monitor_changes_in_production_envs
HP-1900: Monitor changes in production envs
2 parents 8c6a512 + db83f9c commit df418cc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/exception/HasContext.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

0 commit comments

Comments
 (0)