5
5
namespace Doctrine \DBAL \Schema ;
6
6
7
7
use Doctrine \DBAL \Platforms \AbstractPlatform ;
8
+ use Doctrine \DBAL \Schema \Exception \InvalidObjectName ;
8
9
use Doctrine \DBAL \Schema \Name \Parser ;
9
10
use Doctrine \DBAL \Schema \Name \Parser \Identifier ;
10
- use Doctrine \Deprecations \Deprecation ;
11
11
12
12
use function array_map ;
13
13
use function count ;
14
14
use function crc32 ;
15
15
use function dechex ;
16
- use function explode ;
17
16
use function implode ;
18
- use function sprintf ;
19
- use function str_contains ;
20
17
use function str_replace ;
21
18
use function strtolower ;
22
19
use function strtoupper ;
@@ -43,51 +40,28 @@ abstract class AbstractAsset
43
40
/** @var list<Identifier> */
44
41
private array $ identifiers = [];
45
42
46
- private bool $ validateFuture = false ;
47
-
48
43
/**
49
44
* Sets the name of this asset.
50
45
*/
51
46
protected function _setName (string $ name ): void
52
47
{
53
- $ input = $ name ;
54
-
55
- if ($ this ->isIdentifierQuoted ($ name )) {
56
- $ this ->_quoted = true ;
57
- $ name = $ this ->trimQuotes ($ name );
58
- }
59
-
60
- if (str_contains ($ name , '. ' )) {
61
- $ parts = explode ('. ' , $ name );
62
- $ this ->_namespace = $ parts [0 ];
63
- $ name = $ parts [1 ];
64
- }
65
-
66
- $ this ->_name = $ name ;
67
-
68
- $ this ->validateFuture = false ;
69
-
70
- if ($ input !== '' ) {
48
+ if ($ name !== '' ) {
71
49
$ parser = new Parser ();
72
50
73
51
try {
74
- $ identifiers = $ parser ->parse ($ input );
52
+ $ identifiers = $ parser ->parse ($ name );
75
53
} catch (Parser \Exception $ e ) {
76
- Deprecation::trigger (
77
- 'doctrine/dbal ' ,
78
- 'https://github.com/doctrine/dbal/pull/6592 ' ,
79
- 'Unable to parse object name: %s. ' ,
80
- $ e ->getMessage (),
81
- );
82
-
83
- return ;
54
+ throw InvalidObjectName::fromParserException ($ name , $ e );
84
55
}
85
56
} else {
86
57
$ identifiers = [];
87
58
}
88
59
89
60
switch (count ($ identifiers )) {
90
61
case 0 :
62
+ $ this ->_name = '' ;
63
+ $ this ->_quoted = false ;
64
+ $ this ->_namespace = null ;
91
65
$ this ->identifiers = [];
92
66
93
67
return ;
@@ -102,43 +76,13 @@ protected function _setName(string $name): void
102
76
break ;
103
77
104
78
default :
105
- Deprecation::trigger (
106
- 'doctrine/dbal ' ,
107
- 'https://github.com/doctrine/dbal/pull/6592 ' ,
108
- 'An object name may consist of at most 2 identifiers (<namespace>.<name>), %d given. ' ,
109
- count ($ identifiers ),
110
- );
111
-
112
- return ;
113
- }
114
-
115
- $ this ->identifiers = $ identifiers ;
116
- $ this ->validateFuture = true ;
117
-
118
- $ futureName = $ name ->getValue ();
119
- $ futureNamespace = $ namespace ?->getValue();
120
-
121
- if ($ this ->_name !== $ futureName ) {
122
- Deprecation::trigger (
123
- 'doctrine/dbal ' ,
124
- 'https://github.com/doctrine/dbal/pull/6592 ' ,
125
- 'Instead of "%s", this name will be interpreted as "%s" in 5.0 ' ,
126
- $ this ->_name ,
127
- $ futureName ,
128
- );
79
+ throw InvalidObjectName::tooManyQualifiers ($ name , count ($ identifiers ) - 1 );
129
80
}
130
81
131
- if ($ this ->_namespace === $ futureNamespace ) {
132
- return ;
133
- }
134
-
135
- Deprecation::trigger (
136
- 'doctrine/dbal ' ,
137
- 'https://github.com/doctrine/dbal/pull/6592 ' ,
138
- 'Instead of %s, the namespace in this name will be interpreted as %s in 5.0. ' ,
139
- $ this ->_namespace !== null ? sprintf ('"%s" ' , $ this ->_namespace ) : 'null ' ,
140
- $ futureNamespace !== null ? sprintf ('"%s" ' , $ futureNamespace ) : 'null ' ,
141
- );
82
+ $ this ->_name = $ name ->getValue ();
83
+ $ this ->_quoted = $ name ->isQuoted ();
84
+ $ this ->_namespace = $ namespace ?->getValue();
85
+ $ this ->identifiers = $ identifiers ;
142
86
}
143
87
144
88
/**
@@ -210,53 +154,22 @@ public function getName(): string
210
154
}
211
155
212
156
/**
213
- * Gets the quoted representation of this asset but only if it was defined with one. Otherwise
214
- * return the plain unquoted value as inserted .
157
+ * Returns the quoted representation of this asset's name. If the name is unquoted, it is normalized according to
158
+ * the platform's unquoted name normalization rules .
215
159
*/
216
160
public function getQuotedName (AbstractPlatform $ platform ): string
217
161
{
218
- $ keywords = $ platform ->getReservedKeywordsList ();
219
- $ parts = $ normalizedParts = [];
220
-
221
- foreach (explode ('. ' , $ this ->getName ()) as $ identifier ) {
222
- $ isQuoted = $ this ->_quoted || $ keywords ->isKeyword ($ identifier );
162
+ $ parts = array_map (static function (Identifier $ identifier ) use ($ platform ): string {
163
+ $ value = $ identifier ->getValue ();
223
164
224
- if (! $ isQuoted ) {
225
- $ parts [] = $ identifier ;
226
- $ normalizedParts [] = $ platform ->normalizeUnquotedIdentifier ($ identifier );
227
- } else {
228
- $ parts [] = $ platform ->quoteSingleIdentifier ($ identifier );
229
- $ normalizedParts [] = $ identifier ;
165
+ if (! $ identifier ->isQuoted ()) {
166
+ $ value = $ platform ->normalizeUnquotedIdentifier ($ value );
230
167
}
231
- }
232
168
233
- $ name = implode ('. ' , $ parts );
234
-
235
- if ($ this ->validateFuture ) {
236
- $ futureParts = array_map (static function (Identifier $ identifier ) use ($ platform ): string {
237
- $ value = $ identifier ->getValue ();
238
-
239
- if (! $ identifier ->isQuoted ()) {
240
- $ value = $ platform ->normalizeUnquotedIdentifier ($ value );
241
- }
242
-
243
- return $ value ;
244
- }, $ this ->identifiers );
245
-
246
- if ($ normalizedParts !== $ futureParts ) {
247
- Deprecation::trigger (
248
- 'doctrine/dbal ' ,
249
- 'https://github.com/doctrine/dbal/pull/6592 ' ,
250
- 'Relying on implicitly quoted identifiers preserving their original case is deprecated. '
251
- . 'The current name %s will become %s in 5.0. '
252
- . 'Please quote the name if the case needs to be preserved. ' ,
253
- $ name ,
254
- implode ('. ' , array_map ([$ platform , 'quoteSingleIdentifier ' ], $ futureParts )),
255
- );
256
- }
257
- }
169
+ return $ platform ->quoteSingleIdentifier ($ value );
170
+ }, $ this ->identifiers );
258
171
259
- return $ name ;
172
+ return implode ( ' . ' , $ parts ) ;
260
173
}
261
174
262
175
/**
0 commit comments