Skip to content

Commit

Permalink
Merge branch '4.3.x' into 5.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Nov 18, 2024
2 parents d3fb37f + d0154ea commit 3ffa7ba
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 18 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ all drivers and middleware.

# Upgrade to 4.3

## Deprecated `AbstractAsset::_setName()`

Setting object name via `AbstractAsset::_setName()` has been deprecated. Pass the name to the `AbstractAsset`
constructor instead.

## Marked `Identifier` class as internal

In order to build SQL identifiers, use `AbstractPlatform::quoteSingleIdentifier()`.
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::createReservedKeywordsList" />
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getReservedKeywordsList" />

<!--
https://github.com/doctrine/dbal/pull/6610
TODO: remove in 5.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::_setName" />
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
Expand Down
25 changes: 25 additions & 0 deletions src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,36 @@ abstract class AbstractAsset

private bool $validateFuture = false;

public function __construct(?string $name = null)
{
if ($name === null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6610',
'Not passing $name to %s is deprecated.',
__METHOD__,
);

return;
}

$this->_setName($name);
}

/**
* Sets the name of this asset.
*
* @deprecated Use the constructor instead.
*/
protected function _setName(string $name): void
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6610',
'%s is deprecated. Use the constructor instead.',
__METHOD__,
);

$input = $name;

if ($this->isIdentifierQuoted($name)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class Column extends AbstractAsset
*/
public function __construct(string $name, Type $type, array $options = [])
{
$this->_setName($name);
parent::__construct($name);

$this->setType($type);
$this->setOptions($options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/ForeignKeyConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
string $name = '',
protected array $options = [],
) {
$this->_setName($name);
parent::__construct($name);

$this->_localColumnNames = $this->createIdentifierMap($localColumnNames);
$this->_foreignTableName = new Identifier($foreignTableName);
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Identifier extends AbstractAsset
*/
public function __construct(string $identifier, bool $quote = false)
{
$this->_setName($identifier);
parent::__construct($identifier);

if (! $quote || $this->_quoted) {
return;
Expand Down
8 changes: 2 additions & 6 deletions src/Schema/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ public function __construct(
array $flags = [],
private readonly array $options = [],
) {
$isUnique = $isUnique || $isPrimary;
parent::__construct($name ?? '');

if ($name !== null) {
$this->_setName($name);
}

$this->_isUnique = $isUnique;
$this->_isUnique = $isUnique || $isPrimary;
$this->_isPrimary = $isPrimary;

foreach ($columns as $column) {
Expand Down
11 changes: 7 additions & 4 deletions src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public function __construct(

$name = $schemaConfig->getName();

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

foreach ($namespaces as $namespace) {
$this->createNamespace($namespace);
Expand Down Expand Up @@ -290,7 +288,12 @@ public function createTable(string $name): Table
public function renameTable(string $oldName, string $newName): self
{
$table = $this->getTable($oldName);
$table->_setName($newName);

$identifier = new Identifier($newName);

$table->_name = $identifier->_name;
$table->_namespace = $identifier->_namespace;
$table->_quoted = $identifier->_quoted;

$this->dropTable($oldName);
$this->_addTable($table);
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function __construct(
int $initialValue = 1,
protected ?int $cache = null,
) {
$this->_setName($name);
parent::__construct($name);

$this->setAllocationSize($allocationSize);
$this->setInitialValue($initialValue);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
throw InvalidTableName::new($name);
}

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

foreach ($columns as $column) {
$this->_addColumn($column);
Expand Down Expand Up @@ -299,7 +299,8 @@ final public function renameColumn(string $oldName, string $newName): Column
}

$column = $this->getColumn($oldName);
$column->_setName($newName);

$column->_name = $newName;
unset($this->_columns[$oldName]);
$this->_addColumn($column);

Expand Down
2 changes: 1 addition & 1 deletion src/Schema/UniqueConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
array $flags = [],
private readonly array $options = [],
) {
$this->_setName($name);
parent::__construct($name);

foreach ($columns as $column) {
$this->addColumn($column);
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class View extends AbstractAsset
{
public function __construct(string $name, private readonly string $sql)
{
$this->_setName($name);
parent::__construct($name);
}

public function getSql(): string
Expand Down

0 comments on commit 3ffa7ba

Please sign in to comment.