Skip to content

Commit dcb2342

Browse files
committed
move phpError() function to trait
1 parent 6cd3715 commit dcb2342

File tree

3 files changed

+25
-34
lines changed

3 files changed

+25
-34
lines changed

src/HeroTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use ErrorException;
88
use ErrorHeroModule\Handler\Logging;
9+
use Webmozart\Assert\Assert;
10+
use Zend\Mvc\MvcEvent;
911

1012
trait HeroTrait
1113
{
@@ -22,6 +24,29 @@ trait HeroTrait
2224
/** @var string */
2325
private $result = '';
2426

27+
public function phpError() : void
28+
{
29+
if ($this instanceof Listener\Mvc && \func_get_args()) {
30+
Assert::isInstanceOf(
31+
$this->mvcEvent = \func_get_arg(0),
32+
MvcEvent::class
33+
);
34+
}
35+
36+
if (! $this->errorHeroModuleConfig['display-settings']['display_errors']) {
37+
\error_reporting(\E_ALL | \E_STRICT);
38+
\ini_set('display_errors', '0');
39+
}
40+
41+
while (\ob_get_level() > 0) {
42+
\ob_end_flush();
43+
}
44+
45+
\ob_start([$this, 'phpFatalErrorHandler']);
46+
\register_shutdown_function([$this, 'execOnShutdown']);
47+
\set_error_handler([$this, 'phpErrorHandler']);
48+
}
49+
2550
private static function isUncaught(array $error)
2651
{
2752
return 0 === strpos($error['message'], 'Uncaught');

src/Listener/Mvc.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,6 @@ public function attach(EventManagerInterface $events, $priority = 1) : void
5757
$this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP, [$this, 'phpError']);
5858
}
5959

60-
public function phpError(MvcEvent $e) : void
61-
{
62-
$this->mvcEvent = $e;
63-
64-
if (! $this->errorHeroModuleConfig['display-settings']['display_errors']) {
65-
\error_reporting(\E_ALL | \E_STRICT);
66-
\ini_set('display_errors', '0');
67-
}
68-
69-
while (\ob_get_level() > 0) {
70-
\ob_end_flush();
71-
}
72-
73-
\ob_start([$this, 'phpFatalErrorHandler']);
74-
\register_shutdown_function([$this, 'execOnShutdown']);
75-
\set_error_handler([$this, 'phpErrorHandler']);
76-
}
77-
7860
public function exceptionError(MvcEvent $e) : void
7961
{
8062
$exception = $e->getParam('exception');

src/Middleware/Expressive.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6363
return $this->exceptionError($t);
6464
}
6565

66-
public function phpError() : void
67-
{
68-
if (! $this->errorHeroModuleConfig['display-settings']['display_errors']) {
69-
\error_reporting(\E_ALL | \E_STRICT);
70-
\ini_set('display_errors', '0');
71-
}
72-
73-
while (\ob_get_level() > 0) {
74-
\ob_end_flush();
75-
}
76-
77-
\ob_start([$this, 'phpFatalErrorHandler']);
78-
\register_shutdown_function([$this, 'execOnShutdown']);
79-
\set_error_handler([$this, 'phpErrorHandler']);
80-
}
81-
8266
/**
8367
* @throws Error when 'display_errors' config is 1 and Error has thrown
8468
* @throws Exception when 'display_errors' config is 1 and Exception has thrown

0 commit comments

Comments
 (0)