Skip to content

Commit a9205c4

Browse files
author
Nil Portugues Caldero
committed
Fixed Trait. Methods are now protected and objects namespace have been corrected
1 parent c9857cd commit a9205c4

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

src/Serializer/JsonApiResponseTrait.php

+33-23
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
namespace NilPortugues\Symfony\JsonApiBundle\Serializer;
44

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;
515
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
616

717
trait JsonApiResponseTrait
818
{
919
/**
10-
* @param \Psr\Http\Message\ResponseInterface $response
20+
* @param ResponseInterface $response
1121
*
12-
* @return \Psr\Http\Message\ResponseInterface
22+
* @return ResponseInterface
1323
*/
14-
protected function addHeaders(\Psr\Http\Message\ResponseInterface $response)
24+
protected function addHeaders(ResponseInterface $response)
1525
{
1626
return $response;
1727
}
@@ -21,108 +31,108 @@ protected function addHeaders(\Psr\Http\Message\ResponseInterface $response)
2131
*
2232
* @return \Symfony\Component\HttpFoundation\Response
2333
*/
24-
private function errorResponse($json)
34+
protected function errorResponse($json)
2535
{
2636
return (new HttpFoundationFactory())
27-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ErrorResponse($json)));
37+
->createResponse($this->addHeaders(new BadRequest($json)));
2838
}
2939

3040
/**
3141
* @param string $json
3242
*
3343
* @return \Symfony\Component\HttpFoundation\Response
3444
*/
35-
private function resourceCreatedResponse($json)
45+
protected function resourceCreatedResponse($json)
3646
{
3747
return (new HttpFoundationFactory())
38-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ResourceCreatedResponse($json)));
48+
->createResponse($this->addHeaders(new ResourceCreated($json)));
3949
}
4050

4151
/**
4252
* @param string $json
4353
*
4454
* @return \Symfony\Component\HttpFoundation\Response
4555
*/
46-
private function resourceDeletedResponse($json)
56+
protected function resourceDeletedResponse($json)
4757
{
4858
return (new HttpFoundationFactory())
49-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ResourceDeletedResponse($json)));
59+
->createResponse($this->addHeaders(new ResourceDeleted($json)));
5060
}
5161

5262
/**
5363
* @param string $json
5464
*
5565
* @return \Symfony\Component\HttpFoundation\Response
5666
*/
57-
private function resourceNotFoundResponse($json)
67+
protected function resourceNotFoundResponse($json)
5868
{
5969
return (new HttpFoundationFactory())
60-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ResourceNotFoundResponse($json)));
70+
->createResponse($this->addHeaders(new ResourceNotFound($json)));
6171
}
6272

6373
/**
6474
* @param string $json
6575
*
6676
* @return \Symfony\Component\HttpFoundation\Response
6777
*/
68-
private function resourcePatchErrorResponse($json)
78+
protected function resourcePatchErrorResponse($json)
6979
{
7080
return (new HttpFoundationFactory())
71-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ResourcePatchErrorResponse($json)));
81+
->createResponse($this->addHeaders(new UnprocessableEntity($json)));
7282
}
7383

7484
/**
7585
* @param string $json
7686
*
7787
* @return \Symfony\Component\HttpFoundation\Response
7888
*/
79-
private function resourcePostErrorResponse($json)
89+
protected function resourcePostErrorResponse($json)
8090
{
8191
return (new HttpFoundationFactory())
82-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ResourcePostErrorResponse($json)));
92+
->createResponse($this->addHeaders(new UnprocessableEntity($json)));
8393
}
8494

8595
/**
8696
* @param string $json
8797
*
8898
* @return \Symfony\Component\HttpFoundation\Response
8999
*/
90-
private function resourceProcessingResponse($json)
100+
protected function resourceProcessingResponse($json)
91101
{
92102
return (new HttpFoundationFactory())
93-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ResourceProcessingResponse($json)));
103+
->createResponse($this->addHeaders(new ResourceProcessing($json)));
94104
}
95105

96106
/**
97107
* @param string $json
98108
*
99109
* @return \Symfony\Component\HttpFoundation\Response
100110
*/
101-
private function resourceUpdatedResponse($json)
111+
protected function resourceUpdatedResponse($json)
102112
{
103113
return (new HttpFoundationFactory())
104-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\ResourceUpdatedResponse($json)));
114+
->createResponse($this->addHeaders(new ResourceUpdated($json)));
105115
}
106116

107117
/**
108118
* @param string $json
109119
*
110120
* @return \Symfony\Component\HttpFoundation\Response
111121
*/
112-
private function response($json)
122+
protected function response($json)
113123
{
114124
return (new HttpFoundationFactory())
115-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\Response($json)));
125+
->createResponse($this->addHeaders(new Response($json)));
116126
}
117127

118128
/**
119129
* @param string $json
120130
*
121131
* @return \Symfony\Component\HttpFoundation\Response
122132
*/
123-
private function unsupportedActionResponse($json)
133+
protected function unsupportedActionResponse($json)
124134
{
125135
return (new HttpFoundationFactory())
126-
->createResponse($this->addHeaders(new \NilPortugues\Api\JsonApi\Http\Message\UnsupportedActionResponse($json)));
136+
->createResponse($this->addHeaders(new UnsupportedAction($json)));
127137
}
128138
}

0 commit comments

Comments
 (0)