Skip to content

Commit 4a6ee92

Browse files
authored
Merge pull request #6945 from morozov/column-editor
Deprecate Column features and introduce ColumnEditor
2 parents 7128a34 + ac36c28 commit 4a6ee92

File tree

84 files changed

+3979
-1331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3979
-1331
lines changed

UPGRADE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ awareness about deprecated code.
88

99
# Upgrade to 4.3
1010

11+
## Deprecated `Column` methods
12+
13+
The following `Column` methods have been deprecated:
14+
15+
- `Column::getPlatformOptions()`, `Column::hasPlatformOption()`, `Column::getPlatformOption()` – use
16+
`Column::getCharset()`, `Column::getCollation()`, `Column::getMinimumValue()` and `Column::getMaximumValue()`
17+
instead.
18+
19+
Additionally,
20+
1. Extending the `Column` class has been deprecated. Use the `Column` class directly.
21+
2. The `Column` constructor has been marked as internal. Use `Column::editor()` to instantiate an
22+
editor and `ColumnEditor::create()` to create a column.
23+
1124
## The `jsonb` column platform option has been deprecated
1225

1326
The `jsonb` column platform option has been deprecated. To define a `JSONB` column, use the `JSONB` type instead.

src/Platforms/MySQL/CharsetMetadataProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
/** @internal */
88
interface CharsetMetadataProvider
99
{
10+
/** @return ?non-empty-string */
1011
public function getDefaultCharsetCollation(string $charset): ?string;
1112
}

