SchemaAlterTableAddColumnEventArgs.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Doctrine\DBAL\Event;
  3. use Doctrine\DBAL\Platforms\AbstractPlatform;
  4. use Doctrine\DBAL\Schema\Column;
  5. use Doctrine\DBAL\Schema\TableDiff;
  6. use Doctrine\Deprecations\Deprecation;
  7. use function array_merge;
  8. use function func_get_args;
  9. use function is_array;
  10. /**
  11. * Event Arguments used when SQL queries for adding table columns are generated inside {@link AbstractPlatform}.
  12. */
  13. class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
  14. {
  15. /** @var Column */
  16. private $column;
  17. /** @var TableDiff */
  18. private $tableDiff;
  19. /** @var AbstractPlatform */
  20. private $platform;
  21. /** @var string[] */
  22. private $sql = [];
  23. public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
  24. {
  25. $this->column = $column;
  26. $this->tableDiff = $tableDiff;
  27. $this->platform = $platform;
  28. }
  29. /**
  30. * @return Column
  31. */
  32. public function getColumn()
  33. {
  34. return $this->column;
  35. }
  36. /**
  37. * @return TableDiff
  38. */
  39. public function getTableDiff()
  40. {
  41. return $this->tableDiff;
  42. }
  43. /**
  44. * @return AbstractPlatform
  45. */
  46. public function getPlatform()
  47. {
  48. return $this->platform;
  49. }
  50. /**
  51. * Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
  52. *
  53. * @param string|string[] $sql
  54. *
  55. * @return SchemaAlterTableAddColumnEventArgs
  56. */
  57. public function addSql($sql)
  58. {
  59. if (is_array($sql)) {
  60. Deprecation::trigger(
  61. 'doctrine/dbal',
  62. 'https://github.com/doctrine/dbal/issues/3580',
  63. 'Passing multiple SQL statements as an array to SchemaAlterTableAddColumnEventaArrgs::addSql() ' .
  64. 'is deprecated. Pass each statement as an individual argument instead.'
  65. );
  66. }
  67. $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
  68. return $this;
  69. }
  70. /**
  71. * @return string[]
  72. */
  73. public function getSql()
  74. {
  75. return $this->sql;
  76. }
  77. }