MigrationPlan.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Migrations\Metadata;
  4. use Doctrine\Migrations\AbstractMigration;
  5. use Doctrine\Migrations\Exception\PlanAlreadyExecuted;
  6. use Doctrine\Migrations\Version\ExecutionResult;
  7. use Doctrine\Migrations\Version\Version;
  8. /**
  9. * Represents an available migration to be executed in a specific direction.
  10. */
  11. final class MigrationPlan
  12. {
  13. /** @var string */
  14. private $direction;
  15. /** @var Version */
  16. private $version;
  17. /** @var AbstractMigration */
  18. private $migration;
  19. /** @var ExecutionResult */
  20. public $result;
  21. public function __construct(Version $version, AbstractMigration $migration, string $direction)
  22. {
  23. $this->version = $version;
  24. $this->migration = $migration;
  25. $this->direction = $direction;
  26. }
  27. public function getVersion(): Version
  28. {
  29. return $this->version;
  30. }
  31. public function getResult(): ?ExecutionResult
  32. {
  33. return $this->result;
  34. }
  35. public function markAsExecuted(ExecutionResult $result): void
  36. {
  37. if ($this->result !== null) {
  38. throw PlanAlreadyExecuted::new();
  39. }
  40. $this->result = $result;
  41. }
  42. public function getMigration(): AbstractMigration
  43. {
  44. return $this->migration;
  45. }
  46. public function getDirection(): string
  47. {
  48. return $this->direction;
  49. }
  50. }