diff --git a/src/TracyBlueScreenDebugger.php b/src/TracyBlueScreenDebugger.php new file mode 100644 index 0000000..05abcbb --- /dev/null +++ b/src/TracyBlueScreenDebugger.php @@ -0,0 +1,148 @@ + 'ORM error', + 'panel' => '

' . htmlspecialchars($e->getMessage()) . '

', + ]; + } + + + /** + * @param DriverException $e + * @return string[] + */ + private static function renderDriver(DriverException $e): array + { + if (preg_match('/while executing \'(.+)\' with params (.+):(?:\n\s)+(.+)/', $e->getMessage(), $parser)) { + return [ + 'tab' => 'Driver error | ' . $parser[3], + 'panel' => '
' . QueryUtils::highlight($parser[1]) . '
' + . '

With params:

' . Dumper::toHtml(json_decode($parser[2])), + ]; + } + + if (preg_match('/while executing \'(.+)\'/', $e->getMessage(), $parser)) { + return [ + 'tab' => 'Driver error', + 'panel' => '
' . QueryUtils::highlight($parser[1]) . '
', + ]; + } + + return [ + 'tab' => 'Driver error', + 'panel' => '

' . htmlspecialchars($e->getMessage()) . '

', + ]; + } + + + /** + * @param QueryException $e + * @return string[] + */ + private static function renderQuery(QueryException $e): array + { + return [ + 'tab' => 'Query error', + 'panel' => '

' . htmlspecialchars($e->getMessage()) . '

', + ]; + } + + + /** + * @param MappingException $e + * @return string[] + */ + private static function renderMapping(MappingException $e): array + { + if (preg_match('/Class "([^"]+)"/', $e->getMessage(), $parser)) { + if (class_exists($className = $parser[1]) === true) { + $fileName = null; + $fileContent = null; + $docComment = ''; + $startLine = 1; + try { + $fileName = ($ref = new \ReflectionClass($className))->getFileName(); + $fileContent = \is_file($fileName) ? file_get_contents($fileName) : null; + $startLine = $ref->getStartLine(); + $docComment = trim((string) $ref->getDocComment()); + } catch (\ReflectionException $e) { + } + + if ($fileName !== null && $fileContent !== null) { + return [ + 'tab' => 'Mapping error', + 'panel' => '

Class ' . htmlspecialchars($className) . ', path: ' . htmlspecialchars($fileName) . '

' + . BlueScreen::highlightPhp(htmlspecialchars($fileContent, ENT_IGNORE, 'UTF-8'), $startLine) + . '

Doc comment:

' + . ($docComment === '' ? 'Doc comment is empty.' : '
' . htmlspecialchars($docComment) . '
'), + ]; + } + } + + return [ + 'tab' => 'Mapping error', + 'panel' => '

Class "' . htmlspecialchars($className) . '" does not exist!

' + . '

' . htmlspecialchars($e->getMessage()) . '

', + ]; + } + + return [ + 'tab' => 'Mapping error', + 'panel' => '

' . htmlspecialchars($e->getMessage()) . '

', + ]; + } +}