Charset.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Value object class for a character set
  4. * @package PhpMyAdmin\Charsets
  5. */
  6. declare(strict_types=1);
  7. namespace PhpMyAdmin\Charsets;
  8. /**
  9. * Value object class for a character set
  10. * @package PhpMyAdmin\Charsets
  11. */
  12. final class Charset
  13. {
  14. /**
  15. * The character set name
  16. * @var string
  17. */
  18. private $name;
  19. /**
  20. * A description of the character set
  21. * @var string
  22. */
  23. private $description;
  24. /**
  25. * The default collation for the character set
  26. * @var string
  27. */
  28. private $defaultCollation;
  29. /**
  30. * The maximum number of bytes required to store one character
  31. * @var int
  32. */
  33. private $maxLength;
  34. /**
  35. * @param string $name Charset name
  36. * @param string $description Description
  37. * @param string $defaultCollation Default collation
  38. * @param int $maxLength Maximum length
  39. */
  40. private function __construct(
  41. string $name,
  42. string $description,
  43. string $defaultCollation,
  44. int $maxLength
  45. ) {
  46. $this->name = $name;
  47. $this->description = $description;
  48. $this->defaultCollation = $defaultCollation;
  49. $this->maxLength = $maxLength;
  50. }
  51. /**
  52. * @param array $state State obtained from the database server
  53. * @return Charset
  54. */
  55. public static function fromServer(array $state): self
  56. {
  57. return new self(
  58. $state['Charset'] ?? '',
  59. $state['Description'] ?? '',
  60. $state['Default collation'] ?? '',
  61. (int) ($state['Maxlen'] ?? 0)
  62. );
  63. }
  64. /**
  65. * @return string
  66. */
  67. public function getName(): string
  68. {
  69. return $this->name;
  70. }
  71. /**
  72. * @return string
  73. */
  74. public function getDescription(): string
  75. {
  76. return $this->description;
  77. }
  78. /**
  79. * @return string
  80. */
  81. public function getDefaultCollation(): string
  82. {
  83. return $this->defaultCollation;
  84. }
  85. /**
  86. * @return int
  87. */
  88. public function getMaxLength(): int
  89. {
  90. return $this->maxLength;
  91. }
  92. }