From 044920addbf2ba711717d048d45a603ab4e05921 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 14 Dec 2023 18:21:41 +0100 Subject: [PATCH] Implement JsonSerializable Signed-off-by: Kamil Tekiela --- .../Database/Structure/FavoriteTableController.php | 11 ++--------- src/Favorites/RecentFavoriteTable.php | 11 ++++++++++- src/Favorites/RecentFavoriteTables.php | 8 ++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Controllers/Database/Structure/FavoriteTableController.php b/src/Controllers/Database/Structure/FavoriteTableController.php index ffa375f7b6..cb1d4d7660 100644 --- a/src/Controllers/Database/Structure/FavoriteTableController.php +++ b/src/Controllers/Database/Structure/FavoriteTableController.php @@ -21,7 +21,6 @@ use PhpMyAdmin\Url; use PhpMyAdmin\Util; use function __; -use function array_map; use function count; use function json_decode; use function json_encode; @@ -114,10 +113,7 @@ final class FavoriteTableController extends AbstractController } } - $favoriteTables[$user] = array_map( - static fn (RecentFavoriteTable $table) => $table->toArray(), - $favoriteInstance->getTables(), - ); + $favoriteTables[$user] = $favoriteInstance->getTables(); $json = []; $json['changes'] = $changes; @@ -174,10 +170,7 @@ final class FavoriteTableController extends AbstractController } } - $favoriteTables[$user] = array_map( - static fn (RecentFavoriteTable $table) => $table->toArray(), - $favoriteInstance->getTables(), - ); + $favoriteTables[$user] = $favoriteInstance->getTables(); // Set flag when localStorage and pmadb(if present) are in sync. $_SESSION['tmpval']['favorites_synced'][$GLOBALS['server']] = true; diff --git a/src/Favorites/RecentFavoriteTable.php b/src/Favorites/RecentFavoriteTable.php index 8277a62224..a0b941a5e2 100644 --- a/src/Favorites/RecentFavoriteTable.php +++ b/src/Favorites/RecentFavoriteTable.php @@ -4,10 +4,11 @@ declare(strict_types=1); namespace PhpMyAdmin\Favorites; +use JsonSerializable; use PhpMyAdmin\Identifiers\DatabaseName; use PhpMyAdmin\Identifiers\TableName; -final class RecentFavoriteTable +final class RecentFavoriteTable implements JsonSerializable { public function __construct(public readonly DatabaseName $db, public readonly TableName $table) { @@ -24,4 +25,12 @@ final class RecentFavoriteTable { return ['db' => $this->db->getName(), 'table' => $this->table->getName()]; } + + public function jsonSerialize(): mixed + { + return [ + 'db' => $this->db->getName(), + 'table' => $this->table->getName(), + ]; + } } diff --git a/src/Favorites/RecentFavoriteTables.php b/src/Favorites/RecentFavoriteTables.php index 6792f95ae0..bae4e54a65 100644 --- a/src/Favorites/RecentFavoriteTables.php +++ b/src/Favorites/RecentFavoriteTables.php @@ -203,14 +203,14 @@ class RecentFavoriteTables $tables = []; foreach ($this->tables as $table) { $removeParameters = [ - 'db' => $table->db, + 'db' => $table->db->getName(), + 'favorite_table' => $table->table->getName(), 'ajax_request' => true, - 'favorite_table' => $table->table, 'remove_favorite' => true, ]; $tableParameters = [ - 'db' => $table->db, - 'table' => $table->table, + 'db' => $table->db->getName(), + 'table' => $table->table->getName(), 'md5' => md5($table->db . '.' . $table->table), ];