PocketMine-MP 5.15.1 git-fb9a74e8799c71ed8292cfa53abe7a4c9204629d
CrashDumpRenderer.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\crash;
25
28use function count;
29use function date;
30use function fwrite;
31use function implode;
32use const PHP_EOL;
33
35
39 public function __construct(private $fp, private CrashDumpData $data){
40
41 }
42
43 public function renderHumanReadable() : void{
44 $this->addLine($this->data->general->name . " Crash Dump " . date("D M j H:i:s T Y", (int) $this->data->time));
45 $this->addLine();
46
47 $version = new VersionString($this->data->general->base_version, $this->data->general->is_dev, $this->data->general->build);
48 $this->addLine($this->data->general->name . " version: " . $version->getFullVersion(true) . " [Protocol " . $this->data->general->protocol . "]");
49 $this->addLine("Git commit: " . $this->data->general->git);
50 $this->addLine("PHP version: " . $this->data->general->php);
51 $this->addLine("OS: " . $this->data->general->php_os . ", " . $this->data->general->os);
52
53 if($this->data->plugin_involvement !== CrashDump::PLUGIN_INVOLVEMENT_NONE){
54 $this->addLine();
55 $this->addLine(match($this->data->plugin_involvement){
56 CrashDump::PLUGIN_INVOLVEMENT_DIRECT => "THIS CRASH WAS CAUSED BY A PLUGIN",
57 CrashDump::PLUGIN_INVOLVEMENT_INDIRECT => "A PLUGIN WAS INVOLVED IN THIS CRASH",
58 default => "Unknown plugin involvement!"
59 });
60 }
61 if($this->data->plugin !== ""){
62 $this->addLine("BAD PLUGIN: " . $this->data->plugin);
63 }
64
65 $this->addLine();
66
67 $this->addLine("Thread: " . $this->data->thread);
68 $this->addLine("Error: " . $this->data->error["message"]);
69 $this->addLine("File: " . $this->data->error["file"]);
70 $this->addLine("Line: " . $this->data->error["line"]);
71 $this->addLine("Type: " . $this->data->error["type"]);
72 $this->addLine("Backtrace:");
73 foreach($this->data->trace as $line){
74 $this->addLine($line);
75 }
76
77 $this->addLine();
78 $this->addLine("Code:");
79
80 foreach($this->data->code as $lineNumber => $line){
81 $this->addLine("[$lineNumber] $line");
82 }
83
84 if(count($this->data->plugins) > 0){
85 $this->addLine();
86 $this->addLine("Loaded plugins:");
87 foreach($this->data->plugins as $p){
88 $this->addLine($p->name . " " . $p->version . " by " . implode(", ", $p->authors) . " for API(s) " . implode(", ", $p->api));
89 }
90 }
91
92 $this->addLine();
93 $this->addLine("uname -a: " . $this->data->general->uname);
94 $this->addLine("Zend version: " . $this->data->general->zend);
95 $this->addLine("Composer libraries: ");
96 foreach(Utils::stringifyKeys($this->data->general->composer_libraries) as $library => $libraryVersion){
97 $this->addLine("- $library $libraryVersion");
98 }
99 }
100
101 public function addLine(string $line = "") : void{
102 fwrite($this->fp, $line . PHP_EOL);
103 }
104}
__construct(private $fp, private CrashDumpData $data)
static stringifyKeys(array $array)
Definition: Utils.php:605