Skip to content

Commit 894458b

Browse files
committed
add a local cache for classMetadataFactory
1 parent 09bbfbe commit 894458b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Hal/Serializer/ItemNormalizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ final class ItemNormalizer extends AbstractItemNormalizer
3030
const FORMAT = 'jsonhal';
3131

3232
private $componentsCache = [];
33+
private $attributesMetadataCache = [];
3334

3435
/**
3536
* {@inheritdoc}
@@ -169,7 +170,10 @@ private function getComponents($object, string $format = null, array $context)
169170
private function populateRelation(array $data, $object, string $format = null, array $context, array $components, string $type): array
170171
{
171172
$class = \get_class($object);
172-
$attributesMetadata = $this->classMetadataFactory ? $this->classMetadataFactory->getMetadataFor($object)->getAttributesMetadata() : null;
173+
174+
$attributesMetadata = \array_key_exists($class, $this->attributesMetadataCache) ?
175+
$this->attributesMetadataCache[$class] :
176+
$this->attributesMetadataCache[$class] = $this->classMetadataFactory ? $this->classMetadataFactory->getMetadataFor($object)->getAttributesMetadata() : null;
173177

174178
$key = '_'.$type;
175179
foreach ($components[$type] as $relation) {

0 commit comments

Comments
 (0)