MySQLField.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Wikimedia\Rdbms;
  3. class MySQLField implements Field {
  4. private $name, $tablename, $default, $max_length, $nullable,
  5. $is_pk, $is_unique, $is_multiple, $is_key, $type, $binary,
  6. $is_numeric, $is_blob, $is_unsigned, $is_zerofill;
  7. function __construct( $info ) {
  8. $this->name = $info->name;
  9. $this->tablename = $info->table;
  10. $this->default = $info->def;
  11. $this->max_length = $info->max_length;
  12. $this->nullable = !$info->not_null;
  13. $this->is_pk = $info->primary_key;
  14. $this->is_unique = $info->unique_key;
  15. $this->is_multiple = $info->multiple_key;
  16. $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple );
  17. $this->type = $info->type;
  18. $this->binary = $info->binary ?? false;
  19. $this->is_numeric = $info->numeric ?? false;
  20. $this->is_blob = $info->blob ?? false;
  21. $this->is_unsigned = $info->unsigned ?? false;
  22. $this->is_zerofill = $info->zerofill ?? false;
  23. }
  24. /**
  25. * @return string
  26. */
  27. function name() {
  28. return $this->name;
  29. }
  30. /**
  31. * @return string
  32. */
  33. function tableName() {
  34. return $this->tablename;
  35. }
  36. /**
  37. * @return string
  38. */
  39. function type() {
  40. return $this->type;
  41. }
  42. /**
  43. * @return bool
  44. */
  45. function isNullable() {
  46. return $this->nullable;
  47. }
  48. function defaultValue() {
  49. return $this->default;
  50. }
  51. /**
  52. * @return bool
  53. */
  54. function isKey() {
  55. return $this->is_key;
  56. }
  57. /**
  58. * @return bool
  59. */
  60. function isMultipleKey() {
  61. return $this->is_multiple;
  62. }
  63. /**
  64. * @return bool
  65. */
  66. function isBinary() {
  67. return $this->binary;
  68. }
  69. /**
  70. * @return bool
  71. */
  72. function isNumeric() {
  73. return $this->is_numeric;
  74. }
  75. /**
  76. * @return bool
  77. */
  78. function isBlob() {
  79. return $this->is_blob;
  80. }
  81. /**
  82. * @return bool
  83. */
  84. function isUnsigned() {
  85. return $this->is_unsigned;
  86. }
  87. /**
  88. * @return bool
  89. */
  90. function isZerofill() {
  91. return $this->is_zerofill;
  92. }
  93. }