diff --git a/UPGRADE.md b/UPGRADE.md
index 1b1c83a7c3..78fe75e465 100644
--- a/UPGRADE.md
+++ b/UPGRADE.md
@@ -80,6 +80,11 @@ all drivers and middleware.
# Upgrade to 4.3
+## Deprecated `AbstractAsset::getQuotedName()`
+
+The `AbstractAsset::getQuotedName()` method has been deprecated. Use `NamedObject::getObjectName()` or
+`OptionallyQualifiedName::getObjectName()` followed by `Name::toSQL()` instead.
+
## Deprecated `AbstractAsset` namespace-related methods and property
The following namespace-related methods and property have been deprecated:
diff --git a/psalm.xml.dist b/psalm.xml.dist
index cd73308464..bb9d3e0b54 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -62,6 +62,12 @@
-->
+
+
+
diff --git a/src/Schema/AbstractAsset.php b/src/Schema/AbstractAsset.php
index 9518177f8c..05aacc5504 100644
--- a/src/Schema/AbstractAsset.php
+++ b/src/Schema/AbstractAsset.php
@@ -12,6 +12,7 @@
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
use Doctrine\DBAL\Schema\Name\Parser;
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
+use Doctrine\Deprecations\Deprecation;
use function array_map;
use function assert;
@@ -148,9 +149,19 @@ public function getName(): string
/**
* Returns the quoted representation of this asset's name. If the name is unquoted, it is normalized according to
* the platform's unquoted name normalization rules.
+ *
+ * @deprecated Use {@see NamedObject::getObjectName()} or {@see OptionallyQualifiedName::getObjectName()} followed
+ * by {@see Name::toSQL()} instead.
*/
public function getQuotedName(AbstractPlatform $platform): string
{
+ Deprecation::triggerIfCalledFromOutside(
+ 'doctrine/dbal',
+ 'https://github.com/doctrine/dbal/pull/6674',
+ '%s is deprecated and will be removed in 5.0.',
+ __METHOD__,
+ );
+
$parts = array_map(static function (Identifier $identifier) use ($platform): string {
$value = $identifier->getValue();
diff --git a/src/Schema/Name.php b/src/Schema/Name.php
index 92e7721b61..d5169775b8 100644
--- a/src/Schema/Name.php
+++ b/src/Schema/Name.php
@@ -4,11 +4,18 @@
namespace Doctrine\DBAL\Schema;
+use Doctrine\DBAL\Platforms\AbstractPlatform;
+
/**
* Represents a database object name.
*/
interface Name
{
+ /**
+ * Returns the SQL representation of the name for the given platform.
+ */
+ public function toSQL(AbstractPlatform $platform): string;
+
/**
* Returns the string representation of the name.
*
diff --git a/src/Schema/Name/AbstractName.php b/src/Schema/Name/AbstractName.php
index 30c79d307c..95d3c56dbf 100644
--- a/src/Schema/Name/AbstractName.php
+++ b/src/Schema/Name/AbstractName.php
@@ -4,6 +4,7 @@
namespace Doctrine\DBAL\Schema\Name;
+use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Name;
use function array_map;
@@ -25,11 +26,19 @@ public function __construct(Identifier $firstIdentifier, Identifier ...$otherIde
$this->identifiers = array_merge([$firstIdentifier], array_values($otherIdentifiers));
}
+ public function toSQL(AbstractPlatform $platform): string
+ {
+ return $this->joinIdentifiers(static fn (Identifier $identifier): string => $identifier->toSql($platform));
+ }
+
public function toString(): string
{
- return implode('.', array_map(
- static fn (Identifier $identifier): string => $identifier->toString(),
- $this->identifiers,
- ));
+ return $this->joinIdentifiers(static fn (Identifier $identifier): string => $identifier->toString());
+ }
+
+ /** @param callable(Identifier): string $mapper */
+ private function joinIdentifiers(callable $mapper): string
+ {
+ return implode('.', array_map($mapper, $this->identifiers));
}
}
diff --git a/src/Schema/Name/Identifier.php b/src/Schema/Name/Identifier.php
index 1ae4ad6778..aa591de4cb 100644
--- a/src/Schema/Name/Identifier.php
+++ b/src/Schema/Name/Identifier.php
@@ -4,6 +4,7 @@
namespace Doctrine\DBAL\Schema\Name;
+use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Exception\InvalidIdentifier;
use function sprintf;
@@ -34,6 +35,17 @@ public function isQuoted(): bool
return $this->isQuoted;
}
+ public function toSql(AbstractPlatform $platform): string
+ {
+ if (! $this->isQuoted) {
+ $value = $platform->normalizeUnquotedIdentifier($this->value);
+ } else {
+ $value = $this->value;
+ }
+
+ return $platform->quoteSingleIdentifier($value);
+ }
+
public function toString(): string
{
if (! $this->isQuoted) {