Skip to content

Commit

Permalink
Merge branch '2.14.x' into 2.15.x
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
derrabus committed Dec 31, 2022
2 parents 10d27c1 + 85ac276 commit 515a3d8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 2.14

## Deprecated `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byName($field)` method.

Use `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byFullyQualifiedName($className, $field)` instead.

## Deprecated constants of `Doctrine\ORM\Internal\CommitOrderCalculator`

The following public constants have been deprecated:
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,11 @@ private function getTimestampKey(): ?TimestampCacheKey
protected function getHydrationCacheId()
{
$parameters = [];
$types = [];

foreach ($this->getParameters() as $parameter) {
$parameters[$parameter->getName()] = $this->processParameterValue($parameter->getValue());
$types[$parameter->getName()] = $parameter->getType();
}

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

return $queryCacheProfile->generateCacheKeys($sql, $parameters, $hints);
return $queryCacheProfile->generateCacheKeys($sql, $parameters, $types, $hints);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ final protected function updateTable(
$targetType = PersisterHelper::getTypeOfField($targetMapping->identifier[0], $targetMapping, $this->em);

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

$types[] = reset($targetType);
Expand Down Expand Up @@ -1199,7 +1199,7 @@ final protected function getOrderBySQL(array $orderBy, string $baseTableAlias):
continue;
}

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

return ' ORDER BY ' . implode(', ', $orderByList);
Expand Down Expand Up @@ -1757,7 +1757,7 @@ private function getSelectConditionStatementColumnSQL(
return [$field];
}

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

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

final class UnrecognizedField extends PersisterException
{
/** @deprecated Use {@see byFullyQualifiedName()} instead. */
public static function byName(string $field): self
{
return new self(sprintf('Unrecognized field: %s', $field));
}

/** @param class-string $className */
public static function byFullyQualifiedName(string $className, string $field): self
{
return new self(sprintf('Unrecognized field: %s::$%s', $className, $field));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Persisters\Exception;

use Doctrine\ORM\Persisters\Exception\UnrecognizedField;
use Doctrine\Tests\Models\Taxi\Car;
use PHPUnit\Framework\TestCase;

class UnrecognizedFieldTest extends TestCase
{
public function testByFullyQualifiedName(): void
{
static::expectException(UnrecognizedField::class);
static::expectExceptionMessage('Unrecognized field: Doctrine\Tests\Models\Taxi\Car::$color');

throw UnrecognizedField::byFullyQualifiedName(Car::class, 'color');
}
}

0 comments on commit 515a3d8

Please sign in to comment.