3 * Used to render the console of PMA's pages
6 declare(strict_types
=1);
10 use PhpMyAdmin\Bookmarks\BookmarkRepository
;
11 use PhpMyAdmin\ConfigStorage\Relation
;
14 use function _ngettext
;
19 * Class used to output the console
24 * Whether to display anything
26 private bool $isEnabled = true;
29 * Whether we are servicing an ajax request.
31 private bool $isAjax = false;
32 private readonly Config
$config;
34 public function __construct(
35 private readonly Relation
$relation,
36 private readonly Template
$template,
37 private readonly BookmarkRepository
$bookmarkRepository,
39 $this->config
= Config
::getInstance();
43 * Set the ajax flag to indicate whether
44 * we are servicing an ajax request
46 * @param bool $isAjax Whether we are servicing an ajax request
48 public function setAjax(bool $isAjax): void
50 $this->isAjax
= $isAjax;
54 * Disables the rendering of the footer
56 public function disable(): void
58 $this->isEnabled
= false;
62 * Renders the bookmark content
64 public function getBookmarkContent(): string
66 $bookmarkFeature = $this->relation
->getRelationParameters()->bookmarkFeature
;
67 if ($bookmarkFeature === null) {
71 $bookmarks = $this->bookmarkRepository
->getList($this->config
->selectedServer
['user']);
72 $countBookmarks = count($bookmarks);
73 if ($countBookmarks > 0) {
74 $welcomeMessage = sprintf(
76 'Showing %1$d bookmark (both private and shared)',
77 'Showing %1$d bookmarks (both private and shared)',
83 $welcomeMessage = __('No bookmarks');
86 return $this->template
->render('console/bookmark_content', [
87 'welcome_message' => $welcomeMessage,
88 'bookmarks' => $bookmarks,
93 * Returns the list of JS scripts required by console
95 * @return string[] list of scripts
97 public function getScripts(): array
99 return ['console.js'];
103 * Renders the console
105 public function getDisplay(): string
107 if ($this->isAjax ||
! $this->isEnabled
) {
111 $bookmarkFeature = $this->relation
->getRelationParameters()->bookmarkFeature
;
112 $sqlHistory = $this->relation
->getHistory($this->config
->selectedServer
['user']);
113 $bookmarkContent = $this->getBookmarkContent();
115 return $this->template
->render('console/display', [
116 'settings' => $this->config
->config
->Console
->asArray(),
117 'has_bookmark_feature' => $bookmarkFeature !== null,
118 'sql_history' => $sqlHistory,
119 'bookmark_content' => $bookmarkContent,
120 'debug' => $this->config
->config
->debug
->sql
,