88use MalteHuebner \DataQueryBundle \Parameter \ParameterInterface ;
99use MalteHuebner \DataQueryBundle \Query \QueryInterface ;
1010use MalteHuebner \DataQueryBundle \RequestParameterList \RequestParameterList ;
11- use App \Criticalmass \Util \ClassUtil ;
12- use Sensio \Bundle \FrameworkExtraBundle \Configuration \ParamConverter ;
13- use Symfony \Component \HttpFoundation \Request ;
14- use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1511
1612class ValueAssigner implements ValueAssignerInterface
1713{
18- public function __construct (private readonly ManagerRegistry $ managerRegistry )
14+ public function __construct (
15+ private readonly ManagerRegistry $ managerRegistry
16+ )
1917 {
2018
2119 }
@@ -94,26 +92,42 @@ protected function assignEntityValueFromRepository(RequestParameterList $request
9492 {
9593 $ parameterName = $ queryField ->getParameterName ();
9694 $ entityClass = $ queryField ->getType ();
97- $ methodName = $ queryField ->getMethodName ();
9895
9996 if (!$ requestParameterList ->has ($ parameterName )) {
10097 return $ query ;
10198 }
10299
103- $ id = $ requestParameterList ->get ($ parameterName );
104- $ entityManager = $ this ->managerRegistry ->getManagerForClass ($ entityClass );
100+ $ queryParameterValue = $ requestParameterList ->get ($ parameterName );
101+
102+ if ($ queryField ->getRepository ()) {
103+ $ repository = $ this ->managerRegistry ->getRepository ($ queryField ->getRepository ());
104+ } else {
105+ $ repository = $ this ->managerRegistry ->getRepository ($ entityClass );
106+ }
107+
108+ if (!$ repository ) {
109+ throw new \RuntimeException (sprintf ('No repository found for class %s ' , $ entityClass ));
110+ }
105111
106- if (!$ entityManager ) {
107- throw new \RuntimeException (sprintf ('No entity manager found for class %s ' , $ entityClass ));
112+ if ($ queryField ->getRepositoryMethod ()) {
113+ $ methodName = $ queryField ->getRepositoryMethod ();
114+ } else {
115+ $ methodName = 'find ' ;
108116 }
109117
110- $ entity = $ entityManager ->getRepository ($ entityClass )->find ($ id );
118+ $ entity = $ repository ->$ methodName ($ queryParameterValue );
119+
120+ if ($ queryField ->getAccessor ()) {
121+ $ accessMethodName = $ queryField ->getAccessor ();
122+ $ entity = $ entity ->$ accessMethodName ();
123+ }
111124
112125 if (null === $ entity ) {
113126 return $ query ;
114127 }
115128
116- $ query ->$ methodName ($ entity );
129+ $ setMethodName = $ queryField ->getMethodName ();
130+ $ query ->$ setMethodName ($ entity );
117131
118132 return $ query ;
119133 }
@@ -126,5 +140,4 @@ protected function convertToInt(string $stringValue, string $parameterName): int
126140
127141 return (int )$ stringValue ;
128142 }
129-
130143}
0 commit comments