Skip to content

Commit

Permalink
Merge branch 'handle-class-not-found-fatal-error'
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Sep 16, 2018
2 parents b88cdb8 + 656b39c commit 53db924
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/.travis.yml export-ignore
/phpstan.neon export-ignore
/spec/ export-ignore
/CONTRIBUTING.md export-ignore
/CONTRIBUTING.md export-ignore
/kahlan-config.php export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage.json
bin
.php_cs.cache
.vscode/
build/logs/*
23 changes: 23 additions & 0 deletions kahlan-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php // kahlan-config.php

use Kahlan\Filter\Filters;
use Kahlan\Reporter\Coverage;
use Kahlan\Reporter\Coverage\Driver\Xdebug;

Filters::apply($this, 'coverage', function($next) {
if (! extension_loaded('xdebug')) {
return;
}

$reporters = $this->reporters();
$coverage = new Coverage([
'verbosity' => $this->commandLine()->get('coverage'),
'driver' => new Xdebug(),
'path' => $this->commandLine()->get('src'),
'exclude' => [
'src/HeroAutoload.php',
],
'colors' => ! $this->commandLine()->get('no-colors')
]);
$reporters->add('coverage', $coverage);
});
34 changes: 34 additions & 0 deletions src/HeroAutoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace ErrorHeroModule;

use RuntimeException;

class HeroAutoload
{
public static function handle(string $class)
{
if (\class_exists($class)) {
return;
}

if (\in_array(
$class,
[
'error_reporting',
'error_get_last',
'ErrorHeroModuleLogger',
'ZendDeveloperTools\\ProfilerEvent',
]
)) {
return;
}

throw new RuntimeException(sprintf(
'class %s not found',
$class
));
}
}
2 changes: 2 additions & 0 deletions src/Listener/Mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Assert\Assertion;
use ErrorHeroModule\Handler\Logging;
use ErrorHeroModule\HeroAutoload;
use ErrorHeroModule\HeroTrait;
use Zend\Console\Response as ConsoleResponse;
use Zend\EventManager\AbstractListenerAggregate;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function phpError(MvcEvent $e) : void
{
\register_shutdown_function([$this, 'execOnShutdown']);
\set_error_handler([$this, 'phpErrorHandler']);
\spl_autoload_register([HeroAutoload::class, 'handle']);
}

public function exceptionError(MvcEvent $e) : void
Expand Down
2 changes: 2 additions & 0 deletions src/Middleware/Expressive.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Closure;
use Error;
use ErrorHeroModule\Handler\Logging;
use ErrorHeroModule\HeroAutoload;
use ErrorHeroModule\HeroTrait;
use Exception;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -60,6 +61,7 @@ public function phpError() : void
{
\register_shutdown_function([$this, 'execOnShutdown']);
\set_error_handler([$this, 'phpErrorHandler']);
\spl_autoload_register([HeroAutoload::class, 'handle']);
}

/**
Expand Down

0 comments on commit 53db924

Please sign in to comment.