| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Boot-failure shutdown handler. |
| 8 |
* |
| 9 |
* Defines abj404_boot_shutdown_handler(), which captures compile/parse fatals in |
| 10 |
* the plugin's files during PHP shutdown and stores them in a transient so the |
| 11 |
* degraded admin page can display the error on the next request. This matters on |
| 12 |
* PHP 7.4 where syntax errors in required files produce an uncatchable |
| 13 |
* E_COMPILE_ERROR. |
| 14 |
* |
| 15 |
* The register_shutdown_function() call that wires this handler stays in |
| 16 |
* 404-solution.php (it must run as part of the boot sequence, before Loader.php |
| 17 |
* is required). This file only defines the function. |
| 18 |
*/ |
| 19 |
// allow-no-test-found: boot-time global function (abj404_boot_shutdown_handler) wired via register_shutdown_function in 404-solution.php before the autoloader; it captures uncatchable E_COMPILE_ERROR fatals during real PHP shutdown, which cannot be reproduced in-process, so there is no isolated unit seam. |
| 20 |
|
| 21 |
// Minimal shutdown handler: catches compile/parse fatals in plugin files and |
| 22 |
// stores them in a transient so the degraded admin page can display the error |
| 23 |
// on the next request. This is important for PHP 7.4 where syntax errors in |
| 24 |
// required files produce uncatchable E_COMPILE_ERROR. |
| 25 |
if (!function_exists('abj404_boot_shutdown_handler')) { |
| 26 |
/** @return void */ |
| 27 |
function abj404_boot_shutdown_handler() { |
| 28 |
if ($GLOBALS['abj404_boot_ok']) { |
| 29 |
return; |
| 30 |
} |
| 31 |
$error = error_get_last(); |
| 32 |
if ($error === null) { |
| 33 |
return; |
| 34 |
} |
| 35 |
// Only capture fatal/compile errors in our plugin files. |
| 36 |
$fatalTypes = E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR; |
| 37 |
if (!($error['type'] & $fatalTypes)) { |
| 38 |
return; |
| 39 |
} |
| 40 |
$pluginDir = defined('ABJ404_PATH') ? ABJ404_PATH : dirname(dirname(__DIR__)) . '/'; |
| 41 |
if (strpos($error['file'], $pluginDir) === false) { |
| 42 |
return; |
| 43 |
} |
| 44 |
$errorInfo = array( |
| 45 |
'message' => $error['message'], |
| 46 |
'file' => $error['file'], |
| 47 |
'line' => $error['line'], |
| 48 |
'type' => $error['type'], |
| 49 |
'time' => abj404_now(), |
| 50 |
); |
| 51 |
// Use update_option as a fallback: set_transient might not be available |
| 52 |
// during a fatal shutdown. |
| 53 |
if (function_exists('set_transient')) { |
| 54 |
set_transient('abj404_boot_fatal', $errorInfo, 3600); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|