1 | <?php namespace Arcanedev\LaravelApiHelper\Http; |
||
12 | class JsonResponder implements JsonResponseContract |
||
13 | { |
||
14 | /* ----------------------------------------------------------------- |
||
15 | | Properties |
||
16 | | ----------------------------------------------------------------- |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | * The response factory. |
||
21 | * |
||
22 | * @var \Illuminate\Contracts\Routing\ResponseFactory |
||
23 | */ |
||
24 | protected $response; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Constructor |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | |||
31 | /** |
||
32 | * JsonResponse constructor. |
||
33 | * |
||
34 | * @param \Illuminate\Contracts\Routing\ResponseFactory $response |
||
35 | */ |
||
36 | 28 | public function __construct(ResponseFactory $response) |
|
40 | |||
41 | /* ----------------------------------------------------------------- |
||
42 | | Main Methods |
||
43 | | ----------------------------------------------------------------- |
||
44 | */ |
||
45 | |||
46 | /** |
||
47 | * Respond with a success response. |
||
48 | * |
||
49 | * @param array $data |
||
50 | * @param int $status |
||
51 | * @param string $code |
||
52 | * @param array $headers |
||
53 | * @param int $options |
||
54 | * |
||
55 | * @return \Illuminate\Http\JsonResponse |
||
56 | */ |
||
57 | 16 | public function success(array $data = [], $status = 200, $code = 'success', array $headers = [], $options = 0) |
|
61 | |||
62 | /** |
||
63 | * Respond with an error response. |
||
64 | * |
||
65 | * @param array $data |
||
66 | * @param int $status |
||
67 | * @param string $code |
||
68 | * @param array $headers |
||
69 | * @param int $options |
||
70 | * |
||
71 | * @return \Illuminate\Http\JsonResponse |
||
72 | */ |
||
73 | 12 | public function error(array $data = [], $status = 400, $code = 'error', array $headers = [], $options = 0) |
|
77 | |||
78 | /** |
||
79 | * Respond with a json response. |
||
80 | * |
||
81 | * @param array $data |
||
82 | * @param int $status |
||
83 | * @param string $code |
||
84 | * @param array $headers |
||
85 | * @param int $options |
||
86 | * |
||
87 | * @return \Illuminate\Http\JsonResponse |
||
88 | */ |
||
89 | 28 | public function respond(array $data, $status = 200, $code, array $headers = [], $options = 0) |
|
95 | } |
||
96 |