Skip to content

Commit 17ac066

Browse files
Merge pull request #18846 from kamil-tekiela/favorites-jsonserializable
Implement JsonSerializable
2 parents 2a3550e + 044920a commit 17ac066

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/Controllers/Database/Structure/FavoriteTableController.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use PhpMyAdmin\Util;
2222

2323
use function __;
24-
use function array_map;
2524
use function count;
2625
use function json_decode;
2726
use function json_encode;
@@ -114,10 +113,7 @@ public function __invoke(ServerRequest $request): void
114113
}
115114
}
116115

117-
$favoriteTables[$user] = array_map(
118-
static fn (RecentFavoriteTable $table) => $table->toArray(),
119-
$favoriteInstance->getTables(),
120-
);
116+
$favoriteTables[$user] = $favoriteInstance->getTables();
121117

122118
$json = [];
123119
$json['changes'] = $changes;
@@ -174,10 +170,7 @@ private function synchronizeFavoriteTables(
174170
}
175171
}
176172

177-
$favoriteTables[$user] = array_map(
178-
static fn (RecentFavoriteTable $table) => $table->toArray(),
179-
$favoriteInstance->getTables(),
180-
);
173+
$favoriteTables[$user] = $favoriteInstance->getTables();
181174

182175
// Set flag when localStorage and pmadb(if present) are in sync.
183176
$_SESSION['tmpval']['favorites_synced'][$GLOBALS['server']] = true;

src/Favorites/RecentFavoriteTable.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
namespace PhpMyAdmin\Favorites;
66

7+
use JsonSerializable;
78
use PhpMyAdmin\Identifiers\DatabaseName;
89
use PhpMyAdmin\Identifiers\TableName;
910

10-
final class RecentFavoriteTable
11+
final class RecentFavoriteTable implements JsonSerializable
1112
{
1213
public function __construct(public readonly DatabaseName $db, public readonly TableName $table)
1314
{
@@ -24,4 +25,12 @@ public function toArray(): array
2425
{
2526
return ['db' => $this->db->getName(), 'table' => $this->table->getName()];
2627
}
28+
29+
public function jsonSerialize(): mixed
30+
{
31+
return [
32+
'db' => $this->db->getName(),
33+
'table' => $this->table->getName(),
34+
];
35+
}
2736
}

src/Favorites/RecentFavoriteTables.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ public function getHtmlList(): string
203203
$tables = [];
204204
foreach ($this->tables as $table) {
205205
$removeParameters = [
206-
'db' => $table->db,
206+
'db' => $table->db->getName(),
207+
'favorite_table' => $table->table->getName(),
207208
'ajax_request' => true,
208-
'favorite_table' => $table->table,
209209
'remove_favorite' => true,
210210
];
211211
$tableParameters = [
212-
'db' => $table->db,
213-
'table' => $table->table,
212+
'db' => $table->db->getName(),
213+
'table' => $table->table->getName(),
214214
'md5' => md5($table->db . '.' . $table->table),
215215
];
216216

0 commit comments

Comments
 (0)