/** * Attempt to rebuild extension autoloader when a "Class not found" error * occurs. * * @param \Bolt\Application $app * @param array $error */ private static function attemptExtensionRecovery($app, $error) { $cwd = getcwd(); if ($error['type'] === E_ERROR && strpos($error['message'], 'Class') === 0) { $path = $_SERVER['PATH_INFO']; if (isset($_SERVER['QUERY_STRING'])) { if (strpos($_SERVER['QUERY_STRING'], 'rebuild-autoloader') !== false) { header("location: {$path}?rebuild-done"); } elseif (strpos($_SERVER['QUERY_STRING'], 'rebuild-done') !== false) { chdir($cwd); return; } } restore_error_handler(); $html = self::$html; $html = str_replace('%error_title%', 'PHP Fatal Error: Bolt Extensions Class Loader', $html); $message = '<b>Attempting to rebuild extension autoloader</b>'; $message .= "<p>Redirecting to <a href='{$path}?rebuild-autoloader'>{$path}</a> on completion.</p>"; $message .= "<script>window.setTimeout(function () { window.location='{$path}?rebuild-autoloader'; }, 5000);</script>"; $message = nl2br($message); $html = str_replace('%error%', $message, $html); $html = str_replace('%info%', '', $html); if (php_sapi_name() == 'cli') { $html = self::cleanHTML($html) . "\n\n"; } echo $html; $app['extend.enabled'] = false; $app['extensions']->checkLocalAutoloader(true); $html = '<div style="max-width: 640px; margin: auto;"><p class="status-ok">Completed rebuild… Attempting reload!</p>'; if (php_sapi_name() == 'cli') { $html = self::cleanHTML($html) . "\n\n"; } echo $html; // Reboot the application and retry loading chdir($cwd); $app->boot(); $app->abort(Response::HTTP_MOVED_PERMANENTLY); } }