Skip to content

Commit

Permalink
Fix Whoops displaying error page if there is PHP core warning or error (
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Feb 17, 2017
1 parent a3ccae5 commit 14bde9f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
1. [](#bugfix)
* Fix for double extensions getting added during some redirects [#1307](https://github.com/getgrav/grav/issues/1307)
* Fix syntax error in PHP 5.3. Move the version check before requiring the autoloaded deps
* Fix Whoops displaying error page if there is PHP core warning or error (#980)

# v1.1.16
## 02/10/2017
Expand Down
3 changes: 2 additions & 1 deletion system/src/Grav/Common/Errors/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function resetHandlers()
$jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json';

// Setup Whoops-based error handler
$whoops = new \Whoops\Run;
$system = new SystemFacade;
$whoops = new \Whoops\Run($system);

$verbosity = 1;

Expand Down
39 changes: 39 additions & 0 deletions system/src/Grav/Common/Errors/SystemFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @package Grav.Common.Errors
*
* @copyright Copyright (C) 2014 - 2016 RocketTheme, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

namespace Grav\Common\Errors;

class SystemFacade extends \Whoops\Util\SystemFacade
{
protected $whoopsShutdownHandler;

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

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

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

0 comments on commit 14bde9f

Please sign in to comment.