Implement JsonSerializable

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2023-12-14 18:21:41 +01:00
parent 2a3550e185
commit 044920addb
3 changed files with 16 additions and 14 deletions

View File

@ -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;

View File

@ -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(),
];
}
}

View File

@ -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),
];