phpmyadmin/libraries/classes/Controllers/ConfigController.php
Maurício Meneghini Fauth bd2ef2b8ee
Get post params from ServerRequest class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2021-08-30 17:45:28 -03:00

68 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Config;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use function json_decode;
final class ConfigController extends AbstractController
{
/** @var Config */
private $config;
/**
* @param ResponseRenderer $response
*/
public function __construct($response, Template $template, Config $config)
{
parent::__construct($response, $template);
$this->config = $config;
}
public function get(ServerRequest $request): void
{
/** @var string|null $key */
$key = $request->getParsedBodyParam('key');
if (! isset($key)) {
$this->response->setRequestStatus(false);
$this->response->addJSON(['message' => Message::error()]);
return;
}
$this->response->addJSON(['value' => $this->config->get($key)]);
}
public function set(ServerRequest $request): void
{
/** @var string|null $key */
$key = $request->getParsedBodyParam('key');
/** @var string|null $value */
$value = $request->getParsedBodyParam('value');
if (! isset($key, $value)) {
$this->response->setRequestStatus(false);
$this->response->addJSON(['message' => Message::error()]);
return;
}
$result = $this->config->setUserValue(null, $key, json_decode($value));
if ($result === true) {
return;
}
$this->response->setRequestStatus(false);
$this->response->addJSON(['message' => $result]);
}
}