fix(hal): use spl_object_id() for circular reference counters
spl_object_hash() is deprecated in PHP 8.6, and the HAL ItemNormalizer calls it in isHalCircularReference() on every item it normalizes. The hash is only used as a key for the circular reference counters, so spl_object_id() is a drop-in replacement (same change as doctrine/dbal#7518).
This commit is contained in:
1 parent
28b90c7e34
commit
167625fa31
1 file changed
+6
-6
@@ -370,19 +370,19 @@ final class ItemNormalizer extends AbstractItemNormalizer
|
||||
*/
|
||||
protected function isHalCircularReference(object $object, array &$context): bool
|
||||
{
|
||||
$objectHash = spl_object_hash($object);
|
||||
$objectId = spl_object_id($object);
|
||||
|
||||
$circularReferenceLimit = $context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT] ?? $this->defaultContext[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT];
|
||||
if (isset($context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash])) {
|
||||
if ($context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] >= $circularReferenceLimit) {
|
||||
unset($context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash]);
|
||||
if (isset($context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId])) {
|
||||
if ($context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId] >= $circularReferenceLimit) {
|
||||
unset($context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
++$context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash];
|
||||
++$context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId];
|
||||
} else {
|
||||
$context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] = 1;
|
||||
$context[self::HAL_CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId] = 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user