123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- declare(strict_types=1);
- namespace Doctrine\Migrations\Configuration;
- use Doctrine\Migrations\Configuration\Exception\FrozenConfiguration;
- use Doctrine\Migrations\Configuration\Exception\UnknownConfigurationValue;
- use Doctrine\Migrations\Exception\MigrationException;
- use Doctrine\Migrations\Metadata\Storage\MetadataStorageConfiguration;
- use function strtolower;
- /**
- * The Configuration class is responsible for defining migration configuration information.
- */
- final class Configuration
- {
- public const VERSIONS_ORGANIZATION_NONE = 'none';
- public const VERSIONS_ORGANIZATION_BY_YEAR = 'year';
- public const VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH = 'year_and_month';
- /** @var array<string, string> */
- private $migrationsDirectories = [];
- /** @var string[] */
- private $migrationClasses = [];
- /** @var bool */
- private $migrationsAreOrganizedByYear = false;
- /** @var bool */
- private $migrationsAreOrganizedByYearAndMonth = false;
- /** @var string|null */
- private $customTemplate;
- /** @var bool */
- private $isDryRun = false;
- /** @var bool */
- private $allOrNothing = false;
- /** @var string|null */
- private $connectionName;
- /** @var string|null */
- private $entityManagerName;
- /** @var bool */
- private $checkDbPlatform = true;
- /** @var MetadataStorageConfiguration */
- private $metadataStorageConfiguration;
- /** @var bool */
- private $frozen = false;
- public function freeze(): void
- {
- $this->frozen = true;
- }
- private function assertNotFrozen(): void
- {
- if ($this->frozen) {
- throw FrozenConfiguration::new();
- }
- }
- public function setMetadataStorageConfiguration(MetadataStorageConfiguration $metadataStorageConfiguration): void
- {
- $this->assertNotFrozen();
- $this->metadataStorageConfiguration = $metadataStorageConfiguration;
- }
- /**
- * @return string[]
- */
- public function getMigrationClasses(): array
- {
- return $this->migrationClasses;
- }
- public function addMigrationClass(string $className): void
- {
- $this->assertNotFrozen();
- $this->migrationClasses[] = $className;
- }
- public function getMetadataStorageConfiguration(): ?MetadataStorageConfiguration
- {
- return $this->metadataStorageConfiguration;
- }
- public function addMigrationsDirectory(string $namespace, string $path): void
- {
- $this->assertNotFrozen();
- $this->migrationsDirectories[$namespace] = $path;
- }
- /**
- * @return array<string,string>
- */
- public function getMigrationDirectories(): array
- {
- return $this->migrationsDirectories;
- }
- public function getConnectionName(): ?string
- {
- return $this->connectionName;
- }
- public function setConnectionName(?string $connectionName): void
- {
- $this->assertNotFrozen();
- $this->connectionName = $connectionName;
- }
- public function getEntityManagerName(): ?string
- {
- return $this->entityManagerName;
- }
- public function setEntityManagerName(?string $entityManagerName): void
- {
- $this->assertNotFrozen();
- $this->entityManagerName = $entityManagerName;
- }
- public function setCustomTemplate(?string $customTemplate): void
- {
- $this->assertNotFrozen();
- $this->customTemplate = $customTemplate;
- }
- public function getCustomTemplate(): ?string
- {
- return $this->customTemplate;
- }
- public function areMigrationsOrganizedByYear(): bool
- {
- return $this->migrationsAreOrganizedByYear;
- }
- /**
- * @throws MigrationException
- */
- public function setMigrationsAreOrganizedByYear(
- bool $migrationsAreOrganizedByYear = true
- ): void {
- $this->assertNotFrozen();
- $this->migrationsAreOrganizedByYear = $migrationsAreOrganizedByYear;
- }
- /**
- * @throws MigrationException
- */
- public function setMigrationsAreOrganizedByYearAndMonth(
- bool $migrationsAreOrganizedByYearAndMonth = true
- ): void {
- $this->assertNotFrozen();
- $this->migrationsAreOrganizedByYear = $migrationsAreOrganizedByYearAndMonth;
- $this->migrationsAreOrganizedByYearAndMonth = $migrationsAreOrganizedByYearAndMonth;
- }
- public function areMigrationsOrganizedByYearAndMonth(): bool
- {
- return $this->migrationsAreOrganizedByYearAndMonth;
- }
- public function setIsDryRun(bool $isDryRun): void
- {
- $this->assertNotFrozen();
- $this->isDryRun = $isDryRun;
- }
- public function isDryRun(): bool
- {
- return $this->isDryRun;
- }
- public function setAllOrNothing(bool $allOrNothing): void
- {
- $this->assertNotFrozen();
- $this->allOrNothing = $allOrNothing;
- }
- public function isAllOrNothing(): bool
- {
- return $this->allOrNothing;
- }
- public function setCheckDatabasePlatform(bool $checkDbPlatform): void
- {
- $this->checkDbPlatform = $checkDbPlatform;
- }
- public function isDatabasePlatformChecked(): bool
- {
- return $this->checkDbPlatform;
- }
- public function setMigrationOrganization(string $migrationOrganization): void
- {
- $this->assertNotFrozen();
- switch (strtolower($migrationOrganization)) {
- case self::VERSIONS_ORGANIZATION_NONE:
- $this->setMigrationsAreOrganizedByYearAndMonth(false);
- break;
- case self::VERSIONS_ORGANIZATION_BY_YEAR:
- $this->setMigrationsAreOrganizedByYear();
- break;
- case self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH:
- $this->setMigrationsAreOrganizedByYearAndMonth();
- break;
- default:
- throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization);
- }
- }
- }
|