Skip to content

Commit 67314ba

Browse files
committed
Merge branch '4.3.x' into 5.0.x
2 parents 13c6154 + d0154ea commit 67314ba

12 files changed

+64
-21
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ all drivers and middleware.
5555

5656
# Upgrade to 4.3
5757

58+
## Deprecated `AbstractAsset::_setName()`
59+
60+
Setting object name via `AbstractAsset::_setName()` has been deprecated. Pass the name to the `AbstractAsset`
61+
constructor instead.
62+
5863
## Marked `Identifier` class as internal
5964

6065
In order to build SQL identifiers, use `AbstractPlatform::quoteSingleIdentifier()`.

psalm.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555

5656
<!-- TODO for PHPUnit 11 -->
5757
<referencedMethod name="PHPUnit\Framework\TestCase::iniSet"/>
58+
59+
<!--
60+
https://github.com/doctrine/dbal/pull/6610
61+
TODO: remove in 5.0.0
62+
-->
63+
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::_setName" />
5864
</errorLevel>
5965
</DeprecatedMethod>
6066
<DocblockTypeContradiction>

src/Schema/AbstractAsset.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Schema\Exception\InvalidObjectName;
99
use Doctrine\DBAL\Schema\Name\Parser;
1010
use Doctrine\DBAL\Schema\Name\Parser\Identifier;
11+
use Doctrine\Deprecations\Deprecation;
1112

1213
use function array_map;
1314
use function count;
@@ -40,11 +41,36 @@ abstract class AbstractAsset
4041
/** @var list<Identifier> */
4142
private array $identifiers = [];
4243

44+
public function __construct(?string $name = null)
45+
{
46+
if ($name === null) {
47+
Deprecation::trigger(
48+
'doctrine/dbal',
49+
'https://github.com/doctrine/dbal/pull/6610',
50+
'Not passing $name to %s is deprecated.',
51+
__METHOD__,
52+
);
53+
54+
return;
55+
}
56+
57+
$this->_setName($name);
58+
}
59+
4360
/**
4461
* Sets the name of this asset.
62+
*
63+
* @deprecated Use the constructor instead.
4564
*/
4665
protected function _setName(string $name): void
4766
{
67+
Deprecation::triggerIfCalledFromOutside(
68+
'doctrine/dbal',
69+
'https://github.com/doctrine/dbal/pull/6610',
70+
'%s is deprecated. Use the constructor instead.',
71+
__METHOD__,
72+
);
73+
4874
if ($name !== '') {
4975
$parser = new Parser();
5076

src/Schema/Column.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class Column extends AbstractAsset
5050
*/
5151
public function __construct(string $name, Type $type, array $options = [])
5252
{
53-
$this->_setName($name);
53+
parent::__construct($name);
54+
5455
$this->setType($type);
5556
$this->setOptions($options);
5657
}

src/Schema/ForeignKeyConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
string $name = '',
5454
protected array $options = [],
5555
) {
56-
$this->_setName($name);
56+
parent::__construct($name);
5757

5858
$this->_localColumnNames = $this->createIdentifierMap($localColumnNames);
5959
$this->_foreignTableName = new Identifier($foreignTableName);

src/Schema/Identifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Identifier extends AbstractAsset
2020
*/
2121
public function __construct(string $identifier, bool $quote = false)
2222
{
23-
$this->_setName($identifier);
23+
parent::__construct($identifier);
2424

2525
if (! $quote || $this->_quoted) {
2626
return;

src/Schema/Index.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ public function __construct(
4747
array $flags = [],
4848
private readonly array $options = [],
4949
) {
50-
$isUnique = $isUnique || $isPrimary;
50+
parent::__construct($name ?? '');
5151

52-
if ($name !== null) {
53-
$this->_setName($name);
54-
}
55-
56-
$this->_isUnique = $isUnique;
52+
$this->_isUnique = $isUnique || $isPrimary;
5753
$this->_isPrimary = $isPrimary;
5854

5955
foreach ($columns as $column) {

src/Schema/Schema.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public function __construct(
7676

7777
$name = $schemaConfig->getName();
7878

79-
if ($name !== null) {
80-
$this->_setName($name);
81-
}
79+
parent::__construct($name ?? '');
8280

8381
foreach ($namespaces as $namespace) {
8482
$this->createNamespace($namespace);
@@ -290,7 +288,12 @@ public function createTable(string $name): Table
290288
public function renameTable(string $oldName, string $newName): self
291289
{
292290
$table = $this->getTable($oldName);
293-
$table->_setName($newName);
291+
292+
$identifier = new Identifier($newName);
293+
294+
$table->_name = $identifier->_name;
295+
$table->_namespace = $identifier->_namespace;
296+
$table->_quoted = $identifier->_quoted;
294297

295298
$this->dropTable($oldName);
296299
$this->_addTable($table);

src/Schema/Sequence.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function __construct(
2222
int $initialValue = 1,
2323
protected ?int $cache = null,
2424
) {
25-
$this->_setName($name);
25+
parent::__construct($name);
26+
2627
$this->setAllocationSize($allocationSize);
2728
$this->setInitialValue($initialValue);
2829
}

src/Schema/Table.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __construct(
8282
throw InvalidTableName::new($name);
8383
}
8484

85-
$this->_setName($name);
85+
parent::__construct($name);
8686

8787
foreach ($columns as $column) {
8888
$this->_addColumn($column);
@@ -298,10 +298,15 @@ final public function renameColumn(string $oldName, string $newName): Column
298298
));
299299
}
300300

301-
$column = $this->getColumn($oldName);
302-
$column->_setName($newName);
301+
$oldColumn = $this->getColumn($oldName);
302+
$options = $oldColumn->toArray();
303+
304+
unset($options['name'], $options['type']);
305+
306+
$newColumn = new Column($newName, $oldColumn->getType(), $options);
307+
303308
unset($this->_columns[$oldName]);
304-
$this->_addColumn($column);
309+
$this->_addColumn($newColumn);
305310

306311
$this->renameColumnInIndexes($oldName, $newName);
307312
$this->renameColumnInForeignKeyConstraints($oldName, $newName);
@@ -318,7 +323,7 @@ final public function renameColumn(string $oldName, string $newName): Column
318323
$this->renamedColumns[$newName] = $oldName;
319324
}
320325

321-
return $column;
326+
return $newColumn;
322327
}
323328

324329
/** @param array<string, mixed> $options */

0 commit comments

Comments
 (0)