DBALSchemaDiffProvider.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Migrations\Provider;
  4. use Doctrine\DBAL\Platforms\AbstractPlatform;
  5. use Doctrine\DBAL\Schema\AbstractSchemaManager;
  6. use Doctrine\DBAL\Schema\Schema;
  7. /**
  8. * The SchemaDiffProvider class is responsible for providing a Doctrine\DBAL\Schema\Schema instance that
  9. * represents the current state of your database. A clone of this Schema instance is passed to each of your migrations
  10. * so that you can manipulate the Schema object. Your manipulated Schema object is then compared to the original Schema
  11. * object to produce the SQL statements that need to be executed.
  12. *
  13. * @internal
  14. *
  15. * @see Doctrine\Migrations\Version\DbalExecutor
  16. */
  17. class DBALSchemaDiffProvider implements SchemaDiffProvider
  18. {
  19. /** @var AbstractPlatform */
  20. private $platform;
  21. /** @var AbstractSchemaManager */
  22. private $schemaManager;
  23. public function __construct(AbstractSchemaManager $schemaManager, AbstractPlatform $platform)
  24. {
  25. $this->schemaManager = $schemaManager;
  26. $this->platform = $platform;
  27. }
  28. public function createFromSchema(): Schema
  29. {
  30. return $this->schemaManager->createSchema();
  31. }
  32. public function createToSchema(Schema $fromSchema): Schema
  33. {
  34. return clone $fromSchema;
  35. }
  36. /** @return string[] */
  37. public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema): array
  38. {
  39. return $fromSchema->getMigrateToSql($toSchema, $this->platform);
  40. }
  41. }