Skip to content

Commit 263edcb

Browse files
committed
more mongodb fixes
1 parent 1bf26c2 commit 263edcb

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

src/Doctrine/Odm/PropertyHelperTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ protected function getClassMetadata(string $resourceClass): ClassMetadata
4747
$managerRegistry = $this->getManagerRegistry();
4848
$manager = $managerRegistry?->getManagerForClass($resourceClass);
4949

50-
if ($manager) {
51-
return $manager->getClassMetadata($resourceClass);
50+
if (!$manager) {
51+
throw new InvalidArgumentException(\sprintf('Unable to get class metadata for resource "%s". No object manager found.', $resourceClass));
5252
}
5353

54-
return new MongoDbOdmClassMetadata($resourceClass);
54+
return $manager->getClassMetadata($resourceClass);
5555
}
5656

5757
/**

src/Serializer/Mapping/Loader/PropertyMetadataLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
6161
$attributesMetadata = $classMetadata->getAttributesMetadata();
6262

6363
foreach ($refl->getAttributes() as $a) {
64+
// Skip attributes whose classes don't exist (e.g., optional dependencies like MongoDB ODM)
65+
if (!class_exists($a->getName()) && !interface_exists($a->getName())) {
66+
continue;
67+
}
68+
6469
$attribute = $a->newInstance();
70+
6571
if ($attribute instanceof DiscriminatorMap) {
6672
$classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping(
6773
method_exists($attribute, 'getTypeProperty') ? $attribute->getTypeProperty() : $attribute->typeProperty,

tests/Fixtures/TestBundle/ApiResource/AgentDocumentApi.php renamed to tests/Fixtures/TestBundle/ApiResourceOdm/AgentDocumentApi.php

File renamed without changes.

tests/Fixtures/app/AppKernel.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ class_exists(NativePasswordHasher::class) ? 'password_hashers' : 'encoders' => [
314314
if ('mongodb' === $this->environment) {
315315
$c->prependExtensionConfig('api_platform', [
316316
'mapping' => [
317-
'paths' => ['%kernel.project_dir%/../TestBundle/Resources/config/api_resources_odm'],
317+
'paths' => [
318+
'%kernel.project_dir%/../TestBundle/Resources/config/api_resources_odm',
319+
'%kernel.project_dir%/../TestBundle/ApiResourceOdm',
320+
],
318321
],
319322
]);
320323

tests/Fixtures/app/config/config_mongodb.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ api_platform:
2626
mapping:
2727
paths:
2828
- '%kernel.project_dir%/../TestBundle/Model'
29-
- '%kernel.project_dir%/../TestBundle/ApiResource/AgentDocumentApi.php'
29+
- '%kernel.project_dir%/../TestBundle/ApiResourceOdm/AgentDocumentApi.php'
3030

3131
services:
3232
app.my_dummy_resource.mongodb.boolean_filter:

tests/Functional/Parameters/QueryParameterStateOptionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
1717
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\AgentApi;
18-
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\AgentDocumentApi;
18+
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResourceOdm\AgentDocumentApi;
1919
use ApiPlatform\Tests\Fixtures\TestBundle\Document\AgentDocument;
2020
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Agent;
2121
use ApiPlatform\Tests\SetupClassResourcesTrait;

0 commit comments

Comments
 (0)