ColumnDiff.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Doctrine\DBAL\Schema;
  3. use function in_array;
  4. /**
  5. * Represents the change of a column.
  6. */
  7. class ColumnDiff
  8. {
  9. /** @var string */
  10. public $oldColumnName;
  11. /** @var Column */
  12. public $column;
  13. /** @var string[] */
  14. public $changedProperties = [];
  15. /** @var Column */
  16. public $fromColumn;
  17. /**
  18. * @param string $oldColumnName
  19. * @param string[] $changedProperties
  20. */
  21. public function __construct($oldColumnName, Column $column, array $changedProperties = [], ?Column $fromColumn = null)
  22. {
  23. $this->oldColumnName = $oldColumnName;
  24. $this->column = $column;
  25. $this->changedProperties = $changedProperties;
  26. $this->fromColumn = $fromColumn;
  27. }
  28. /**
  29. * @param string $propertyName
  30. *
  31. * @return bool
  32. */
  33. public function hasChanged($propertyName)
  34. {
  35. return in_array($propertyName, $this->changedProperties);
  36. }
  37. /**
  38. * @return Identifier
  39. */
  40. public function getOldColumnName()
  41. {
  42. $quote = $this->fromColumn && $this->fromColumn->isQuoted();
  43. return new Identifier($this->oldColumnName, $quote);
  44. }
  45. }