Skip to content

Commit

Permalink
Make Whoops not to report PHP startup errors and warnings (#1821)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jan 27, 2017
1 parent 0671989 commit a54790d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 5.4.7
## xx/xx/2017

1. [Common](#common)
2. [](#improved)
- Make Whoops not to report PHP startup errors and warnings (#1821)

# 5.4.6
## 26/01/2017

Expand Down
27 changes: 27 additions & 0 deletions src/classes/Gantry/Component/Whoops/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class System extends SystemFacade
protected $registeredPatterns;
protected $whoopsErrorHandler;
protected $whoopsExceptionHandler;
protected $whoopsShutdownHandler;
protected $platformExceptionHandler;

/**
Expand Down Expand Up @@ -53,6 +54,17 @@ public function setErrorHandler(callable $handler, $types = 'use-php-defaults')
return parent::setErrorHandler([$this, 'handleError'], $types);
}

/**
* @param callable $function
*
* @return void
*/
public function registerShutdownFunction(callable $function)
{
$this->whoopsShutdownHandler = $function;
register_shutdown_function([$this, 'handleShutdown']);
}

/**
* @param callable $handler
*
Expand Down Expand Up @@ -130,4 +142,19 @@ public function handleException($exception)
call_user_func_array($this->platformExceptionHandler, [&$exception]);
}
}

/**
* Special case to deal with Fatal errors and the like.
*/
public function handleShutdown()
{
$handler = $this->whoopsShutdownHandler;

$error = $this->getLastError();

// Ignore core warnings and errors.
if ($error && !($error['type'] & (E_CORE_WARNING | E_CORE_ERROR))) {
$handler();
}
}
}

0 comments on commit a54790d

Please sign in to comment.