SchemaIndexDefinitionEventArgs.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Doctrine\DBAL\Event;
  3. use Doctrine\DBAL\Connection;
  4. use Doctrine\DBAL\Platforms\AbstractPlatform;
  5. use Doctrine\DBAL\Schema\Index;
  6. use Doctrine\Deprecations\Deprecation;
  7. /**
  8. * Event Arguments used when the portable index definition is generated inside {@link AbstractSchemaManager}.
  9. */
  10. class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
  11. {
  12. /** @var Index|null */
  13. private $index;
  14. /**
  15. * Raw index data as fetched from the database.
  16. *
  17. * @var mixed[]
  18. */
  19. private $tableIndex;
  20. /** @var string */
  21. private $table;
  22. /** @var Connection */
  23. private $connection;
  24. /**
  25. * @param mixed[] $tableIndex
  26. * @param string $table
  27. */
  28. public function __construct(array $tableIndex, $table, Connection $connection)
  29. {
  30. $this->tableIndex = $tableIndex;
  31. $this->table = $table;
  32. $this->connection = $connection;
  33. }
  34. /**
  35. * Allows to clear the index which means the index will be excluded from tables index list.
  36. *
  37. * @return SchemaIndexDefinitionEventArgs
  38. */
  39. public function setIndex(?Index $index = null)
  40. {
  41. $this->index = $index;
  42. return $this;
  43. }
  44. /**
  45. * @return Index|null
  46. */
  47. public function getIndex()
  48. {
  49. return $this->index;
  50. }
  51. /**
  52. * @return mixed[]
  53. */
  54. public function getTableIndex()
  55. {
  56. return $this->tableIndex;
  57. }
  58. /**
  59. * @return string
  60. */
  61. public function getTable()
  62. {
  63. return $this->table;
  64. }
  65. /**
  66. * @return Connection
  67. */
  68. public function getConnection()
  69. {
  70. return $this->connection;
  71. }
  72. /**
  73. * @deprecated Use SchemaIndexDefinitionEventArgs::getConnection() and Connection::getDatabasePlatform() instead.
  74. *
  75. * @return AbstractPlatform
  76. */
  77. public function getDatabasePlatform()
  78. {
  79. Deprecation::trigger(
  80. 'doctrine/dbal',
  81. 'https://github.com/doctrine/dbal/issues/3580',
  82. 'SchemaIndexDefinitionEventArgs::getDatabasePlatform() is deprecated, ' .
  83. 'use SchemaIndexDefinitionEventArgs::getConnection()->getDatabasePlatform() instead.'
  84. );
  85. return $this->connection->getDatabasePlatform();
  86. }
  87. }