Skip to content

Commit 544c933

Browse files
committed
Fix visualization issue
1 parent bbaf3b9 commit 544c933

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/Controllers/DatabaseController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function getDatabaseNames() : array {
2222
$databaseNames[] = $databaseInfo['name'];
2323
}
2424
} catch (\Throwable $th) {
25-
ErrorNormalizer::prettyPrint($th); exit;
25+
ErrorNormalizer::prettyPrintAndDie($th);
2626
}
2727

2828
}
@@ -68,21 +68,19 @@ public function getNetworkGraphAction() : Response {
6868

6969
try {
7070

71-
foreach (MongoDBHelper::getClient()->listDatabases() as $databaseInfo) {
71+
foreach (self::getDatabaseNames() as $databaseName) {
7272

7373
$nodeCounter++;
7474

7575
$databaseNode = [
7676
'id' => $nodeCounter,
77-
'label' => 'DB: ' . $databaseInfo['name'],
77+
'label' => 'DB: ' . $databaseName,
7878
'shape' => 'image',
7979
'image' => MPG_BASE_URL . '/static/images/database-icon.svg',
8080
'size' => 24
8181
];
8282

83-
$database = MongoDBHelper::getClient()->selectDatabase(
84-
$databaseInfo['name']
85-
);
83+
$database = MongoDBHelper::getClient()->selectDatabase($databaseName);
8684

8785
foreach ($database->listCollections() as $collectionInfo) {
8886

@@ -104,7 +102,7 @@ public function getNetworkGraphAction() : Response {
104102
]);
105103

106104
$networkGraph['mapping'][ $collectionNode['id'] ] = [
107-
'databaseName' => $databaseInfo['name'],
105+
'databaseName' => $databaseName,
108106
'collectionName' => $collectionInfo['name']
109107
];
110108

@@ -118,7 +116,7 @@ public function getNetworkGraphAction() : Response {
118116
]);
119117

120118
$networkGraph['mapping'][ $databaseNode['id'] ] = [
121-
'databaseName' => $databaseInfo['name'],
119+
'databaseName' => $databaseName,
122120
'collectionName' => null
123121
];
124122

src/Normalizers/ErrorNormalizer.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@ public static function normalize(\Throwable $error, string $function = null) : a
3232
}
3333

3434
/**
35-
* Normalizes then prints an error prettily.
35+
* Normalizes then prints an error prettily then terminates script.
3636
*
3737
* @param \Throwable $error
3838
*/
39-
public static function prettyPrint(\Throwable $error) {
39+
public static function prettyPrintAndDie(\Throwable $error) {
4040

41-
echo '<pre>' . print_r(self::normalize($error), true) . '</pre>';
41+
http_response_code(500);
42+
header('Content-Type: application/json');
43+
44+
echo json_encode(self::normalize($error), JSON_PRETTY_PRINT);
45+
46+
die;
4247

4348
}
4449

0 commit comments

Comments
 (0)