Skip to content

Commit 53db924

Browse files
committed
Merge branch 'handle-class-not-found-fatal-error'
2 parents b88cdb8 + 656b39c commit 53db924

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/.travis.yml export-ignore
66
/phpstan.neon export-ignore
77
/spec/ export-ignore
8-
/CONTRIBUTING.md export-ignore
8+
/CONTRIBUTING.md export-ignore
9+
/kahlan-config.php export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ coverage.json
55
bin
66
.php_cs.cache
77
.vscode/
8+
build/logs/*

kahlan-config.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php // kahlan-config.php
2+
3+
use Kahlan\Filter\Filters;
4+
use Kahlan\Reporter\Coverage;
5+
use Kahlan\Reporter\Coverage\Driver\Xdebug;
6+
7+
Filters::apply($this, 'coverage', function($next) {
8+
if (! extension_loaded('xdebug')) {
9+
return;
10+
}
11+
12+
$reporters = $this->reporters();
13+
$coverage = new Coverage([
14+
'verbosity' => $this->commandLine()->get('coverage'),
15+
'driver' => new Xdebug(),
16+
'path' => $this->commandLine()->get('src'),
17+
'exclude' => [
18+
'src/HeroAutoload.php',
19+
],
20+
'colors' => ! $this->commandLine()->get('no-colors')
21+
]);
22+
$reporters->add('coverage', $coverage);
23+
});

src/HeroAutoload.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ErrorHeroModule;
6+
7+
use RuntimeException;
8+
9+
class HeroAutoload
10+
{
11+
public static function handle(string $class)
12+
{
13+
if (\class_exists($class)) {
14+
return;
15+
}
16+
17+
if (\in_array(
18+
$class,
19+
[
20+
'error_reporting',
21+
'error_get_last',
22+
'ErrorHeroModuleLogger',
23+
'ZendDeveloperTools\\ProfilerEvent',
24+
]
25+
)) {
26+
return;
27+
}
28+
29+
throw new RuntimeException(sprintf(
30+
'class %s not found',
31+
$class
32+
));
33+
}
34+
}

src/Listener/Mvc.php

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

77
use Assert\Assertion;
88
use ErrorHeroModule\Handler\Logging;
9+
use ErrorHeroModule\HeroAutoload;
910
use ErrorHeroModule\HeroTrait;
1011
use Zend\Console\Response as ConsoleResponse;
1112
use Zend\EventManager\AbstractListenerAggregate;
@@ -56,6 +57,7 @@ public function phpError(MvcEvent $e) : void
5657
{
5758
\register_shutdown_function([$this, 'execOnShutdown']);
5859
\set_error_handler([$this, 'phpErrorHandler']);
60+
\spl_autoload_register([HeroAutoload::class, 'handle']);
5961
}
6062

6163
public function exceptionError(MvcEvent $e) : void

src/Middleware/Expressive.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Closure;
88
use Error;
99
use ErrorHeroModule\Handler\Logging;
10+
use ErrorHeroModule\HeroAutoload;
1011
use ErrorHeroModule\HeroTrait;
1112
use Exception;
1213
use Psr\Http\Message\ResponseInterface;
@@ -60,6 +61,7 @@ public function phpError() : void
6061
{
6162
\register_shutdown_function([$this, 'execOnShutdown']);
6263
\set_error_handler([$this, 'phpErrorHandler']);
64+
\spl_autoload_register([HeroAutoload::class, 'handle']);
6365
}
6466

6567
/**

0 commit comments

Comments
 (0)