|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the bugloos/fault-tolerance-bundle project. |
|
5
|
|
|
* (c) Bugloos <https://bugloos.com/> |
|
6
|
|
|
* For the full copyright and license information, please view |
|
7
|
|
|
* the LICENSE file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Bugloos\FaultToleranceBundle\Exception; |
|
11
|
|
|
|
|
12
|
|
|
use Exception; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Mojtaba Gheytasi <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class RuntimeException extends \RuntimeException |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Exception while retrieving the fallback, if enabled |
|
21
|
|
|
*/ |
|
22
|
|
|
private ?Exception $fallbackException; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class name of the command |
|
26
|
|
|
*/ |
|
27
|
|
|
private string $commandClass; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $message |
|
33
|
|
|
* @param int $commandClass |
|
34
|
|
|
* @param Exception|null $originalException (Optional) Original exception. May be null if short-circuited |
|
35
|
|
|
* @param Exception|null $fallbackException (Optional) Exception thrown while retrieving fallback |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct( |
|
38
|
|
|
$message, |
|
39
|
|
|
$commandClass, |
|
40
|
|
|
Exception $originalException = null, |
|
41
|
|
|
Exception $fallbackException = null |
|
42
|
|
|
) { |
|
43
|
|
|
parent::__construct($message, 0, $originalException); |
|
44
|
|
|
$this->fallbackException = $fallbackException; |
|
45
|
|
|
$this->commandClass = $commandClass; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Returns class name of the command the exception was thrown from |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getCommandClass(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->commandClass; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Returns fallback exception if available |
|
58
|
|
|
* |
|
59
|
|
|
* @return Exception |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getFallbackException(): ?Exception |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->fallbackException; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|