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