Skip to content

Commit ae73e20

Browse files
committed
orm/odm
1 parent 45dde86 commit ae73e20

File tree

5 files changed

+23
-1788
lines changed

5 files changed

+23
-1788
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,3 @@ parameters:
173173
identifier: method.notFound
174174
paths:
175175
- tests/Functional/JsonStreamerTest.php
176-
-
177-
identifier: method.notFound
178-
paths:
179-
- src/Serializer/Mapping/Loader/PropertyMetadataLoader.php

src/Doctrine/Odm/Tests/AppKernel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
2121
use Symfony\Component\HttpKernel\Bundle\Bundle;
2222
use Symfony\Component\HttpKernel\Kernel;
23+
use Symfony\Component\PropertyInfo\Type;
2324

2425
/**
2526
* AppKernel for tests.
@@ -82,6 +83,11 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
8283
'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7],
8384
];
8485

86+
if (!class_exists(Type::class)) {
87+
unset($config['annotations']);
88+
$c->setParameter('.json_streamer.lazy_ghosts_dir', __DIR__.'/cache/json_streamer_lazy_ghost');
89+
}
90+
8591
$c->prependExtensionConfig('framework', $config);
8692

8793
$loader->load(__DIR__.'/config.yml');

src/Doctrine/Orm/Tests/AppKernel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
2121
use Symfony\Component\HttpKernel\Bundle\Bundle;
2222
use Symfony\Component\HttpKernel\Kernel;
23+
use Symfony\Component\PropertyInfo\Type;
2324

2425
/**
2526
* AppKernel for tests.
@@ -83,6 +84,11 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
8384
'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7],
8485
];
8586

87+
if (!class_exists(Type::class)) {
88+
unset($config['annotations']);
89+
$c->setParameter('.json_streamer.lazy_ghosts_dir', __DIR__.'/cache/json_streamer_lazy_ghost');
90+
}
91+
8692
$c->prependExtensionConfig('framework', $config);
8793

8894
$loader->load(__DIR__.'/config.yml');

src/Serializer/Mapping/Loader/PropertyMetadataLoader.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
6464
$attribute = $a->newInstance();
6565
if ($attribute instanceof DiscriminatorMap) {
6666
$classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping(
67-
property_exists($attribute, 'typeProperty') ? $attribute->typeProperty : $attribute->getTypeProperty(),
68-
property_exists($attribute, 'mapping') ? $attribute->mapping : $attribute->getMapping()
67+
method_exists($attribute, 'getTypeProperty') ? $attribute->getTypeProperty() : $attribute->typeProperty,
68+
method_exists($attribute, 'getMapping') ? $attribute->getMapping() : $attribute->mapping
6969
));
7070
continue;
7171
}
7272

7373
if ($attribute instanceof Groups) {
74-
$classGroups = property_exists($attribute, 'groups') ? $attribute->groups : $attribute->getGroups();
74+
$classGroups = method_exists($attribute, 'getGroups') ? $attribute->getGroups() : $attribute->groups;
7575

7676
continue;
7777
}
@@ -116,17 +116,17 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
116116
// This code is adapted from Symfony\Component\Serializer\Mapping\Loader\AttributeLoader
117117
foreach ($attributes[$propertyName] as $attr) {
118118
if ($attr instanceof Groups) {
119-
$groups = property_exists($attr, 'groups') ? $attr->groups : $attr->getGroups();
119+
$groups = method_exists($attr, 'getGroups') ? $attr->getGroups() : $attr->groups;
120120
foreach ($groups as $group) {
121121
$attributeMetadata->addGroup($group);
122122
}
123123
continue;
124124
}
125125

126126
match (true) {
127-
$attr instanceof MaxDepth => $attributeMetadata->setMaxDepth(property_exists($attr, 'maxDepth') ? $attr->maxDepth : $attr->getMaxDepth()),
128-
$attr instanceof SerializedName => $attributeMetadata->setSerializedName(property_exists($attr, 'serializedName') ? $attr->serializedName : $attr->getSerializedName()),
129-
$attr instanceof SerializedPath => $attributeMetadata->setSerializedPath(property_exists($attr, 'serializedPath') ? $attr->serializedPath : $attr->getSerializedPath()),
127+
$attr instanceof MaxDepth => $attributeMetadata->setMaxDepth(method_exists($attr, 'getMaxDepth') ? $attr->getMaxDepth() : $attr->maxDepth),
128+
$attr instanceof SerializedName => $attributeMetadata->setSerializedName(method_exists($attr, 'getSerializedName') ? $attr->getSerializedName() : $attr->serializedName),
129+
$attr instanceof SerializedPath => $attributeMetadata->setSerializedPath(method_exists($attr, 'getSerializedPath') ? $attr->getSerializedPath() : $attr->serializedPath),
130130
$attr instanceof Ignore => $attributeMetadata->setIgnore(true),
131131
$attr instanceof Context => $this->setAttributeContextsForGroups($attr, $attributeMetadata),
132132
default => null,
@@ -149,10 +149,10 @@ private function addAttributeMetadata(ApiProperty $attribute, array &$attributes
149149

150150
private function setAttributeContextsForGroups(Context $annotation, AttributeMetadataInterface $attributeMetadata): void
151151
{
152-
$context = property_exists($annotation, 'context') ? $annotation->context : $annotation->getContext();
153-
$groups = property_exists($annotation, 'groups') ? $annotation->groups : $annotation->getGroups();
154-
$normalizationContext = property_exists($annotation, 'normalizationContext') ? $annotation->normalizationContext : $annotation->getNormalizationContext();
155-
$denormalizationContext = property_exists($annotation, 'denormalizationContext') ? $annotation->denormalizationContext : $annotation->getDenormalizationContext();
152+
$context = method_exists($annotation, 'getContext') ? $annotation->getContext() : $annotation->context;
153+
$groups = method_exists($annotation, 'getGroups') ? $annotation->getGroups() : $annotation->groups;
154+
$normalizationContext = method_exists($annotation, 'getNormalizationContext') ? $annotation->getNormalizationContext() : $annotation->normalizationContext;
155+
$denormalizationContext = method_exists($annotation, 'getDenormalizationContext') ? $annotation->getDenormalizationContext() : $annotation->denormalizationContext;
156156

157157
if ($normalizationContext || $context) {
158158
$attributeMetadata->setNormalizationContextForGroups($normalizationContext ?: $context, $groups);

0 commit comments

Comments
 (0)