|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | + |
3 | 5 | use Psr\Http\Message\ServerRequestInterface; |
| 6 | +use ReflectionClass; |
| 7 | +use Throwable; |
4 | 8 | use Yiisoft\ErrorHandler\CompositeException; |
5 | 9 | use Yiisoft\ErrorHandler\Exception\ErrorException; |
| 10 | +use Yiisoft\ErrorHandler\HeadersProvider; |
6 | 11 | use Yiisoft\ErrorHandler\Renderer\HtmlRenderer; |
7 | 12 | use Yiisoft\FriendlyException\FriendlyExceptionInterface; |
8 | 13 |
|
|
20 | 25 | } |
21 | 26 | $isFriendlyException = $throwable instanceof FriendlyExceptionInterface; |
22 | 27 | $solution = $isFriendlyException ? $throwable->getSolution() : null; |
| 28 | + |
| 29 | +// Check if the exception class has FriendlyException attribute |
| 30 | +if ($solution === null && class_exists('Yiisoft\FriendlyException\Attribute\FriendlyException')) { |
| 31 | + try { |
| 32 | + $reflectionClass = new ReflectionClass($throwable); |
| 33 | + $attributes = $reflectionClass->getAttributes('Yiisoft\FriendlyException\Attribute\FriendlyException'); |
| 34 | + |
| 35 | + if (!empty($attributes)) { |
| 36 | + $friendlyExceptionAttribute = $attributes[0]->newInstance(); |
| 37 | + $solution = $friendlyExceptionAttribute->solution; |
| 38 | + } |
| 39 | + } catch (\Throwable $e) { |
| 40 | + // Ignore exception |
| 41 | + } |
| 42 | +} |
| 43 | + |
23 | 44 | $exceptionClass = get_class($throwable); |
24 | 45 | $exceptionMessage = $throwable->getMessage(); |
25 | 46 |
|
|
78 | 99 | <div class="exception-card"> |
79 | 100 | <div class="exception-class"> |
80 | 101 | <?php |
81 | | - if ($isFriendlyException): ?> |
| 102 | + $hasFriendlyName = false; |
| 103 | + if ($isFriendlyException) { |
| 104 | + $hasFriendlyName = true; |
| 105 | + ?> |
82 | 106 | <span><?= $this->htmlEncode($throwable->getName())?></span> |
83 | 107 | — |
84 | 108 | <?= $exceptionClass ?> |
85 | | - <?php else: ?> |
86 | | - <span><?= $exceptionClass ?></span> |
87 | | - <?php endif ?> |
| 109 | + <?php |
| 110 | + } else { |
| 111 | + // Check if the exception class has FriendlyException attribute |
| 112 | + $hasFriendlyNameFromAttribute = false; |
| 113 | + |
| 114 | + if (class_exists('Yiisoft\FriendlyException\Attribute\FriendlyException')) { |
| 115 | + try { |
| 116 | + $reflectionClass = new ReflectionClass($throwable); |
| 117 | + $attributes = $reflectionClass->getAttributes('Yiisoft\FriendlyException\Attribute\FriendlyException'); |
| 118 | + |
| 119 | + if (!empty($attributes)) { |
| 120 | + $friendlyExceptionAttribute = $attributes[0]->newInstance(); |
| 121 | + $hasFriendlyNameFromAttribute = true; |
| 122 | + ?> |
| 123 | + <span><?= $this->htmlEncode($friendlyExceptionAttribute->name) ?></span> |
| 124 | + — |
| 125 | + <?= $exceptionClass ?> |
| 126 | + <?php |
| 127 | + } |
| 128 | + } catch (\Throwable $e) { |
| 129 | + // Ignore exception |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + if (!$hasFriendlyName && !$hasFriendlyNameFromAttribute) { |
| 134 | + ?> |
| 135 | + <span><?= $exceptionClass ?></span> |
| 136 | + <?php |
| 137 | + } |
| 138 | + } |
| 139 | + ?> |
88 | 140 | (Code #<?= $throwable->getCode() ?>) |
89 | 141 | </div> |
90 | 142 |
|
|
98 | 150 |
|
99 | 151 | <?= $this->renderPreviousExceptions($originalException) ?> |
100 | 152 |
|
101 | | - <textarea id="clipboard"><?= $this->htmlEncode($throwable) ?></textarea> |
| 153 | + <textarea id="clipboard"><?= $this->htmlEncode((string)$throwable) ?></textarea> |
102 | 154 | <span id="copied">Copied!</span> |
103 | 155 |
|
104 | 156 | <a href="#" |
105 | 157 | class="copy-clipboard" |
106 | | - data-clipboard="<?= $this->htmlEncode($throwable) ?>" |
| 158 | + data-clipboard="<?= $this->htmlEncode((string)$throwable) ?>" |
107 | 159 | title="Copy the stacktrace for use in a bug report or pastebin" |
108 | 160 | > |
109 | 161 | <svg width="26" height="30" fill="none" xmlns="http://www.w3.org/2000/svg"> |
|
0 commit comments