CollationsController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Holds the PhpMyAdmin\Controllers\Server\CollationsController
  5. *
  6. * @package PhpMyAdmin\Controllers
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Controllers\Server;
  10. use PhpMyAdmin\Charsets;
  11. use PhpMyAdmin\Charsets\Charset;
  12. use PhpMyAdmin\Charsets\Collation;
  13. use PhpMyAdmin\Controllers\AbstractController;
  14. use PhpMyAdmin\DatabaseInterface;
  15. use PhpMyAdmin\Response;
  16. use PhpMyAdmin\Template;
  17. /**
  18. * Handles viewing character sets and collations
  19. *
  20. * @package PhpMyAdmin\Controllers
  21. */
  22. class CollationsController extends AbstractController
  23. {
  24. /**
  25. * @var array|null
  26. */
  27. private $charsets;
  28. /**
  29. * @var array|null
  30. */
  31. private $collations;
  32. /**
  33. * CollationsController constructor.
  34. *
  35. * @param Response $response Response object
  36. * @param DatabaseInterface $dbi DatabaseInterface object
  37. * @param Template $template Template object
  38. * @param array|null $charsets Array of charsets
  39. * @param array|null $collations Array of collations
  40. */
  41. public function __construct(
  42. $response,
  43. $dbi,
  44. Template $template,
  45. ?array $charsets = null,
  46. ?array $collations = null
  47. ) {
  48. global $cfg;
  49. parent::__construct($response, $dbi, $template);
  50. $this->charsets = $charsets ?? Charsets::getCharsets(
  51. $this->dbi,
  52. $cfg['Server']['DisableIS']
  53. );
  54. $this->collations = $collations ?? Charsets::getCollations(
  55. $this->dbi,
  56. $cfg['Server']['DisableIS']
  57. );
  58. }
  59. /**
  60. * Index action
  61. *
  62. * @return string HTML
  63. */
  64. public function indexAction(): string
  65. {
  66. include_once ROOT_PATH . 'libraries/server_common.inc.php';
  67. $charsets = [];
  68. /** @var Charset $charset */
  69. foreach ($this->charsets as $charset) {
  70. $charsetCollations = [];
  71. /** @var Collation $collation */
  72. foreach ($this->collations[$charset->getName()] as $collation) {
  73. $charsetCollations[] = [
  74. 'name' => $collation->getName(),
  75. 'description' => $collation->getDescription(),
  76. 'is_default' => $collation->isDefault(),
  77. ];
  78. }
  79. $charsets[] = [
  80. 'name' => $charset->getName(),
  81. 'description' => $charset->getDescription(),
  82. 'collations' => $charsetCollations,
  83. ];
  84. }
  85. return $this->template->render('server/collations/index', [
  86. 'charsets' => $charsets,
  87. ]);
  88. }
  89. }