22
22
use ApiPlatform \Metadata \Operation ;
23
23
use ApiPlatform \Metadata \Resource \Factory \ResourceMetadataCollectionFactoryInterface ;
24
24
use ApiPlatform \Metadata \Resource \ResourceMetadataCollection ;
25
+ use ApiPlatform \State \Util \StateOptionsTrait ;
25
26
use Doctrine \ORM \EntityManagerInterface ;
26
27
use Doctrine \Persistence \ManagerRegistry ;
27
28
28
29
final class DoctrineOrmResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface
29
30
{
31
+ use StateOptionsTrait;
32
+
30
33
public function __construct (private readonly ManagerRegistry $ managerRegistry , private readonly ResourceMetadataCollectionFactoryInterface $ decorated )
31
34
{
32
35
}
@@ -45,10 +48,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
45
48
if ($ operations ) {
46
49
/** @var Operation $operation */
47
50
foreach ($ resourceMetadata ->getOperations () as $ operationName => $ operation ) {
48
- $ entityClass = $ operation ->getClass ();
49
- if (($ options = $ operation ->getStateOptions ()) && $ options instanceof Options && $ options ->getEntityClass ()) {
50
- $ entityClass = $ options ->getEntityClass ();
51
- }
51
+ $ entityClass = $ this ->getStateOptionsClass ($ operation , $ operation ->getClass (), Options::class);
52
52
53
53
if (!$ this ->managerRegistry ->getManagerForClass ($ entityClass ) instanceof EntityManagerInterface) {
54
54
continue ;
@@ -64,10 +64,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
64
64
65
65
if ($ graphQlOperations ) {
66
66
foreach ($ graphQlOperations as $ operationName => $ graphQlOperation ) {
67
- $ entityClass = $ graphQlOperation ->getClass ();
68
- if (($ options = $ graphQlOperation ->getStateOptions ()) && $ options instanceof Options && $ options ->getEntityClass ()) {
69
- $ entityClass = $ options ->getEntityClass ();
70
- }
67
+ $ entityClass = $ this ->getStateOptionsClass ($ graphQlOperation , $ graphQlOperation ->getClass (), Options::class);
71
68
72
69
if (!$ this ->managerRegistry ->getManagerForClass ($ entityClass ) instanceof EntityManagerInterface) {
73
70
continue ;
0 commit comments