Constraint.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * Constraint structural element.
  9. * Used for creating additional rules on db tables.
  10. */
  11. class Constraint extends GenericElement implements
  12. ElementInterface,
  13. TableElementInterface
  14. {
  15. /**
  16. * In case if we will need to change this object: add, modify or drop, we will need
  17. * to define it by its type.
  18. */
  19. const TYPE = 'constraint';
  20. /**
  21. * Means PRIMARY KEY
  22. */
  23. const PRIMARY_TYPE = 'primary';
  24. /**
  25. * Means UNIQUE KEY
  26. */
  27. const UNIQUE_TYPE = 'unique';
  28. /**
  29. * @var Table
  30. */
  31. private $table;
  32. /**
  33. * @var string
  34. */
  35. private $nameWithoutPrefix;
  36. /**
  37. * Constructor.
  38. *
  39. * @param string $name
  40. * @param string $type
  41. * @param Table $table
  42. * @param string $nameWithoutPrefix
  43. */
  44. public function __construct(
  45. string $name,
  46. string $type,
  47. Table $table,
  48. string $nameWithoutPrefix
  49. ) {
  50. parent::__construct($name, $type);
  51. $this->table = $table;
  52. $this->nameWithoutPrefix = $nameWithoutPrefix;
  53. }
  54. /**
  55. * Retrieve table object.
  56. *
  57. * @return Table
  58. */
  59. public function getTable()
  60. {
  61. return $this->table;
  62. }
  63. /**
  64. * @inheritdoc
  65. */
  66. public function getElementType()
  67. {
  68. return self::TYPE;
  69. }
  70. /**
  71. * Retrieve the constraint name which is calculated without table prefix.
  72. *
  73. * @return string
  74. */
  75. public function getNameWithoutPrefix()
  76. {
  77. return $this->nameWithoutPrefix;
  78. }
  79. }