Skip to content

Commit 6617c6f

Browse files
authored
Merge pull request #6675 from morozov/5.0.x
Merge 4.3.x up into 5.0.x
2 parents d3fcbcf + 5b1b344 commit 6617c6f

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

UPGRADE.md

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

8181
# Upgrade to 4.3
8282

83+
## Deprecated `AbstractAsset::getQuotedName()`
84+
85+
The `AbstractAsset::getQuotedName()` method has been deprecated. Use `NamedObject::getObjectName()` or
86+
`OptionallyQualifiedName::getObjectName()` followed by `Name::toSQL()` instead.
87+
8388
## Deprecated `AbstractAsset` namespace-related methods and property
8489

8590
The following namespace-related methods and property have been deprecated:

psalm.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
-->
6363
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::getNameParser" />
6464
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::setName" />
65+
66+
<!--
67+
https://github.com/doctrine/dbal/pull/6674
68+
TODO: remove in 5.0.0
69+
-->
70+
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::getQuotedName" />
6571
</errorLevel>
6672
</DeprecatedMethod>
6773
<DocblockTypeContradiction>

src/Schema/AbstractAsset.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
1313
use Doctrine\DBAL\Schema\Name\Parser;
1414
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
15+
use Doctrine\Deprecations\Deprecation;
1516

1617
use function array_map;
1718
use function assert;
@@ -148,9 +149,19 @@ public function getName(): string
148149
/**
149150
* Returns the quoted representation of this asset's name. If the name is unquoted, it is normalized according to
150151
* the platform's unquoted name normalization rules.
152+
*
153+
* @deprecated Use {@see NamedObject::getObjectName()} or {@see OptionallyQualifiedName::getObjectName()} followed
154+
* by {@see Name::toSQL()} instead.
151155
*/
152156
public function getQuotedName(AbstractPlatform $platform): string
153157
{
158+
Deprecation::triggerIfCalledFromOutside(
159+
'doctrine/dbal',
160+
'https://github.com/doctrine/dbal/pull/6674',
161+
'%s is deprecated and will be removed in 5.0.',
162+
__METHOD__,
163+
);
164+
154165
$parts = array_map(static function (Identifier $identifier) use ($platform): string {
155166
$value = $identifier->getValue();
156167

src/Schema/Name.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
namespace Doctrine\DBAL\Schema;
66

7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
79
/**
810
* Represents a database object name.
911
*/
1012
interface Name
1113
{
14+
/**
15+
* Returns the SQL representation of the name for the given platform.
16+
*/
17+
public function toSQL(AbstractPlatform $platform): string;
18+
1219
/**
1320
* Returns the string representation of the name.
1421
*

src/Schema/Name/AbstractName.php

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

55
namespace Doctrine\DBAL\Schema\Name;
66

7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
78
use Doctrine\DBAL\Schema\Name;
89

910
use function array_map;
@@ -25,11 +26,19 @@ public function __construct(Identifier $firstIdentifier, Identifier ...$otherIde
2526
$this->identifiers = array_merge([$firstIdentifier], array_values($otherIdentifiers));
2627
}
2728

29+
public function toSQL(AbstractPlatform $platform): string
30+
{
31+
return $this->joinIdentifiers(static fn (Identifier $identifier): string => $identifier->toSql($platform));
32+
}
33+
2834
public function toString(): string
2935
{
30-
return implode('.', array_map(
31-
static fn (Identifier $identifier): string => $identifier->toString(),
32-
$this->identifiers,
33-
));
36+
return $this->joinIdentifiers(static fn (Identifier $identifier): string => $identifier->toString());
37+
}
38+
39+
/** @param callable(Identifier): string $mapper */
40+
private function joinIdentifiers(callable $mapper): string
41+
{
42+
return implode('.', array_map($mapper, $this->identifiers));
3443
}
3544
}

src/Schema/Name/Identifier.php

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

55
namespace Doctrine\DBAL\Schema\Name;
66

7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
78
use Doctrine\DBAL\Schema\Exception\InvalidIdentifier;
89

910
use function sprintf;
@@ -34,6 +35,17 @@ public function isQuoted(): bool
3435
return $this->isQuoted;
3536
}
3637

38+
public function toSql(AbstractPlatform $platform): string
39+
{
40+
if (! $this->isQuoted) {
41+
$value = $platform->normalizeUnquotedIdentifier($this->value);
42+
} else {
43+
$value = $this->value;
44+
}
45+
46+
return $platform->quoteSingleIdentifier($value);
47+
}
48+
3749
public function toString(): string
3850
{
3951
if (! $this->isQuoted) {

0 commit comments

Comments
 (0)