src/Platforms/MySQL/CharsetMetadataProvider/CachingCharsetMetadataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/** @internal */
1212
final class CachingCharsetMetadataProvider implements CharsetMetadataProvider
1313
{
14-
/** @var array<string,?string> */
14+
/** @var array<string,?non-empty-string> */
1515
private array $cache = [];
1616

1717
public function __construct(private readonly CharsetMetadataProvider $charsetMetadataProvider)

src/Platforms/MySQL/CollationMetadataProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
/** @internal */
88
interface CollationMetadataProvider
99
{
10+
/**
11+
* @param non-empty-string $collation
12+
*
13+
* @return ?non-empty-string
14+
*/
1015
public function getCollationCharset(string $collation): ?string;
1116
}

src/Platforms/MySQL/CollationMetadataProvider/CachingCollationMetadataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/** @internal */
1212
final class CachingCollationMetadataProvider implements CollationMetadataProvider
1313
{
14-
/** @var array<string,?string> */
14+
/** @var array<non-empty-string,?non-empty-string> */
1515
private array $cache = [];
1616

1717
public function __construct(private readonly CollationMetadataProvider $collationMetadataProvider)

src/Schema/Column.php

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\DBAL\Schema;
66

7+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
78
use Doctrine\DBAL\Schema\Exception\UnknownColumnOption;
89
use Doctrine\DBAL\Schema\Name\Parser\UnqualifiedNameParser;
910
use Doctrine\DBAL\Schema\Name\Parsers;
@@ -17,22 +18,23 @@
1718
/**
1819
* Object representation of a database column.
1920
*
21+
* @final
2022
* @extends AbstractNamedObject<UnqualifiedName>
2123
* @phpstan-type ColumnProperties = array{
2224
* name: string,
2325
* type: Type,
2426
* default: mixed,
2527
* notnull?: bool,
2628
* autoincrement: bool,
27-
* columnDefinition: ?string,
29+
* columnDefinition: ?non-empty-string,
2830
* comment: string,
29-
* charset?: ?string,
30-
* collation?: ?string,
31+
* charset?: ?non-empty-string,
32+
* collation?: ?non-empty-string,
3133
* }
3234
* @phpstan-type PlatformOptions = array{
33-
* charset?: ?string,
34-
* collation?: ?string,
35-
* default_constraint_name?: string,
35+
* charset?: ?non-empty-string,
36+
* collation?: ?non-empty-string,
37+
* default_constraint_name?: non-empty-string,
3638
* jsonb?: bool,
3739
* version?: bool,
3840
* }
@@ -63,12 +65,14 @@ class Column extends AbstractNamedObject
6365
/** @var PlatformOptions */
6466
protected array $_platformOptions = [];
6567

68+
/** @var ?non-empty-string */
6669
protected ?string $_columnDefinition = null;
6770

6871
protected string $_comment = '';
6972

7073
/**
71-
* Creates a new Column.
74+
* @internal Use {@link Column::editor()} to instantiate an editor and {@link ColumnEditor::create()} to create a
75+
* column.
7276
*
7377
* @param array<string, mixed> $options
7478
*/
@@ -189,6 +193,7 @@ public function setPlatformOption(string $name, mixed $value): self
189193
return $this;
190194
}
191195

196+
/** @param ?non-empty-string $value */
192197
public function setColumnDefinition(?string $value): self
193198
{
194199
$this->_columnDefinition = $value;
@@ -236,19 +241,82 @@ public function getDefault(): mixed
236241
return $this->_default;
237242
}
238243

239-
/** @return PlatformOptions */
244+
/**
245+
* Returns the name of the character set to use with the column.
246+
*
247+
* @return ?non-empty-string
248+
*/
249+
public function getCharset(): ?string
250+
{
251+
return $this->_platformOptions['charset'] ?? null;
252+
}
253+
254+
/**
255+
* Returns the name of the collation to use with the column.
256+
*
257+
* @return ?non-empty-string
258+
*/
259+
public function getCollation(): ?string
260+
{
261+
return $this->_platformOptions['collation'] ?? null;
262+
}
263+
264+
/**
265+
* Returns the minimum value to enforce on the column.
266+
*/
267+
public function getMinimumValue(): mixed
268+
{
269+
return $this->_platformOptions['min'] ?? null;
270+
}
271+
272+
/**
273+
* Returns the maximum value to enforce on the column.
274+
*/
275+
public function getMaximumValue(): mixed
276+
{
277+
return $this->_platformOptions['max'] ?? null;
278+
}
279+
280+
/**
281+
* @internal Should be used only from within the {@see AbstractSchemaManager} class hierarchy.
282+
*
283+
* Returns the name of the DEFAULT constraint that implements the default value for the column on SQL Server.
284+
*
285+
* @return ?non-empty-string
286+
*/
287+
public function getDefaultConstraintName(): ?string
288+
{
289+
return $this->_platformOptions[SQLServerPlatform::OPTION_DEFAULT_CONSTRAINT_NAME] ?? null;
290+
}
291+
292+
/**
293+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
294+
* instead.
295+
*
296+
* @return PlatformOptions
297+
*/
240298
public function getPlatformOptions(): array
241299
{
242300
return $this->_platformOptions;
243301
}
244302

245-
/** @param key-of<PlatformOptions> $name */
303+
/**
304+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
305+
* instead.
306+
*
307+
* @param key-of<PlatformOptions> $name
308+
*/
246309
public function hasPlatformOption(string $name): bool
247310
{
248311
return isset($this->_platformOptions[$name]);
249312
}
250313

251-
/** @param key-of<PlatformOptions> $name */
314+
/**
315+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
316+
* instead.
317+
*
318+
* @param key-of<PlatformOptions> $name
319+
*/
252320
public function getPlatformOption(string $name): mixed
253321
{
254322
/** @phpstan-ignore offsetAccess.notFound */
@@ -321,4 +389,32 @@ public function toArray(): array
321389
'values' => $this->_values,
322390
], $this->_platformOptions);
323391
}
392+
393+
public static function editor(): ColumnEditor
394+
{
395+
return new ColumnEditor();
396+
}
397+
398+
public function edit(): ColumnEditor
399+
{
400+
return self::editor()
401+
->setName($this->getObjectName())
402+
->setType($this->_type)
403+
->setLength($this->_length)
404+
->setPrecision($this->_precision)
405+
->setScale($this->_scale)
406+
->setUnsigned($this->_unsigned)
407+
->setFixed($this->_fixed)
408+
->setNotNull($this->_notnull)
409+
->setDefaultValue($this->_default)
410+
->setAutoincrement($this->_autoincrement)
411+
->setComment($this->_comment)
412+
->setValues($this->_values)
413+
->setColumnDefinition($this->_columnDefinition)
414+
->setCharset($this->getCharset())
415+
->setCollation($this->getCollation())
416+
->setMinimumValue($this->getMinimumValue())
417+
->setMaximumValue($this->getMaximumValue())
418+
->setDefaultConstraintName($this->getDefaultConstraintName());
419+
}
324420
}

0 commit comments

Comments
 (0)