@@ -72,15 +72,16 @@ public function execute(Request $httprequest)
7272 {
7373 $ json = $ httprequest ->getContent ();
7474 $ request = json_decode ($ json , true );
75+ $ requestId = (isset ($ request ['id ' ]) ? $ request ['id ' ] : null );
7576
7677 if ($ request === null ) {
7778 return $ this ->getErrorResponse (self ::PARSE_ERROR , null );
7879 } 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 );
8081 }
8182
8283 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 );
8485 }
8586
8687 $ service = $ this ->container ->get ($ this ->config ['functions ' ][$ request ['method ' ]]['service ' ]);
@@ -94,7 +95,7 @@ public function execute(Request $httprequest)
9495 if (!(count ($ params ) >= $ r ->getNumberOfRequiredParameters ()
9596 && count ($ params ) <= $ r ->getNumberOfParameters ())
9697 ) {
97- return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ request [ ' id ' ] ,
98+ return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ requestId ,
9899 sprintf ('Number of given parameters (%d) does not match the number of expected parameters (%d required, %d total) ' ,
99100 count ($ params ), $ r ->getNumberOfRequiredParameters (), $ r ->getNumberOfParameters ()));
100101 }
@@ -105,7 +106,7 @@ public function execute(Request $httprequest)
105106 /* @var \ReflectionParameter $rp */
106107 $ name = $ rp ->name ;
107108 if (!isset ($ params ->$ name ) && !$ rp ->isOptional ()) {
108- return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ request [ ' id ' ] ,
109+ return $ this ->getErrorResponse (self ::INVALID_PARAMS , $ requestId ,
109110 sprintf ('Parameter %s is missing ' , $ name ));
110111 }
111112 if (isset ($ params ->$ name )) {
@@ -120,12 +121,12 @@ public function execute(Request $httprequest)
120121 try {
121122 $ result = call_user_func_array (array ($ service , $ method ), $ params );
122123 } catch (\Exception $ e ) {
123- return $ this ->getErrorResponse (self ::INTERNAL_ERROR , $ request [ ' id ' ] , $ e ->getMessage ());
124+ return $ this ->getErrorResponse (self ::INTERNAL_ERROR , $ requestId , $ e ->getMessage ());
124125 }
125126
126127 $ response = array ('jsonrpc ' => '2.0 ' );
127128 $ response ['result ' ] = $ result ;
128- $ response ['id ' ] = ( isset ( $ request [ ' id ' ]) ? $ request [ ' id ' ] : null ) ;
129+ $ response ['id ' ] = $ requestId ;
129130
130131 if ($ this ->container ->has ('jms_serializer ' )) {
131132 $ response = $ this ->container ->get ('jms_serializer ' )->serialize ($ response , 'json ' , $ this ->serializationContext );
@@ -135,7 +136,7 @@ public function execute(Request $httprequest)
135136
136137 return new Response ($ response , 200 , array ('Content-Type ' => 'application/json ' ));
137138 } else {
138- return $ this ->getErrorResponse (self ::METHOD_NOT_FOUND , $ request [ ' id ' ] );
139+ return $ this ->getErrorResponse (self ::METHOD_NOT_FOUND , $ requestId );
139140 }
140141 }
141142
0 commit comments