Skip to content

Commit ea259d3

Browse files
committed
Merge branch '4.3.x' into 5.0.x
2 parents 3ec3525 + 4a6ee92 commit ea259d3

File tree

84 files changed

+3984
-1335
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

+3984
-1335
lines changed

UPGRADE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,19 @@ all drivers and middleware.
340340

341341
# Upgrade to 4.3
342342

343+
## Deprecated `Column` methods
344+
345+
The following `Column` methods have been deprecated:
346+
347+
- `Column::getPlatformOptions()`, `Column::hasPlatformOption()`, `Column::getPlatformOption()` – use
348+
`Column::getCharset()`, `Column::getCollation()`, `Column::getMinimumValue()` and `Column::getMaximumValue()`
349+
instead.
350+
351+
Additionally,
352+
1. Extending the `Column` class has been deprecated. Use the `Column` class directly.
353+
2. The `Column` constructor has been marked as internal. Use `Column::editor()` to instantiate an
354+
editor and `ColumnEditor::create()` to create a column.
355+
343356
## The `jsonb` column platform option has been deprecated
344357

345358
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;
@@ -16,22 +17,23 @@
1617
/**
1718
* Object representation of a database column.
1819
*
20+
* @final
1921
* @extends AbstractNamedObject<UnqualifiedName>
2022
* @phpstan-type ColumnProperties = array{
2123
* name: UnqualifiedName,
2224
* type: Type,
2325
* default: mixed,
2426
* notnull?: bool,
2527
* autoincrement: bool,
26-
* columnDefinition: ?string,
28+
* columnDefinition: ?non-empty-string,
2729
* comment: string,
28-
* charset?: ?string,
29-
* collation?: ?string,
30+
* charset?: ?non-empty-string,
31+
* collation?: ?non-empty-string,
3032
* }
3133
* @phpstan-type PlatformOptions = array{
32-
* charset?: ?string,
33-
* collation?: ?string,
34-
* default_constraint_name?: string,
34+
* charset?: ?non-empty-string,
35+
* collation?: ?non-empty-string,
36+
* default_constraint_name?: non-empty-string,
3537
* }
3638
*/
3739
class Column extends AbstractNamedObject
@@ -60,12 +62,14 @@ class Column extends AbstractNamedObject
6062
/** @var PlatformOptions */
6163
protected array $_platformOptions = [];
6264

65+
/** @var ?non-empty-string */
6366
protected ?string $_columnDefinition = null;
6467

6568
protected string $_comment = '';
6669

6770
/**
68-
* Creates a new Column.
71+
* @internal Use {@link Column::editor()} to instantiate an editor and {@link ColumnEditor::create()} to create a
72+
* column.
6973
*
7074
* @param array<string, mixed> $options
7175
*/
@@ -170,6 +174,7 @@ public function setPlatformOption(string $name, mixed $value): self
170174
return $this;
171175
}
172176

177+
/** @param ?non-empty-string $value */
173178
public function setColumnDefinition(?string $value): self
174179
{
175180
$this->_columnDefinition = $value;
@@ -217,19 +222,82 @@ public function getDefault(): mixed
217222
return $this->_default;
218223
}
219224

220-
/** @return PlatformOptions */
225+
/**
226+
* Returns the name of the character set to use with the column.
227+
*
228+
* @return ?non-empty-string
229+
*/
230+
public function getCharset(): ?string
231+
{
232+
return $this->_platformOptions['charset'] ?? null;
233+
}
234+
235+
/**
236+
* Returns the name of the collation to use with the column.
237+
*
238+
* @return ?non-empty-string
239+
*/
240+
public function getCollation(): ?string
241+
{
242+
return $this->_platformOptions['collation'] ?? null;
243+
}
244+
245+
/**
246+
* Returns the minimum value to enforce on the column.
247+
*/
248+
public function getMinimumValue(): mixed
249+
{
250+
return $this->_platformOptions['min'] ?? null;
251+
}
252+
253+
/**
254+
* Returns the maximum value to enforce on the column.
255+
*/
256+
public function getMaximumValue(): mixed
257+
{
258+
return $this->_platformOptions['max'] ?? null;
259+
}
260+
261+
/**
262+
* @internal Should be used only from within the {@see AbstractSchemaManager} class hierarchy.
263+
*
264+
* Returns the name of the DEFAULT constraint that implements the default value for the column on SQL Server.
265+
*
266+
* @return ?non-empty-string
267+
*/
268+
public function getDefaultConstraintName(): ?string
269+
{
270+
return $this->_platformOptions[SQLServerPlatform::OPTION_DEFAULT_CONSTRAINT_NAME] ?? null;
271+
}
272+
273+
/**
274+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
275+
* instead.
276+
*
277+
* @return PlatformOptions
278+
*/
221279
public function getPlatformOptions(): array
222280
{
223281
return $this->_platformOptions;
224282
}
225283

226-
/** @param key-of<PlatformOptions> $name */
284+
/**
285+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
286+
* instead.
287+
*
288+
* @param key-of<PlatformOptions> $name
289+
*/
227290
public function hasPlatformOption(string $name): bool
228291
{
229292
return isset($this->_platformOptions[$name]);
230293
}
231294

232-
/** @param key-of<PlatformOptions> $name */
295+
/**
296+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
297+
* instead.
298+
*
299+
* @param key-of<PlatformOptions> $name
300+
*/
233301
public function getPlatformOption(string $name): mixed
234302
{
235303
/** @phpstan-ignore offsetAccess.notFound */
@@ -302,4 +370,32 @@ public function toArray(): array
302370
'values' => $this->_values,
303371
], $this->_platformOptions);
304372
}
373+
374+
public static function editor(): ColumnEditor
375+
{
376+
return new ColumnEditor();
377+
}
378+
379+
public function edit(): ColumnEditor
380+
{
381+
return self::editor()
382+
->setName($this->getObjectName())
383+
->setType($this->_type)
384+
->setLength($this->_length)
385+
->setPrecision($this->_precision)
386+
->setScale($this->_scale)
387+
->setUnsigned($this->_unsigned)
388+
->setFixed($this->_fixed)
389+
->setNotNull($this->_notnull)
390+
->setDefaultValue($this->_default)
391+
->setAutoincrement($this->_autoincrement)
392+
->setComment($this->_comment)
393+
->setValues($this->_values)
394+
->setColumnDefinition($this->_columnDefinition)
395+
->setCharset($this->getCharset())
396+
->setCollation($this->getCollation())
397+
->setMinimumValue($this->getMinimumValue())
398+
->setMaximumValue($this->getMaximumValue())
399+
->setDefaultConstraintName($this->getDefaultConstraintName());
400+
}
305401
}

0 commit comments

Comments
 (0)