Skip to content

Commit 4c6c957

Browse files
committed
Add mask to shutdownHandler
1 parent d7796aa commit 4c6c957

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Handlers/AbstractHandler.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ abstract class AbstractHandler implements HandlerInterface
3030
protected bool $throwException = true;
3131
protected ?HttpMessagingInterface $http = null;
3232
protected ?Closure $eventCallable = null;
33+
protected int $severity = E_ALL;
3334

3435
/**
3536
* Determine how the code block should look like
@@ -74,6 +75,17 @@ public function getHttp(): HttpMessagingInterface
7475
return $this->http;
7576
}
7677

78+
/**
79+
* Set expected severity mask
80+
* @param int $severity
81+
* @return self
82+
*/
83+
final public function setSeverity(int $severity): self
84+
{
85+
$this->severity = $severity;
86+
return $this;
87+
}
88+
7789
/**
7890
* Main error handler script
7991
* @param int $errNo
@@ -94,10 +106,8 @@ public function errorHandler(int $errNo, string $errStr, string $errFile, int $e
94106
} else {
95107
$this->exceptionHandler($exception);
96108
}
97-
98109
return true;
99110
}
100-
101111
return false;
102112
}
103113

@@ -111,7 +121,7 @@ public function shutdownHandler(): void
111121
$error = error_get_last();
112122
if($error) {
113123
$item = new ExceptionItem(new ErrorException());
114-
if ($item->isLevelFatal()) {
124+
if ($item->isLevelFatal() && ($error['type'] & $this->severity) !== 0) {
115125
$this->errorHandler(
116126
$error['type'],
117127
$error['message'],
@@ -122,6 +132,7 @@ public function shutdownHandler(): void
122132
}
123133
}
124134

135+
125136
/**
126137
* Get trace line with filtered arguments and max length
127138
* @param Throwable $exception

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ You can exclude/remove severities from the error handler.
4141

4242
```php
4343
$run = new Run(new HtmlHandler());
44-
$run->excludeSeverityLevels([E_DEPRECATED, E_USER_DEPRECATED]);
44+
$run->severity()->excludeSeverityLevels([E_DEPRECATED, E_USER_DEPRECATED]);
4545
$run->load();
4646
```
4747
*[You can find a list of available severities here](https://www.php.net/manual/en/errorfunc.constants.php)*

Run.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function load(): void
6060
header_remove('location');
6161
}
6262

63+
$this->handler->setSeverity($this->severity()->getSeverityLevelMask());
6364
set_error_handler([$this->handler, "errorHandler"], $this->severity()->getSeverityLevelMask());
6465
set_exception_handler([$this->handler, "exceptionHandler"]);
6566
register_shutdown_function([$this->handler, "shutdownHandler"]);

0 commit comments

Comments
 (0)