Skip to content

Commit

Permalink
Respect the result of any user-defined error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanshoover committed Feb 28, 2019
1 parent 8fd1e4d commit 544b855
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/Handlers/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,47 @@

class ErrorHandler extends AbstractHandler
{

public function register()
{
$this->previousHandler = set_error_handler(array($this, 'handle'));

parent::register();
}

public function handle()
{
/**
* Overloading methods with different parameters is not supported in PHP
* through language structures. This hack allows to simulate that.
*/
$args = func_get_args();

if (!isset($args[0]) || !isset($args[1])) {
throw new \Exception('No $errno or $errstr to be passed to the error handler.');
}

$errno = $args[0];
$errstr = $args[1];
$errfile = isset($args[2]) ? $args[2] : null;
$errline = isset($args[3]) ? $args[3] : null;

parent::handle();


if (!is_null($this->previous_handler)) {
$stop_processing = call_user_func(
$this->previous_handler,
$errno,
$errstr,
$errfile,
$errline
);

if ($stop_processing) {
return $stop_processing;
}
}

if (is_null($this->logger())) {
return false;
}
Expand All @@ -45,17 +59,7 @@ public function handle()
generateErrorWrapper($errno, $errstr, $errfile, $errline);

$this->logger()->log(Level::ERROR, $exception, array(), true);

if ($this->previousHandler !== null) {
call_user_func(
$this->previousHandler,
$errno,
$errstr,
$errfile,
$errline
);
}


return false;
}
}

0 comments on commit 544b855

Please sign in to comment.