Skip to content

Commit 429c116

Browse files
committed
orm/odm
1 parent 45dde86 commit 429c116

File tree

6 files changed

+30
-1790
lines changed

6 files changed

+30
-1790
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: 5 additions & 1 deletion
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.
@@ -77,11 +78,14 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
7778
'php_errors' => ['log' => true],
7879
'router' => ['utf8' => true],
7980
'http_method_override' => false,
80-
'annotations' => false,
8181
'handle_all_throwables' => true,
8282
'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7],
8383
];
8484

85+
if (!class_exists(Type::class)) {
86+
$c->setParameter('.json_streamer.lazy_ghosts_dir', __DIR__.'/cache/json_streamer_lazy_ghost');
87+
}
88+
8589
$c->prependExtensionConfig('framework', $config);
8690

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

src/Doctrine/Orm/Tests/AppKernel.php

Lines changed: 14 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,7 +84,20 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
8384
'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7],
8485
];
8586

87+
$ormConfig = ['auto_generate_proxy_classes' => '%kernel.debug%'];
88+
89+
if (!class_exists(Type::class)) {
90+
unset($config['annotations']);
91+
unset($ormConfig['auto_generate_proxy_classes']);
92+
$c->setParameter('.json_streamer.lazy_ghosts_dir', __DIR__.'/cache/json_streamer_lazy_ghost');
93+
}
94+
8695
$c->prependExtensionConfig('framework', $config);
96+
$c->prependExtensionConfig('doctrine', [
97+
'orm' => [
98+
$ormConfig,
99+
],
100+
]);
87101

88102
$loader->load(__DIR__.'/config.yml');
89103
}

src/Doctrine/Orm/Tests/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ doctrine:
77
symfony_uuid: Symfony\Bridge\Doctrine\Types\UuidType
88

99
orm:
10-
auto_generate_proxy_classes: '%kernel.debug%'
1110
controller_resolver:
1211
enabled: false
1312
auto_mapping: false

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)