Charset.php 1.9 KB

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