ColumnDiff.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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|null */
  16. public $fromColumn;
  17. /**
  18. * @param string $oldColumnName
  19. * @param string[] $changedProperties
  20. */
  21. public function __construct(
  22. $oldColumnName,
  23. Column $column,
  24. array $changedProperties = [],
  25. ?Column $fromColumn = null
  26. ) {
  27. $this->oldColumnName = $oldColumnName;
  28. $this->column = $column;
  29. $this->changedProperties = $changedProperties;
  30. $this->fromColumn = $fromColumn;
  31. }
  32. /**
  33. * @param string $propertyName
  34. *
  35. * @return bool
  36. */
  37. public function hasChanged($propertyName)
  38. {
  39. return in_array($propertyName, $this->changedProperties);
  40. }
  41. /**
  42. * @return Identifier
  43. */
  44. public function getOldColumnName()
  45. {
  46. $quote = $this->fromColumn && $this->fromColumn->isQuoted();
  47. return new Identifier($this->oldColumnName, $quote);
  48. }
  49. }