Skip to content

Commit ca0f658

Browse files
committed
Added context setters and getters
1 parent 246dd7d commit ca0f658

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/Throwable/Error.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
class Error extends \Error
66
{
7+
/**
8+
* @var mixed[]
9+
*/
10+
protected $context = [];
11+
712
/**
813
* @param string $message
914
* @param int $code
@@ -14,6 +19,22 @@ public function __construct($message = 'Unknown error', $code = 0, $previous = n
1419
parent::__construct($message, $code, $previous);
1520
}
1621

22+
/**
23+
* @param mixed[] $context
24+
*/
25+
public function setContext(array $context = [])
26+
{
27+
$this->context = $context;
28+
}
29+
30+
/**
31+
* @return mixed[]
32+
*/
33+
public function getContext()
34+
{
35+
return $this->context;
36+
}
37+
1738
/**
1839
* @return string
1940
*/

src/Throwable/Exception.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
class Exception extends \Exception
66
{
7+
/**
8+
* @var mixed[]
9+
*/
10+
protected $context = [];
11+
712
/**
813
* @param string $message
914
* @param int $code
@@ -14,6 +19,22 @@ public function __construct($message = 'Unknown exception', $code = 0, $previous
1419
parent::__construct($message, $code, $previous);
1520
}
1621

22+
/**
23+
* @param mixed[] $context
24+
*/
25+
public function setContext(array $context = [])
26+
{
27+
$this->context = $context;
28+
}
29+
30+
/**
31+
* @return mixed[]
32+
*/
33+
public function getContext()
34+
{
35+
return $this->context;
36+
}
37+
1738
/**
1839
* @return string
1940
*/

src/Throwable/ThrowableProxy.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class ThrowableProxy
3232
*/
3333
protected $prev;
3434

35+
/**
36+
* @var mixed[]
37+
*/
38+
protected $context;
39+
3540
/**
3641
* @param \Error|\Exception|string[]|string $throwableOrMessage
3742
*/
@@ -69,6 +74,22 @@ public function __destruct()
6974
unset($this->prev);
7075
}
7176

77+
/**
78+
* @param mixed[] $context
79+
*/
80+
public function setContext(array $context = [])
81+
{
82+
$this->context = $context;
83+
}
84+
85+
/**
86+
* @return mixed[]
87+
*/
88+
public function getContext()
89+
{
90+
return $this->context;
91+
}
92+
7293
/**
7394
* Format proxied Throwable as string.
7495
*

0 commit comments

Comments
 (0)