23
23
use FOS \RestBundle \Controller \Annotations \QueryParam ;
24
24
25
25
use FOS \RestBundle \Request \ParamFetcher ;
26
+ use Symfony \Component \HttpFoundation \Request ;
26
27
use Symfony \Component \HttpFoundation \Response ;
27
28
use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
28
29
@@ -56,27 +57,28 @@ public function getBookAction($id){
56
57
}
57
58
58
59
/**
59
- * @RequestParam(name="data", nullable=false)
60
- *
61
- * @param ParamFetcher $paramFetcher
60
+ * @param Request $request
62
61
* @throws FormException
63
62
* @return Response
64
63
*/
65
- public function postBookAction (ParamFetcher $ paramFetcher ){
64
+ public function postBookAction (Request $ request ){
65
+ // @TODO: restore ParamFetcher
66
+ // @TODO: workaround for https://github.com/FriendsOfSymfony/FOSRestBundle/issues/2258
66
67
67
68
$ book = new Book ();
68
- return $ this ->save ($ book , $ paramFetcher );
69
+ $ body =json_decode ($ request ->getContent (), true );
70
+ return $ this ->save ($ book , $ body ['data ' ]);
69
71
}
70
72
71
73
/**
72
- * @RequestParam(name="data", nullable=false)
73
- *
74
74
* @param int $id
75
- * @param ParamFetcher $paramFetcher
75
+ * @param Request $request
76
76
* @throws FormException
77
77
* @return Response
78
78
*/
79
- public function putBookAction ($ id , ParamFetcher $ paramFetcher ){
79
+ public function putBookAction ($ id , Request $ request ){
80
+ // @TODO: restore ParamFetcher
81
+ // @TODO: workaround for https://github.com/FriendsOfSymfony/FOSRestBundle/issues/2258
80
82
81
83
$ em = $ this ->getDoctrine ()->getManager ();
82
84
$ book = $ em ->getRepository (Book::class)->find ($ id );
@@ -85,18 +87,20 @@ public function putBookAction($id, ParamFetcher $paramFetcher){
85
87
throw new ResourceNotFoundException ("Resource $ id not found " );
86
88
}
87
89
88
- return $ this ->save ($ book , $ paramFetcher );
90
+ $ body =json_decode ($ request ->getContent (), true );
91
+ return $ this ->save ($ book , $ body ['data ' ]);
89
92
}
90
93
91
94
/**
92
95
* @param Book $book
93
- * @param ParamFetcher $paramFetcher
96
+ * @param $data
94
97
* @return Response
95
98
*/
96
- private function save (Book $ book , ParamFetcher $ paramFetcher ){
99
+ private function save (Book $ book , array $ data ){
97
100
98
101
$ form = $ this ->createForm (BookType::class, $ book );
99
- $ requestBody =$ paramFetcher ->get ('data ' );
102
+ // $requestBody=$paramFetcher->get('data');
103
+ $ requestBody = $ data ;
100
104
101
105
$ form ->submit ($ requestBody );
102
106
0 commit comments