ConfigController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers;
  4. use PhpMyAdmin\Config;
  5. use PhpMyAdmin\Message;
  6. use PhpMyAdmin\Response;
  7. use PhpMyAdmin\Template;
  8. use function json_decode;
  9. final class ConfigController extends AbstractController
  10. {
  11. /** @var Config */
  12. private $config;
  13. /**
  14. * @param Response $response
  15. */
  16. public function __construct($response, Template $template, Config $config)
  17. {
  18. parent::__construct($response, $template);
  19. $this->config = $config;
  20. }
  21. public function get(): void
  22. {
  23. if (! isset($_POST['key'])) {
  24. $this->response->setRequestStatus(false);
  25. $this->response->addJSON(['message' => Message::error()]);
  26. return;
  27. }
  28. $this->response->addJSON(['value' => $this->config->get($_POST['key'])]);
  29. }
  30. public function set(): void
  31. {
  32. if (! isset($_POST['key'], $_POST['value'])) {
  33. $this->response->setRequestStatus(false);
  34. $this->response->addJSON(['message' => Message::error()]);
  35. return;
  36. }
  37. $result = $this->config->setUserValue(null, $_POST['key'], json_decode($_POST['value']));
  38. if ($result === true) {
  39. return;
  40. }
  41. $this->response->setRequestStatus(false);
  42. $this->response->addJSON(['message' => $result]);
  43. }
  44. }