2
2
3
3
namespace NilPortugues \Symfony \JsonApiBundle \Serializer ;
4
4
5
+ use NilPortugues \Api \JsonApi \Http \Response \BadRequest ;
6
+ use NilPortugues \Api \JsonApi \Http \Response \ResourceCreated ;
7
+ use NilPortugues \Api \JsonApi \Http \Response \ResourceDeleted ;
8
+ use NilPortugues \Api \JsonApi \Http \Response \ResourceNotFound ;
9
+ use NilPortugues \Api \JsonApi \Http \Response \ResourceProcessing ;
10
+ use NilPortugues \Api \JsonApi \Http \Response \ResourceUpdated ;
11
+ use NilPortugues \Api \JsonApi \Http \Response \Response ;
12
+ use NilPortugues \Api \JsonApi \Http \Response \UnprocessableEntity ;
13
+ use NilPortugues \Api \JsonApi \Http \Response \UnsupportedAction ;
14
+ use Psr \Http \Message \ResponseInterface ;
5
15
use Symfony \Bridge \PsrHttpMessage \Factory \HttpFoundationFactory ;
6
16
7
17
trait JsonApiResponseTrait
8
18
{
9
19
/**
10
- * @param \Psr\Http\Message\ ResponseInterface $response
20
+ * @param ResponseInterface $response
11
21
*
12
- * @return \Psr\Http\Message\ ResponseInterface
22
+ * @return ResponseInterface
13
23
*/
14
- protected function addHeaders (\ Psr \ Http \ Message \ ResponseInterface $ response )
24
+ protected function addHeaders (ResponseInterface $ response )
15
25
{
16
26
return $ response ;
17
27
}
@@ -21,108 +31,108 @@ protected function addHeaders(\Psr\Http\Message\ResponseInterface $response)
21
31
*
22
32
* @return \Symfony\Component\HttpFoundation\Response
23
33
*/
24
- private function errorResponse ($ json )
34
+ protected function errorResponse ($ json )
25
35
{
26
36
return (new HttpFoundationFactory ())
27
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ErrorResponse ($ json )));
37
+ ->createResponse ($ this ->addHeaders (new BadRequest ($ json )));
28
38
}
29
39
30
40
/**
31
41
* @param string $json
32
42
*
33
43
* @return \Symfony\Component\HttpFoundation\Response
34
44
*/
35
- private function resourceCreatedResponse ($ json )
45
+ protected function resourceCreatedResponse ($ json )
36
46
{
37
47
return (new HttpFoundationFactory ())
38
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ResourceCreatedResponse ($ json )));
48
+ ->createResponse ($ this ->addHeaders (new ResourceCreated ($ json )));
39
49
}
40
50
41
51
/**
42
52
* @param string $json
43
53
*
44
54
* @return \Symfony\Component\HttpFoundation\Response
45
55
*/
46
- private function resourceDeletedResponse ($ json )
56
+ protected function resourceDeletedResponse ($ json )
47
57
{
48
58
return (new HttpFoundationFactory ())
49
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ResourceDeletedResponse ($ json )));
59
+ ->createResponse ($ this ->addHeaders (new ResourceDeleted ($ json )));
50
60
}
51
61
52
62
/**
53
63
* @param string $json
54
64
*
55
65
* @return \Symfony\Component\HttpFoundation\Response
56
66
*/
57
- private function resourceNotFoundResponse ($ json )
67
+ protected function resourceNotFoundResponse ($ json )
58
68
{
59
69
return (new HttpFoundationFactory ())
60
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ResourceNotFoundResponse ($ json )));
70
+ ->createResponse ($ this ->addHeaders (new ResourceNotFound ($ json )));
61
71
}
62
72
63
73
/**
64
74
* @param string $json
65
75
*
66
76
* @return \Symfony\Component\HttpFoundation\Response
67
77
*/
68
- private function resourcePatchErrorResponse ($ json )
78
+ protected function resourcePatchErrorResponse ($ json )
69
79
{
70
80
return (new HttpFoundationFactory ())
71
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ResourcePatchErrorResponse ($ json )));
81
+ ->createResponse ($ this ->addHeaders (new UnprocessableEntity ($ json )));
72
82
}
73
83
74
84
/**
75
85
* @param string $json
76
86
*
77
87
* @return \Symfony\Component\HttpFoundation\Response
78
88
*/
79
- private function resourcePostErrorResponse ($ json )
89
+ protected function resourcePostErrorResponse ($ json )
80
90
{
81
91
return (new HttpFoundationFactory ())
82
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ResourcePostErrorResponse ($ json )));
92
+ ->createResponse ($ this ->addHeaders (new UnprocessableEntity ($ json )));
83
93
}
84
94
85
95
/**
86
96
* @param string $json
87
97
*
88
98
* @return \Symfony\Component\HttpFoundation\Response
89
99
*/
90
- private function resourceProcessingResponse ($ json )
100
+ protected function resourceProcessingResponse ($ json )
91
101
{
92
102
return (new HttpFoundationFactory ())
93
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ResourceProcessingResponse ($ json )));
103
+ ->createResponse ($ this ->addHeaders (new ResourceProcessing ($ json )));
94
104
}
95
105
96
106
/**
97
107
* @param string $json
98
108
*
99
109
* @return \Symfony\Component\HttpFoundation\Response
100
110
*/
101
- private function resourceUpdatedResponse ($ json )
111
+ protected function resourceUpdatedResponse ($ json )
102
112
{
103
113
return (new HttpFoundationFactory ())
104
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ ResourceUpdatedResponse ($ json )));
114
+ ->createResponse ($ this ->addHeaders (new ResourceUpdated ($ json )));
105
115
}
106
116
107
117
/**
108
118
* @param string $json
109
119
*
110
120
* @return \Symfony\Component\HttpFoundation\Response
111
121
*/
112
- private function response ($ json )
122
+ protected function response ($ json )
113
123
{
114
124
return (new HttpFoundationFactory ())
115
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ Response ($ json )));
125
+ ->createResponse ($ this ->addHeaders (new Response ($ json )));
116
126
}
117
127
118
128
/**
119
129
* @param string $json
120
130
*
121
131
* @return \Symfony\Component\HttpFoundation\Response
122
132
*/
123
- private function unsupportedActionResponse ($ json )
133
+ protected function unsupportedActionResponse ($ json )
124
134
{
125
135
return (new HttpFoundationFactory ())
126
- ->createResponse ($ this ->addHeaders (new \ NilPortugues \ Api \ JsonApi \ Http \ Message \ UnsupportedActionResponse ($ json )));
136
+ ->createResponse ($ this ->addHeaders (new UnsupportedAction ($ json )));
127
137
}
128
138
}
0 commit comments