Skip to content

Commit

Permalink
Merge pull request #4814 from morozov/deprecate-asset-fully-qualified…
Browse files Browse the repository at this point in the history
…-name

Deprecate AbstractAsset::getFullQualifiedName()
  • Loading branch information
morozov authored Sep 28, 2021
2 parents b631c0b + dffebf1 commit b44d2d3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 3.2

## Deprecated `AbstractAsset::getFullQualifiedName()`.

The `AbstractAsset::getFullQualifiedName()` method has been deprecated. Use `::getNamespaceName()`
and `::getName()` instead.

## Deprecated schema methods related to explicit foreign key indexes.

The following methods have been deprecated:
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@
See https://github.com/doctrine/dbal/pull/4822
-->
<referencedMethod name="Doctrine\DBAL\Schema\SchemaConfig::hasExplicitForeignKeyIndexes"/>
<!--
TODO: remove in 4.0.0
See https://github.com/doctrine/dbal/pull/4814
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::getFullQualifiedName"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
Expand Down
12 changes: 11 additions & 1 deletion src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Deprecations\Deprecation;

use function array_map;
use function crc32;
Expand Down Expand Up @@ -102,20 +103,29 @@ public function getShortestName($defaultNamespaceName)
}

/**
* The normalized name is full-qualified and lowerspaced. Lowerspacing is
* The normalized name is full-qualified and lower-cased. Lower-casing is
* actually wrong, but we have to do it to keep our sanity. If you are
* using database objects that only differentiate in the casing (FOO vs
* Foo) then you will NOT be able to use Doctrine Schema abstraction.
*
* Every non-namespaced element is prefixed with the default namespace
* name which is passed as argument to this method.
*
* @deprecated Use {@link getNamespaceName()} and {@link getName()} instead.
*
* @param string $defaultNamespaceName
*
* @return string
*/
public function getFullQualifiedName($defaultNamespaceName)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4814',
'AbstractAsset::getFullQualifiedName() is deprecated.'
. ' Use AbstractAsset::getNamespaceName() and ::getName() instead.'
);

$name = $this->getName();
if ($this->_namespace === null) {
$name = $defaultNamespaceName . '.' . $name;
Expand Down
9 changes: 7 additions & 2 deletions src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function hasExplicitForeignKeyIndexes()
protected function _addTable(Table $table)
{
$namespaceName = $table->getNamespaceName();
$tableName = $table->getFullQualifiedName($this->getName());
$tableName = $this->normalizeName($table);

if (isset($this->_tables[$tableName])) {
throw SchemaException::tableAlreadyExists($tableName);
Expand All @@ -138,7 +138,7 @@ protected function _addTable(Table $table)
protected function _addSequence(Sequence $sequence)
{
$namespaceName = $sequence->getNamespaceName();
$seqName = $sequence->getFullQualifiedName($this->getName());
$seqName = $this->normalizeName($sequence);

if (isset($this->_sequences[$seqName])) {
throw SchemaException::sequenceAlreadyExists($seqName);
Expand Down Expand Up @@ -208,6 +208,11 @@ private function getFullQualifiedAssetName($name)
return strtolower($name);
}

private function normalizeName(AbstractAsset $asset): string
{
return $asset->getFullQualifiedName($this->getName());
}

/**
* Returns the unquoted representation of a given asset name.
*
Expand Down

0 comments on commit b44d2d3

Please sign in to comment.