-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhpRestfulApiResponse.php
149 lines (134 loc) · 4.34 KB
/
PhpRestfulApiResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Created by PhpStorm.
* User: harry
* Date: 2/14/18
* Time: 11:57 AM
*/
namespace PhpRestfulApiResponse\Contracts;
use League\Fractal\Pagination\Cursor;
use League\Fractal\TransformerAbstract;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response;
interface PhpRestfulApiResponse extends ResponseInterface
{
/**
* @param array|null $data
* @param $code
* @param array $headers
* @return Response|static
*/
public function withArray($data, $code = 200, array $headers = []);
/**
* @param $data
* @param TransformerAbstract|callable $transformer
* @param int $code
* @param null $resourceKey
* @param array $meta
* @param array $headers
* @return Response
*/
public function withItem($data, $transformer, $code = 200, $resourceKey = null, $meta = [], array $headers = []);
/**
* @param $data
* @param TransformerAbstract|callable $transformer
* @param int $code
* @param null $resourceKey
* @param Cursor|null $cursor
* @param array $meta
* @param array $headers
* @return Response
*/
public function withCollection($data, $transformer, $code = 200, $resourceKey = null, Cursor $cursor = null, $meta = [], array $headers = []);
/**
* Generates a response with custom code HTTP header and a given message.
*
* @param $message
* @param int $statusCode
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function withError($message, int $statusCode, $errorCode = null, array $headers = []);
/**
* Generates a response with a 403 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorForbidden(string $message = '', $errorCode = null, array $headers = []);
/**
* Generates a response with a 500 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorInternalError(string $message = '', $errorCode = null, array $headers = []);
/**
* Generates a response with a 404 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorNotFound(string $message = '', $errorCode = null, array $headers = []);
/**
* Generates a response with a 401 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorUnauthorized(string $message = '', $errorCode = null, array $headers = []);
/**
* Generates a response with a 400 HTTP header and a given message.
*
* @param array $message
* @param int|array $errorCode
* @param array $headers
* @return mixed
*/
public function errorWrongArgs(array $message, $errorCode = null, array $headers = []);
/**
* Generates a response with a 410 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorGone(string $message = '', $errorCode = null, array $headers = []);
/**
* Generates a response with a 405 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorMethodNotAllowed(string $message = '', $errorCode = null, array $headers = []);
/**
* Generates a Response with a 431 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorUnwillingToProcess(string $message = '', $errorCode = null, array $headers = []);
/**
* Generates a Response with a 422 HTTP header and a given message.
*
* @param string $message
* @param int|string $errorCode
* @param array $headers
* @return mixed
*/
public function errorUnprocessable(string $message = '', $errorCode = null, array $headers = []);
}