@@ -72,15 +72,16 @@ public function execute(Request $httprequest)
72
72
{
73
73
$ json = $ httprequest ->getContent ();
74
74
$ request = json_decode ($ json , true );
75
+ $ requestId = (isset ($ request ['id ' ]) ? $ request ['id ' ] : null );
75
76
76
77
if ($ request === null ) {
77
78
return $ this ->getErrorResponse (self ::PARSE_ERROR , null );
78
79
} elseif (!(isset ($ request ['jsonrpc ' ]) && isset ($ request ['method ' ]) && $ request ['jsonrpc ' ] == '2.0 ' )) {
79
- return $ this ->getErrorResponse (self ::INVALID_REQUEST , $ request [ ' id ' ] );
80
+ return $ this ->getErrorResponse (self ::INVALID_REQUEST , $ requestId );
80
81
}
81
82
82
83
if (!in_array ($ request ['method ' ], array_keys ($ this ->config ['functions ' ]))) {
83
- return $ this ->getErrorResponse (self ::METHOD_NOT_FOUND , $ request [ ' id ' ] );
84
+ return $ this ->getErrorResponse (self ::METHOD_NOT_FOUND , $ requestId );
84
85
}
85
86
86
87
$ service = $ this ->container ->get ($ this ->config ['functions ' ][$ request ['method ' ]]['service ' ]);
@@ -94,7 +95,7 @@ public function execute(Request $httprequest)
94
95
if (!(count ($ params ) >= $ r ->getNumberOfRequiredParameters ()
95
96
&& count ($ params ) <= $ r ->getNumberOfParameters ())
96
97
) {
97
- return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ request [ ' id ' ] ,
98
+ return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ requestId ,
98
99
sprintf ('Number of given parameters (%d) does not match the number of expected parameters (%d required, %d total) ' ,
99
100
count ($ params ), $ r ->getNumberOfRequiredParameters (), $ r ->getNumberOfParameters ()));
100
101
}
@@ -105,7 +106,7 @@ public function execute(Request $httprequest)
105
106
/* @var \ReflectionParameter $rp */
106
107
$ name = $ rp ->name ;
107
108
if (!isset ($ params ->$ name ) && !$ rp ->isOptional ()) {
108
- return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ request [ ' id ' ] ,
109
+ return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ requestId ,
109
110
sprintf ('Parameter %s is missing ' , $ name ));
110
111
}
111
112
if (isset ($ params ->$ name )) {
@@ -120,12 +121,12 @@ public function execute(Request $httprequest)
120
121
try {
121
122
$ result = call_user_func_array (array ($ service , $ method ), $ params );
122
123
} catch (\Exception $ e ) {
123
- return $ this ->getErrorResponse (self ::INTERNAL_ERROR , $ request [ ' id ' ] , $ e ->getMessage ());
124
+ return $ this ->getErrorResponse (self ::INTERNAL_ERROR , $ requestId , $ e ->getMessage ());
124
125
}
125
126
126
127
$ response = array ('jsonrpc ' => '2.0 ' );
127
128
$ response ['result ' ] = $ result ;
128
- $ response ['id ' ] = ( isset ( $ request [ ' id ' ]) ? $ request [ ' id ' ] : null ) ;
129
+ $ response ['id ' ] = $ requestId ;
129
130
130
131
if ($ this ->container ->has ('jms_serializer ' )) {
131
132
$ response = $ this ->container ->get ('jms_serializer ' )->serialize ($ response , 'json ' , $ this ->serializationContext );
@@ -135,7 +136,7 @@ public function execute(Request $httprequest)
135
136
136
137
return new Response ($ response , 200 , array ('Content-Type ' => 'application/json ' ));
137
138
} else {
138
- return $ this ->getErrorResponse (self ::METHOD_NOT_FOUND , $ request [ ' id ' ] );
139
+ return $ this ->getErrorResponse (self ::METHOD_NOT_FOUND , $ requestId );
139
140
}
140
141
}
141
142
0 commit comments