Total Complexity | 2 |
Total Lines | 24 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
22 | trait CreateMethod |
||
23 | { |
||
24 | /** |
||
25 | * Generic 'createMethod' method for REST resources. |
||
26 | * |
||
27 | * @param array<int, string>|null $allowedHttpMethods |
||
28 | * |
||
29 | * @throws Throwable |
||
30 | */ |
||
31 | 18 | public function createMethod( |
|
32 | Request $request, |
||
33 | RestDtoInterface $restDto, |
||
34 | ?array $allowedHttpMethods = null, |
||
35 | ): Response { |
||
|
|||
36 | 18 | $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? ['POST']); |
|
37 | |||
38 | try { |
||
39 | 3 | $data = $resource->create($restDto, true); |
|
40 | |||
41 | return $this |
||
42 | 2 | ->getResponseHandler() |
|
43 | 2 | ->createResponse($request, $data, $resource, Response::HTTP_CREATED); |
|
44 | 1 | } catch (Throwable $exception) { |
|
45 | 1 | throw $this->handleRestMethodException($exception); |
|
46 | } |
||
49 |