1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Action\Form; |
15
|
|
|
|
16
|
|
|
use Silverback\ApiComponentsBundle\Action\AbstractAction; |
17
|
|
|
use Silverback\ApiComponentsBundle\Entity\Component\Form; |
18
|
|
|
use Silverback\ApiComponentsBundle\Factory\Response\ResponseFactory; |
19
|
|
|
use Silverback\ApiComponentsBundle\Form\Handler\FormSubmitHandler; |
20
|
|
|
use Silverback\ApiComponentsBundle\Serializer\SerializeFormatResolver; |
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Daniel West <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class FormPostPatchAction extends AbstractAction |
28
|
|
|
{ |
29
|
|
|
private FormSubmitHandler $formSubmitHandler; |
30
|
|
|
|
31
|
|
|
public function __construct(SerializerInterface $serializer, SerializeFormatResolver $requestFormatResolver, ResponseFactory $responseFactory, FormSubmitHandler $formSubmitHandler) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($serializer, $requestFormatResolver, $responseFactory); |
34
|
|
|
$this->formSubmitHandler = $formSubmitHandler; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function __invoke(Request $request, Form $data) |
38
|
|
|
{ |
39
|
|
|
$decodedContent = $this->serializer->decode($request->getContent(), $this->requestFormatResolver->getFormatFromRequest($request), []); |
40
|
|
|
$isPatchRequest = Request::METHOD_PATCH === $request->getMethod(); |
41
|
|
|
$response = $this->formSubmitHandler->handle($decodedContent, $isPatchRequest, $data, $this->requestFormatResolver->getFormatFromRequest($request)); |
42
|
|
|
|
43
|
|
|
return $this->responseFactory->create($request, $response->getContent(), $response->getStatusCode()); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|