| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Framework\Http\Response; |
| 4 |
|
| 5 |
use Give\Framework\Http\Response\Types\JsonResponse; |
| 6 |
use Give\Framework\Http\Response\Types\RedirectResponse; |
| 7 |
|
| 8 |
/** |
| 9 |
* @since 2.18.0 |
| 10 |
*/ |
| 11 |
class ResponseFactory |
| 12 |
{ |
| 13 |
|
| 14 |
/** |
| 15 |
* Create a new response instance. |
| 16 |
* |
| 17 |
* @param string $content |
| 18 |
* @param int $status |
| 19 |
* @param array $headers |
| 20 |
* @return Response |
| 21 |
*/ |
| 22 |
public function make($content = '', $status = 200, array $headers = []) |
| 23 |
{ |
| 24 |
return new Response($content, $status, $headers); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Create a new "no content" response. |
| 29 |
* |
| 30 |
* @param int $status |
| 31 |
* @param array $headers |
| 32 |
* @return Response |
| 33 |
*/ |
| 34 |
public function noContent($status = 204, array $headers = []) |
| 35 |
{ |
| 36 |
return $this->make('', $status, $headers); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Create a new JSON response instance. |
| 41 |
* |
| 42 |
* @param mixed $data |
| 43 |
* @param int $status |
| 44 |
* @param array $headers |
| 45 |
* @param int $options |
| 46 |
* @return JsonResponse |
| 47 |
*/ |
| 48 |
public function json($data = [], $status = 200, array $headers = [], $options = 0) |
| 49 |
{ |
| 50 |
return new JsonResponse($data, $status, $headers, $options); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Create a new JSONP response instance. |
| 55 |
* |
| 56 |
* @param string $callback |
| 57 |
* @param mixed $data |
| 58 |
* @param int $status |
| 59 |
* @param array $headers |
| 60 |
* @param int $options |
| 61 |
* @return JsonResponse |
| 62 |
*/ |
| 63 |
public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0) |
| 64 |
{ |
| 65 |
return $this->json($data, $status, $headers, $options)->setCallback($callback); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Create a new redirect response to the given path. |
| 70 |
* |
| 71 |
* @param string $path |
| 72 |
* @param int $status |
| 73 |
* @param array $headers |
| 74 |
* @param bool|null $secure |
| 75 |
* @return RedirectResponse |
| 76 |
*/ |
| 77 |
public function redirectTo($path, $status = 302, $headers = [], $secure = null) |
| 78 |
{ |
| 79 |
return new RedirectResponse($path, $status, $headers); |
| 80 |
} |
| 81 |
} |
| 82 |
|