Skip to content

Commit 515a3d8

Browse files
committed
Merge branch '2.14.x' into 2.15.x
* 2.14.x: Shorter deprecation message (doctrine#10357) Add Fully-Qualified class name in UnrecognizedField exception to ease debugging (doctrine#10342) Include parameter types in hydration cache key generation (doctrine#10355)
2 parents 10d27c1 + 85ac276 commit 515a3d8

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

UPGRADE.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 2.14
22

3+
## Deprecated `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byName($field)` method.
4+
5+
Use `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byFullyQualifiedName($className, $field)` instead.
6+
37
## Deprecated constants of `Doctrine\ORM\Internal\CommitOrderCalculator`
48

59
The following public constants have been deprecated:

lib/Doctrine/ORM/AbstractQuery.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,11 @@ private function getTimestampKey(): ?TimestampCacheKey
13211321
protected function getHydrationCacheId()
13221322
{
13231323
$parameters = [];
1324+
$types = [];
13241325

13251326
foreach ($this->getParameters() as $parameter) {
13261327
$parameters[$parameter->getName()] = $this->processParameterValue($parameter->getValue());
1328+
$types[$parameter->getName()] = $parameter->getType();
13271329
}
13281330

13291331
$sql = $this->getSQL();
@@ -1335,7 +1337,7 @@ protected function getHydrationCacheId()
13351337
ksort($hints);
13361338
assert($queryCacheProfile !== null);
13371339

1338-
return $queryCacheProfile->generateCacheKeys($sql, $parameters, $hints);
1340+
return $queryCacheProfile->generateCacheKeys($sql, $parameters, $types, $hints);
13391341
}
13401342

13411343
/**

lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ final protected function updateTable(
487487
$targetType = PersisterHelper::getTypeOfField($targetMapping->identifier[0], $targetMapping, $this->em);
488488

489489
if ($targetType === []) {
490-
throw UnrecognizedField::byName($targetMapping->identifier[0]);
490+
throw UnrecognizedField::byFullyQualifiedName($this->class->name, $targetMapping->identifier[0]);
491491
}
492492

493493
$types[] = reset($targetType);
@@ -1199,7 +1199,7 @@ final protected function getOrderBySQL(array $orderBy, string $baseTableAlias):
11991199
continue;
12001200
}
12011201

1202-
throw UnrecognizedField::byName($fieldName);
1202+
throw UnrecognizedField::byFullyQualifiedName($this->class->name, $fieldName);
12031203
}
12041204

12051205
return ' ORDER BY ' . implode(', ', $orderByList);
@@ -1757,7 +1757,7 @@ private function getSelectConditionStatementColumnSQL(
17571757
return [$field];
17581758
}
17591759

1760-
throw UnrecognizedField::byName($field);
1760+
throw UnrecognizedField::byFullyQualifiedName($this->class->name, $field);
17611761
}
17621762

17631763
/**

lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php

+7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010

1111
final class UnrecognizedField extends PersisterException
1212
{
13+
/** @deprecated Use {@see byFullyQualifiedName()} instead. */
1314
public static function byName(string $field): self
1415
{
1516
return new self(sprintf('Unrecognized field: %s', $field));
1617
}
18+
19+
/** @param class-string $className */
20+
public static function byFullyQualifiedName(string $className, string $field): self
21+
{
22+
return new self(sprintf('Unrecognized field: %s::$%s', $className, $field));
23+
}
1724
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Persisters\Exception;
6+
7+
use Doctrine\ORM\Persisters\Exception\UnrecognizedField;
8+
use Doctrine\Tests\Models\Taxi\Car;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class UnrecognizedFieldTest extends TestCase
12+
{
13+
public function testByFullyQualifiedName(): void
14+
{
15+
static::expectException(UnrecognizedField::class);
16+
static::expectExceptionMessage('Unrecognized field: Doctrine\Tests\Models\Taxi\Car::$color');
17+
18+
throw UnrecognizedField::byFullyQualifiedName(Car::class, 'color');
19+
}
20+
}

0 commit comments

Comments
 (0)