PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.4
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.4
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Http / Response.php
kirki / libraries / framework / Http Last commit date
Client 1 week ago Concerns 1 week ago Cookie.php 1 week ago JsonResponse.php 1 week ago RedirectResponse.php 1 week ago Request.php 1 week ago Response.php 1 week ago
Response.php
161 lines
1 <?php
2
3 /**
4 * Handles standardized REST API responses for the plugin.
5 *
6 * @package Framework
7 * @subpackage Http
8 * @since 1.0.0
9 */
10 namespace Kirki\Framework\Http;
11
12 \defined('ABSPATH') || exit;
13 use Kirki\Framework\Http\Concerns\InteractsWithCookies;
14 class Response
15 {
16 use InteractsWithCookies;
17 /**
18 * HTTP status code for a successful request.
19 *
20 * @since 1.0.0
21 * @var int
22 */
23 public const OK = 200;
24 /**
25 * HTTP status code for a successfully created resource.
26 *
27 * @since 1.0.0
28 * @var int
29 */
30 public const CREATED = 201;
31 /**
32 * HTTP status code for a successful request with no content.
33 *
34 * @since 1.0.0
35 * @var int
36 */
37 public const NO_CONTENT = 204;
38 /**
39 * HTTP status code for a multi-status response.
40 *
41 * @since 1.0.0
42 * @var int
43 */
44 public const MULTI_STATUS = 207;
45 /**
46 * HTTP status code for a bad request.
47 *
48 * @since 1.0.0
49 * @var int
50 */
51 public const BAD_REQUEST = 400;
52 /**
53 * HTTP status code for an unauthorized request.
54 *
55 * @since 1.0.0
56 * @var int
57 */
58 public const UNAUTHORIZED = 401;
59 /**
60 * HTTP status code when authentication is required and has failed or has not yet been provided.
61 *
62 * @since 1.0.0
63 * @var int
64 */
65 public const FORBIDDEN = 403;
66 /**
67 * HTTP status code when a requested resource is not found.
68 *
69 * @since 1.0.0
70 * @var int
71 */
72 public const NOT_FOUND = 404;
73 /**
74 * HTTP status code when a request method is not allowed.
75 *
76 * @since 1.0.0
77 * @var int
78 */
79 public const METHOD_NOT_ALLOWED = 405;
80 /**
81 * HTTP status code when a conflict occurs.
82 *
83 * @since 1.0.0
84 * @var int
85 */
86 public const CONFLICT = 409;
87 /**
88 * HTTP status code when a request is unprocessable.
89 *
90 * @since 1.0.0
91 * @var int
92 */
93 public const UNPROCESSABLE_ENTITY = 422;
94 /**
95 * HTTP status code for too many requests (rate limiting).
96 *
97 * @since 1.0.0
98 * @var int
99 */
100 public const TOO_MANY_REQUESTS = 429;
101 /**
102 * HTTP status code for internal server error.
103 *
104 * @since 1.0.0
105 * @var int
106 */
107 public const INTERNAL_SERVER_ERROR = 500;
108 /**
109 * HTTP status code for not implemented.
110 *
111 * @since 1.0.0
112 * @var int
113 */
114 public const NOT_IMPLEMENTED = 501;
115 /**
116 * HTTP status code for service unavailable.
117 *
118 * @since 1.0.0
119 * @var int
120 */
121 public const SERVICE_UNAVAILABLE = 503;
122 /**
123 * The request headers
124 *
125 * @var array
126 *
127 * @since 1.0.0
128 */
129 protected $headers = [];
130 /**
131 * Send a JSON response.
132 *
133 * @param array $data The data to send.
134 * @param int $status The HTTP status code.
135 * @param array $headers The headers to send.
136 * @param int $options The options to use when encoding the data.
137 *
138 * @return JsonResponse
139 *
140 * @since 1.0.0
141 */
142 public function json($data = [], $status = 200, array $headers = [], int $options = 0)
143 {
144 return new JsonResponse($data, $status, \array_merge($this->headers, $headers), $options);
145 }
146 /**
147 * Set the headers for the response.
148 *
149 * @param array $headers The headers to set.
150 *
151 * @return $this
152 *
153 * @since 1.0.0
154 */
155 public function with_headers(array $headers)
156 {
157 $this->headers = $headers;
158 return $this;
159 }
160 }
161