1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Core\Exception; |
4: | |
5: | use Salient\Core\Process; |
6: | use Salient\Utility\Get; |
7: | use Throwable; |
8: | |
9: | |
10: | |
11: | |
12: | class ProcessException extends Exception |
13: | { |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | public function __construct( |
28: | string $format = '', |
29: | ?array $values = null, |
30: | ?Throwable $previous = null, |
31: | ?int $exitStatus = null |
32: | ) { |
33: | $message = $values |
34: | ? sprintf($format, ...$this->filterValues($values)) |
35: | : $format; |
36: | |
37: | parent::__construct($message, $previous, $exitStatus); |
38: | } |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | private function filterValues(array $values): array |
45: | { |
46: | foreach ($values as $value) { |
47: | $filtered[] = $value instanceof Process |
48: | ? Get::code($value->getCommand()) |
49: | : $value; |
50: | } |
51: | return $filtered; |
52: | } |
53: | } |
54: | |