Skip to content

Commit 20947a8

Browse files
authored
Merge branch 'master' into enhance
2 parents cdbadac + ae71fd1 commit 20947a8

File tree

5 files changed

+49
-49
lines changed

5 files changed

+49
-49
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
/.editorconfig export-ignore
2727
/.gitattributes export-ignore
2828
/.gitignore export-ignore
29-
/.scrutinizer.yml export-ignore
3029
/phpunit.xml.dist export-ignore
3130
/tests export-ignore
3231
/docs export-ignore

.scrutinizer.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Yii Error Handler Change Log
22

3-
## 3.2.2 under development
3+
## 3.3.1 under development
44

5-
- Enh #117, #120: Show arguments table by click (@xepozz, @vjik)
5+
- no changes in this release.
6+
7+
## 3.3.0 July 11, 2024
8+
9+
- Enh #112: Add copy cURL button, sort request headers, fix UI (@xepozz)
10+
- Enh #113: Simplify error log (@xepozz)
11+
- Enh #114: Show full argument by click (@xepozz)
612
- Enh #116: Remove @anonymous postfix (@xepozz)
13+
- Enh #117, #120: Show arguments table by click (@xepozz, @vjik)
714
- Bug #114: Stop `click` event on text selection (@xepozz)
8-
- Enh #114: Show full argument by click (@xepozz)
9-
- Enh #113: Simplify error log (@xepozz)
10-
- Enh #112: Add copy cURL button, sort request headers, fix UI (@xepozz)
15+
- Bug #122: Do `exit(1)` after all shutdown functions, even postponed ones (@samdark)
1116

1217
## 3.2.1 March 07, 2024
1318

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
[![Latest Stable Version](https://poser.pugx.org/yiisoft/error-handler/v/stable.png)](https://packagist.org/packages/yiisoft/error-handler)
1010
[![Total Downloads](https://poser.pugx.org/yiisoft/error-handler/downloads.png)](https://packagist.org/packages/yiisoft/error-handler)
1111
[![Build status](https://github.com/yiisoft/error-handler/workflows/build/badge.svg)](https://github.com/yiisoft/error-handler/actions?query=workflow%3Abuild)
12-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/error-handler/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/error-handler/?branch=master)
13-
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/error-handler/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/error-handler/?branch=master)
12+
[![Code coverage](https://codecov.io/gh/yiisoft/error-handler/graph/badge.svg?token=3ZC0QHQHIN)](https://codecov.io/gh/yiisoft/error-handler)
1413
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Ferror-handler%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/error-handler/master)
1514
[![static analysis](https://github.com/yiisoft/error-handler/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/error-handler/actions?query=workflow%3A%22static+analysis%22)
1615

src/ErrorHandler.php

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ final class ErrorHandler
4141
private bool $enabled = false;
4242
private bool $initialized = false;
4343

44+
/**
45+
* @param LoggerInterface $logger Logger to write errors to.
46+
* @param ThrowableRendererInterface $defaultRenderer Default throwable renderer.
47+
* @param EventDispatcherInterface|null $eventDispatcher Event dispatcher for error events.
48+
* @param int $exitShutdownHandlerDepth Depth of the exit() shutdown handler to ensure it's executed last.
49+
*/
4450
public function __construct(
4551
private LoggerInterface $logger,
4652
private ThrowableRendererInterface $defaultRenderer,
4753
private ?EventDispatcherInterface $eventDispatcher = null,
54+
private int $exitShutdownHandlerDepth = 2
4855
) {
4956
}
5057

@@ -108,7 +115,7 @@ public function register(): void
108115

109116
$this->initializeOnce();
110117

111-
// Handles throwable, echo output and exit.
118+
// Handles throwable that isn't caught otherwise, echo output and exit.
112119
set_exception_handler(function (Throwable $t): void {
113120
if (!$this->enabled) {
114121
return;
@@ -200,16 +207,41 @@ private function renderThrowableAndTerminate(Throwable $t): void
200207
if (!empty($this->workingDirectory)) {
201208
chdir($this->workingDirectory);
202209
}
203-
// disable error capturing to avoid recursive errors while handling exceptions
210+
// Disable error capturing to avoid recursive errors while handling exceptions.
204211
$this->unregister();
205-
// set preventive HTTP status code to 500 in case error handling somehow fails and headers are sent
212+
// Set preventive HTTP status code to 500 in case error handling somehow fails and headers are sent.
206213
http_response_code(Status::INTERNAL_SERVER_ERROR);
207214

208215
echo $this->handle($t);
209216
$this->eventDispatcher?->dispatch(new ApplicationError($t));
210217

211-
register_shutdown_function(static function (): void {
212-
exit(1);
213-
});
218+
$handler = $this->wrapShutdownHandler(
219+
static function (): void {
220+
exit(1);
221+
},
222+
$this->exitShutdownHandlerDepth
223+
);
224+
225+
register_shutdown_function($handler);
226+
}
227+
228+
/**
229+
* Wraps shutdown handler into another shutdown handler to ensure it is called last after all other shutdown
230+
* functions, even those added to the end.
231+
*
232+
* @param callable $handler Shutdown handler to wrap.
233+
* @param int $depth Wrapping depth.
234+
* @return callable Wrapped handler.
235+
*/
236+
private function wrapShutdownHandler(callable $handler, int $depth): callable
237+
{
238+
$currentDepth = 0;
239+
while ($currentDepth < $depth) {
240+
$handler = static function() use ($handler): void {
241+
register_shutdown_function($handler);
242+
};
243+
$currentDepth++;
244+
}
245+
return $handler;
214246
}
215247
}

0 commit comments

Comments
 (0)