1
0
mirror of https://github.com/phpmyadmin/phpmyadmin.git synced 2026-10-29 21:24:44 +03:00

Move /messages HTTP headers to the JavaScriptMessagesController

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth
2022-10-22 15:31:43 -03:00
parent a1f933d9cc
commit 9706987031
3 changed files with 19 additions and 25 deletions

View File

@@ -6,8 +6,11 @@ namespace PhpMyAdmin\Controllers;
use function __;
use function _pgettext;
use function gmdate;
use function header;
use function json_encode;
use function json_last_error_msg;
use function time;
/**
* Exporting of translated messages from PHP to JavaScript.
@@ -24,6 +27,7 @@ final class JavaScriptMessagesController
public function __invoke(): void
{
$this->setHTTPHeaders();
$messages = json_encode($this->messages);
if ($messages === false) {
echo '// Error when encoding messages: ' . json_last_error_msg();
@@ -34,6 +38,15 @@ final class JavaScriptMessagesController
echo 'window.Messages = ' . $messages . ';';
}
private function setHTTPHeaders(): void
{
// Send correct type.
header('Content-Type: text/javascript; charset=UTF-8');
// Cache output in client
// the nocache query parameter makes sure that this file is reloaded when config changes.
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
}
/**
* @return array<string, string>
*/