Index.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Setup\Declaration\Schema\Dto;
  7. /**
  8. * Index structural element.
  9. * Used to speedup read operations from SQL database.
  10. */
  11. class Index extends GenericElement implements
  12. ElementInterface,
  13. TableElementInterface,
  14. ElementDiffAwareInterface
  15. {
  16. /**
  17. * Element type.
  18. */
  19. const TYPE = 'index';
  20. /**
  21. * Fulltext index type.
  22. */
  23. const FULLTEXT_INDEX = "fulltext";
  24. /**
  25. * @var Table
  26. */
  27. private $table;
  28. /**
  29. * @var array
  30. */
  31. private $columns;
  32. /**
  33. * @var string
  34. */
  35. private $indexType;
  36. /**
  37. * @var string
  38. */
  39. private $nameWithoutPrefix;
  40. /**
  41. * Constructor.
  42. *
  43. * @param string $name
  44. * @param string $type
  45. * @param Table $table
  46. * @param array $columns
  47. * @param string $indexType
  48. * @param string $nameWithoutPrefix
  49. */
  50. public function __construct(
  51. string $name,
  52. string $type,
  53. Table $table,
  54. array $columns,
  55. string $indexType,
  56. string $nameWithoutPrefix
  57. ) {
  58. parent::__construct($name, $type);
  59. $this->table = $table;
  60. $this->columns = $columns;
  61. $this->indexType = $indexType;
  62. $this->nameWithoutPrefix = $nameWithoutPrefix;
  63. }
  64. /**
  65. * Return columns in order, in which they should go in composite index.
  66. *
  67. * @return Column[]
  68. */
  69. public function getColumns()
  70. {
  71. return $this->columns;
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function getTable()
  77. {
  78. return $this->table;
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function getDiffSensitiveParams()
  84. {
  85. return [
  86. 'type' => $this->getType(),
  87. 'columns' => $this->getColumnNames(),
  88. 'indexType' => $this->getIndexType()
  89. ];
  90. }
  91. /**
  92. * Retrieve array with column names from column objects collections.
  93. *
  94. * @return array
  95. */
  96. public function getColumnNames()
  97. {
  98. return array_map(
  99. function (Column $column) {
  100. return $column->getName();
  101. },
  102. $this->getColumns()
  103. );
  104. }
  105. /**
  106. * {@inheritdoc}
  107. */
  108. public function getElementType()
  109. {
  110. return self::TYPE;
  111. }
  112. /**
  113. * Get index type (FULLTEXT, BTREE, HASH).
  114. *
  115. * @return string
  116. */
  117. public function getIndexType()
  118. {
  119. return $this->indexType;
  120. }
  121. /**
  122. * Retrieve the index name which is calculated without table prefix.
  123. *
  124. * @return string
  125. */
  126. public function getNameWithoutPrefix()
  127. {
  128. return $this->nameWithoutPrefix;
  129. }
  130. }