Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL\Schema;
4
 
5
use Doctrine\Deprecations\Deprecation;
6
 
7
use function in_array;
8
 
9
/**
10
 * Represents the change of a column.
11
 */
12
class ColumnDiff
13
{
14
    /**
15
     * @deprecated Use {@see $fromColumn} and {@see Column::getName()} instead.
16
     *
17
     * @var string
18
     */
19
    public $oldColumnName;
20
 
21
    /**
22
     * @internal Use {@see getNewColumn()} instead.
23
     *
24
     * @var Column
25
     */
26
    public $column;
27
 
28
    /**
29
     * @deprecated Use {@see hasTypeChanged()}, {@see hasLengthChanged()}, {@see hasPrecisionChanged()},
30
     * {@see hasScaleChanged()}, {@see hasUnsignedChanged()}, {@see hasFixedChanged()}, {@see hasNotNullChanged()},
31
     * {@see hasDefaultChanged()}, {@see hasAutoIncrementChanged()} or {@see hasCommentChanged()} instead.
32
     *
33
     * @var string[]
34
     */
35
    public $changedProperties = [];
36
 
37
    /**
38
     * @internal Use {@see getOldColumn()} instead.
39
     *
40
     * @var Column|null
41
     */
42
    public $fromColumn;
43
 
44
    /**
45
     * @internal The diff can be only instantiated by a {@see Comparator}.
46
     *
47
     * @param string   $oldColumnName
48
     * @param string[] $changedProperties
49
     */
50
    public function __construct(
51
        $oldColumnName,
52
        Column $column,
53
        array $changedProperties = [],
54
        ?Column $fromColumn = null
55
    ) {
56
        if ($fromColumn === null) {
57
            Deprecation::triggerIfCalledFromOutside(
58
                'doctrine/dbal',
59
                'https://github.com/doctrine/dbal/pull/4785',
60
                'Not passing the $fromColumn to %s is deprecated.',
61
                __METHOD__,
62
            );
63
        }
64
 
65
        $this->oldColumnName     = $oldColumnName;
66
        $this->column            = $column;
67
        $this->changedProperties = $changedProperties;
68
        $this->fromColumn        = $fromColumn;
69
    }
70
 
71
    public function getOldColumn(): ?Column
72
    {
73
        return $this->fromColumn;
74
    }
75
 
76
    public function getNewColumn(): Column
77
    {
78
        return $this->column;
79
    }
80
 
81
    public function hasTypeChanged(): bool
82
    {
83
        return $this->hasChanged('type');
84
    }
85
 
86
    public function hasLengthChanged(): bool
87
    {
88
        return $this->hasChanged('length');
89
    }
90
 
91
    public function hasPrecisionChanged(): bool
92
    {
93
        return $this->hasChanged('precision');
94
    }
95
 
96
    public function hasScaleChanged(): bool
97
    {
98
        return $this->hasChanged('scale');
99
    }
100
 
101
    public function hasUnsignedChanged(): bool
102
    {
103
        return $this->hasChanged('unsigned');
104
    }
105
 
106
    public function hasFixedChanged(): bool
107
    {
108
        return $this->hasChanged('fixed');
109
    }
110
 
111
    public function hasNotNullChanged(): bool
112
    {
113
        return $this->hasChanged('notnull');
114
    }
115
 
116
    public function hasDefaultChanged(): bool
117
    {
118
        return $this->hasChanged('default');
119
    }
120
 
121
    public function hasAutoIncrementChanged(): bool
122
    {
123
        return $this->hasChanged('autoincrement');
124
    }
125
 
126
    public function hasCommentChanged(): bool
127
    {
128
        return $this->hasChanged('comment');
129
    }
130
 
131
    /**
132
     * @deprecated Use {@see hasTypeChanged()}, {@see hasLengthChanged()}, {@see hasPrecisionChanged()},
133
     * {@see hasScaleChanged()}, {@see hasUnsignedChanged()}, {@see hasFixedChanged()}, {@see hasNotNullChanged()},
134
     * {@see hasDefaultChanged()}, {@see hasAutoIncrementChanged()} or {@see hasCommentChanged()} instead.
135
     *
136
     * @param string $propertyName
137
     *
138
     * @return bool
139
     */
140
    public function hasChanged($propertyName)
141
    {
142
        return in_array($propertyName, $this->changedProperties, true);
143
    }
144
 
145
    /**
146
     * @deprecated Use {@see $fromColumn} instead.
147
     *
148
     * @return Identifier
149
     */
150
    public function getOldColumnName()
151
    {
152
        Deprecation::trigger(
153
            'doctrine/dbal',
154
            'https://github.com/doctrine/dbal/pull/5622',
155
            '%s is deprecated. Use $fromColumn instead.',
156
            __METHOD__,
157
        );
158
 
159
        if ($this->fromColumn !== null) {
160
            $name  = $this->fromColumn->getName();
161
            $quote = $this->fromColumn->isQuoted();
162
        } else {
163
            $name  = $this->oldColumnName;
164
            $quote = false;
165
        }
166
 
167
        return new Identifier($name, $quote);
168
    }
169
}