diff --git a/CLAUDE.md b/CLAUDE.md index 80bb3129e..546cabba1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,7 +10,7 @@ TorrentPier is a BitTorrent tracker engine written in PHP, designed for hosting - **PHP 8.3+** with modern features - **MySQL/MariaDB/Percona** database -- **Nette Database** with backward-compatible wrapper +- **Nette Database** with temporary backward-compatible wrapper - **Composer** for dependency management - **Custom BitTorrent tracker** implementation diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md index 8efa50b06..8e8dcdd45 100644 --- a/UPGRADE_GUIDE.md +++ b/UPGRADE_GUIDE.md @@ -474,7 +474,7 @@ The following legacy files have been removed from the codebase: These were completely replaced by: - `src/Database/Database.php` - Modern database class with Nette Database (renamed from `DB.php`) -- `src/Database/DatabaseFactory.php` - Modern factory with backward compatibility (renamed from `DbFactory.php`) +- `src/Database/DatabaseFactory.php` - Modern factory with temporary backward compatibility (renamed from `DbFactory.php`) - `src/Database/DatabaseDebugger.php` - Dedicated debug functionality extracted from Database class - `src/Database/DebugSelection.php` - Debug-enabled wrapper for Nette Database Selection diff --git a/src/Whoops/DatabaseErrorHandler.php b/src/Whoops/DatabaseErrorHandler.php index 8b0aa8392..7e8d20303 100644 --- a/src/Whoops/DatabaseErrorHandler.php +++ b/src/Whoops/DatabaseErrorHandler.php @@ -115,15 +115,14 @@ class DatabaseErrorHandler extends Handler implements HandlerInterface try { $databaseInfo = $this->collectDatabaseInformation(); - // Use reflection to add custom data to the exception - // This will appear in the Whoops error page + // Use Whoops' built-in method if available - this is the proper way if (method_exists($exception, 'setAdditionalInfo')) { $exception->setAdditionalInfo('Database Information', $databaseInfo); - } else { - // Fallback: store in a property that Whoops can access - if (!isset($exception->databaseInfo)) { - $exception->databaseInfo = $databaseInfo; - } + } + // For PHP 8.2+ compatibility: Avoid dynamic properties completely + // Instead, we'll add the info as frame comments on the first database-related frame + else { + $this->addDatabaseInfoAsFrameComments($databaseInfo); } } catch (\Exception $e) { // Don't let database info collection break error handling @@ -133,6 +132,29 @@ class DatabaseErrorHandler extends Handler implements HandlerInterface } } + /** + * Add database info as frame comments when setAdditionalInfo is not available + */ + private function addDatabaseInfoAsFrameComments(array $databaseInfo): void + { + $inspector = $this->getInspector(); + $frames = $inspector->getFrames(); + + // Find the first frame and add database info as comments + if (!empty($frames)) { + $firstFrame = $frames[0]; + $firstFrame->addComment('=== Database Information ===', ''); + + foreach ($databaseInfo as $key => $value) { + if (is_string($value) || is_numeric($value)) { + $firstFrame->addComment("DB Info - $key", $value); + } elseif (is_array($value) && !empty($value)) { + $firstFrame->addComment("DB Info - $key", json_encode($value, JSON_PRETTY_PRINT)); + } + } + } + } + /** * Check if a frame is related to database operations */