diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Schema/ColumnDiff.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Schema/ColumnDiff.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Schema/ColumnDiff.php | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Schema/ColumnDiff.php b/vendor/doctrine/dbal/src/Schema/ColumnDiff.php new file mode 100644 index 0000000..3e4950a --- /dev/null +++ b/vendor/doctrine/dbal/src/Schema/ColumnDiff.php | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Schema; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * Represents the change of a column. | ||
| 9 | */ | ||
| 10 | class ColumnDiff | ||
| 11 | { | ||
| 12 | /** @internal The diff can be only instantiated by a {@see Comparator}. */ | ||
| 13 | public function __construct(private readonly Column $oldColumn, private readonly Column $newColumn) | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | public function getOldColumn(): Column | ||
| 18 | { | ||
| 19 | return $this->oldColumn; | ||
| 20 | } | ||
| 21 | |||
| 22 | public function getNewColumn(): Column | ||
| 23 | { | ||
| 24 | return $this->newColumn; | ||
| 25 | } | ||
| 26 | |||
| 27 | public function hasTypeChanged(): bool | ||
| 28 | { | ||
| 29 | return $this->newColumn->getType()::class !== $this->oldColumn->getType()::class; | ||
| 30 | } | ||
| 31 | |||
| 32 | public function hasLengthChanged(): bool | ||
| 33 | { | ||
| 34 | return $this->hasPropertyChanged(static function (Column $column): ?int { | ||
| 35 | return $column->getLength(); | ||
| 36 | }); | ||
| 37 | } | ||
| 38 | |||
| 39 | public function hasPrecisionChanged(): bool | ||
| 40 | { | ||
| 41 | return $this->hasPropertyChanged(static function (Column $column): ?int { | ||
| 42 | return $column->getPrecision(); | ||
| 43 | }); | ||
| 44 | } | ||
| 45 | |||
| 46 | public function hasScaleChanged(): bool | ||
| 47 | { | ||
| 48 | return $this->hasPropertyChanged(static function (Column $column): int { | ||
| 49 | return $column->getScale(); | ||
| 50 | }); | ||
| 51 | } | ||
| 52 | |||
| 53 | public function hasUnsignedChanged(): bool | ||
| 54 | { | ||
| 55 | return $this->hasPropertyChanged(static function (Column $column): bool { | ||
| 56 | return $column->getUnsigned(); | ||
| 57 | }); | ||
| 58 | } | ||
| 59 | |||
| 60 | public function hasFixedChanged(): bool | ||
| 61 | { | ||
| 62 | return $this->hasPropertyChanged(static function (Column $column): bool { | ||
| 63 | return $column->getFixed(); | ||
| 64 | }); | ||
| 65 | } | ||
| 66 | |||
| 67 | public function hasNotNullChanged(): bool | ||
| 68 | { | ||
| 69 | return $this->hasPropertyChanged(static function (Column $column): bool { | ||
| 70 | return $column->getNotnull(); | ||
| 71 | }); | ||
| 72 | } | ||
| 73 | |||
| 74 | public function hasDefaultChanged(): bool | ||
| 75 | { | ||
| 76 | $oldDefault = $this->oldColumn->getDefault(); | ||
| 77 | $newDefault = $this->newColumn->getDefault(); | ||
| 78 | |||
| 79 | // Null values need to be checked additionally as they tell whether to create or drop a default value. | ||
| 80 | // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. | ||
| 81 | if (($newDefault === null) xor ($oldDefault === null)) { | ||
| 82 | return true; | ||
| 83 | } | ||
| 84 | |||
| 85 | return $newDefault != $oldDefault; | ||
| 86 | } | ||
| 87 | |||
| 88 | public function hasAutoIncrementChanged(): bool | ||
| 89 | { | ||
| 90 | return $this->hasPropertyChanged(static function (Column $column): bool { | ||
| 91 | return $column->getAutoincrement(); | ||
| 92 | }); | ||
| 93 | } | ||
| 94 | |||
| 95 | public function hasCommentChanged(): bool | ||
| 96 | { | ||
| 97 | return $this->hasPropertyChanged(static function (Column $column): string { | ||
| 98 | return $column->getComment(); | ||
| 99 | }); | ||
| 100 | } | ||
| 101 | |||
| 102 | private function hasPropertyChanged(callable $property): bool | ||
| 103 | { | ||
| 104 | return $property($this->newColumn) !== $property($this->oldColumn); | ||
| 105 | } | ||
| 106 | } | ||
