File tree Expand file tree Collapse file tree 2 files changed +20
-11
lines changed
Expand file tree Collapse file tree 2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change 1313
1414namespace ApiPlatform \Metadata ;
1515
16+ use ApiPlatform \Doctrine \Odm \State \Options as DoctrineOdmOptions ;
17+ use ApiPlatform \Doctrine \Orm \State \Options as DoctrineOrmOptions ;
1618use ApiPlatform \State \OptionsInterface ;
1719
1820/**
@@ -617,4 +619,21 @@ public function withExtraProperties(array $extraProperties = []): static
617619
618620 return $ self ;
619621 }
622+
623+ public function getClassFromStateOptions (): ?string
624+ {
625+ $ stateOptions = $ this ->getStateOptions ();
626+
627+ if ($ stateOptions instanceof OptionsInterface) {
628+ if ($ stateOptions instanceof DoctrineOrmOptions) {
629+ return $ stateOptions ->getEntityClass ();
630+ }
631+
632+ if ($ stateOptions instanceof DoctrineOdmOptions) {
633+ return $ stateOptions ->getDocumentClass ();
634+ }
635+ }
636+
637+ return $ this ->getClass ();
638+ }
620639}
Original file line number Diff line number Diff line change 2222use ApiPlatform \Metadata \Resource \ResourceMetadataCollection ;
2323use ApiPlatform \OpenApi \Model \Parameter as OpenApiParameter ;
2424use ApiPlatform \Serializer \Filter \FilterInterface as SerializerFilterInterface ;
25- use ApiPlatform \State \OptionsInterface ;
2625use Psr \Container \ContainerInterface ;
2726use Symfony \Component \Validator \Constraints \Choice ;
2827use Symfony \Component \Validator \Constraints \Count ;
@@ -55,16 +54,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
5554 $ resourceMetadataCollection = $ this ->decorated ?->create($ resourceClass ) ?? new ResourceMetadataCollection ($ resourceClass );
5655
5756 foreach ($ resourceMetadataCollection as $ i => $ resource ) {
58- $ stateOptions = $ resource ->getStateOptions ();
59- if ($ stateOptions instanceof OptionsInterface) {
60- if ($ stateOptions instanceof \ApiPlatform \Doctrine \Orm \State \Options) {
61- $ resourceClass = $ stateOptions ->getEntityClass ();
62- }
63- if ($ stateOptions instanceof \ApiPlatform \Doctrine \Odm \State \Options) {
64- $ resourceClass = $ stateOptions ->getDocumentClass ();
65- }
66- }
67-
57+ $ resourceClass = $ resource ->getClassFromStateOptions ();
6858 $ operations = $ resource ->getOperations ();
6959
7060 $ internalPriority = -1 ;
You can’t perform that action at this time.
0 commit comments