CollationsController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Server;
  4. use PhpMyAdmin\Charsets;
  5. use PhpMyAdmin\Charsets\Charset;
  6. use PhpMyAdmin\Charsets\Collation;
  7. use PhpMyAdmin\Controllers\AbstractController;
  8. use PhpMyAdmin\DatabaseInterface;
  9. use PhpMyAdmin\Response;
  10. use PhpMyAdmin\Template;
  11. use PhpMyAdmin\Url;
  12. /**
  13. * Handles viewing character sets and collations
  14. */
  15. class CollationsController extends AbstractController
  16. {
  17. /** @var array|null */
  18. private $charsets;
  19. /** @var array|null */
  20. private $collations;
  21. /** @var DatabaseInterface */
  22. private $dbi;
  23. /**
  24. * @param Response $response
  25. * @param DatabaseInterface $dbi
  26. * @param array|null $charsets Array of charsets
  27. * @param array|null $collations Array of collations
  28. */
  29. public function __construct(
  30. $response,
  31. Template $template,
  32. $dbi,
  33. ?array $charsets = null,
  34. ?array $collations = null
  35. ) {
  36. global $cfg;
  37. parent::__construct($response, $template);
  38. $this->dbi = $dbi;
  39. $this->charsets = $charsets ?? Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
  40. $this->collations = $collations ?? Charsets::getCollations($this->dbi, $cfg['Server']['DisableIS']);
  41. }
  42. public function index(): void
  43. {
  44. global $err_url;
  45. $err_url = Url::getFromRoute('/');
  46. if ($this->dbi->isSuperUser()) {
  47. $this->dbi->selectDb('mysql');
  48. }
  49. $charsets = [];
  50. /** @var Charset $charset */
  51. foreach ($this->charsets as $charset) {
  52. $charsetCollations = [];
  53. /** @var Collation $collation */
  54. foreach ($this->collations[$charset->getName()] as $collation) {
  55. $charsetCollations[] = [
  56. 'name' => $collation->getName(),
  57. 'description' => $collation->getDescription(),
  58. 'is_default' => $collation->isDefault(),
  59. ];
  60. }
  61. $charsets[] = [
  62. 'name' => $charset->getName(),
  63. 'description' => $charset->getDescription(),
  64. 'collations' => $charsetCollations,
  65. ];
  66. }
  67. $this->render('server/collations/index', ['charsets' => $charsets]);
  68. }
  69. }