Statement.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\Db;
  7. /**
  8. * Statement aggregator for SQL statements for one table.
  9. * All statements are independent with each other, but neither statement can be included with other in one alter query.
  10. */
  11. class Statement
  12. {
  13. /**
  14. * @var string
  15. */
  16. private $statement;
  17. /**
  18. * Type can be: ALTER, CREATE or DROP operations.
  19. * Depends on type different operations will be executed on compilation.
  20. *
  21. * @var string
  22. */
  23. private $type;
  24. /**
  25. * @var string
  26. */
  27. private $tableName;
  28. /**
  29. * @var string
  30. */
  31. private $resource;
  32. /**
  33. * @var callable[]
  34. */
  35. private $triggers = [];
  36. /**
  37. * @var string
  38. */
  39. private $name;
  40. /**
  41. * Constructor.
  42. *
  43. * @param string $name
  44. * @param string $tableName
  45. * @param string $type
  46. * @param string $statement
  47. * @param string $resource
  48. */
  49. public function __construct(
  50. string $name,
  51. string $tableName,
  52. string $type,
  53. string $statement,
  54. string $resource
  55. ) {
  56. $this->statement = $statement;
  57. $this->type = $type;
  58. $this->tableName = $tableName;
  59. $this->resource = $resource;
  60. $this->name = $name;
  61. }
  62. /**
  63. * Get statement.
  64. *
  65. * @return string
  66. */
  67. public function getStatement(): string
  68. {
  69. return $this->statement;
  70. }
  71. /**
  72. * Add trigger to current statement.
  73. * This means, that statement is final and can`t be modified any more.
  74. *
  75. * @param callable $trigger
  76. */
  77. public function addTrigger(callable $trigger)
  78. {
  79. $this->triggers[] = $trigger;
  80. }
  81. /**
  82. * Get statement type.
  83. *
  84. * @return string
  85. */
  86. public function getType(): string
  87. {
  88. return $this->type;
  89. }
  90. /**
  91. * Get table name.
  92. *
  93. * @return string
  94. */
  95. public function getTableName(): string
  96. {
  97. return $this->tableName;
  98. }
  99. /**
  100. * Get resource name.
  101. *
  102. * @return string
  103. */
  104. public function getResource(): string
  105. {
  106. return $this->resource;
  107. }
  108. /**
  109. * Get triggers array.
  110. *
  111. * @return callable[]
  112. */
  113. public function getTriggers(): array
  114. {
  115. return $this->triggers;
  116. }
  117. /**
  118. * Get statement name.
  119. *
  120. * @return string
  121. */
  122. public function getName(): string
  123. {
  124. return $this->name;
  125. }
  126. }