Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae75b12

Browse files
committed
1 parent d18f108 commit ae75b12

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

‎src/Controller/BookController.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use FOS\RestBundle\Controller\Annotations\QueryParam;
2424

2525
use FOS\RestBundle\Request\ParamFetcher;
26+
use Symfony\Component\HttpFoundation\Request;
2627
use Symfony\Component\HttpFoundation\Response;
2728
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
2829

@@ -56,27 +57,28 @@ public function getBookAction($id){
5657
}
5758

5859
/**
59-
* @RequestParam(name="data", nullable=false)
60-
*
61-
* @param ParamFetcher $paramFetcher
60+
* @param Request $request
6261
* @throws FormException
6362
* @return Response
6463
*/
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
6667

6768
$book = new Book();
68-
return $this->save($book, $paramFetcher);
69+
$body=json_decode($request->getContent(), true);
70+
return $this->save($book, $body['data']);
6971
}
7072

7173
/**
72-
* @RequestParam(name="data", nullable=false)
73-
*
7474
* @param int $id
75-
* @param ParamFetcher $paramFetcher
75+
* @param Request $request
7676
* @throws FormException
7777
* @return Response
7878
*/
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
8082

8183
$em = $this->getDoctrine()->getManager();
8284
$book = $em->getRepository(Book::class)->find($id);
@@ -85,18 +87,20 @@ public function putBookAction($id, ParamFetcher $paramFetcher){
8587
throw new ResourceNotFoundException("Resource $id not found");
8688
}
8789

88-
return $this->save($book, $paramFetcher);
90+
$body=json_decode($request->getContent(), true);
91+
return $this->save($book, $body['data']);
8992
}
9093

9194
/**
9295
* @param Book $book
93-
* @param ParamFetcher $paramFetcher
96+
* @param $data
9497
* @return Response
9598
*/
96-
private function save(Book $book, ParamFetcher$paramFetcher){
99+
private function save(Book $book, array$data){
97100

98101
$form = $this->createForm(BookType::class, $book);
99-
$requestBody=$paramFetcher->get('data');
102+
// $requestBody=$paramFetcher->get('data');
103+
$requestBody = $data;
100104

101105
$form->submit($requestBody);
102106

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /