Skip to content

Commit 79e0a26

Browse files
committed
chore: visibility of private property and methods changed to protected.
Sometimes we may need to override methods. This will give some flexibility.
1 parent b425593 commit 79e0a26

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

src/Http/Request/Request.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ class Request extends Validator implements ArrayAccess, JsonSerializable
1717
{
1818
use IpTool;
1919

20-
private $_route;
20+
protected $route;
2121

22-
private $_rest;
22+
protected $rest;
2323

24-
private $_attributes = [];
24+
protected $attributes = [];
2525

26-
private $_queryParams = [];
26+
protected $queryParams = [];
2727

28-
private $_routeParams = [];
28+
protected $routeParams = [];
2929

30-
private $_body = [];
30+
protected $body = [];
3131

3232
/**
3333
* Undocumented function.
3434
*/
3535
public function __construct(RouteRegister $route = null)
3636
{
37-
$this->_route = $route;
37+
$this->route = $route;
3838
$this->setBody();
3939
$this->setQueryParams();
4040
$this->setRouteParams();
41-
$this->_attributes = (array) $this->_queryParams + (array) $this->_body + (array) $this->_routeParams;
41+
$this->attributes = (array) $this->queryParams + (array) $this->body + (array) $this->routeParams;
4242
}
4343

4444
public function __isset($offset)
@@ -63,8 +63,8 @@ public function __unset($offset)
6363

6464
public function __call($method, $parameters)
6565
{
66-
if (isset($this->_rest) && method_exists($this->_rest, $method)) {
67-
return \call_user_func_array([$this->_rest, $method], $parameters);
66+
if (isset($this->rest) && method_exists($this->rest, $method)) {
67+
return \call_user_func_array([$this->rest, $method], $parameters);
6868
}
6969

7070
throw new RuntimeException('Undefined method [' . (string) $method . '] called on ' . __CLASS__ . 'class.');
@@ -82,7 +82,7 @@ public function __clone()
8282

8383
public function queryParams()
8484
{
85-
return $this->_queryParams;
85+
return $this->queryParams;
8686
}
8787

8888
/**
@@ -92,12 +92,12 @@ public function queryParams()
9292
*/
9393
public function getRoute()
9494
{
95-
return $this->_route;
95+
return $this->route;
9696
}
9797

9898
public function body()
9999
{
100-
return $this->_body;
100+
return $this->body;
101101
}
102102

103103
public function method()
@@ -115,8 +115,8 @@ public function setApiRequest(WP_REST_Request $request)
115115
$this->setBody((array) $request->get_body_params() + (array) $request->get_json_params());
116116
$this->setQueryParams((array) $request->get_query_params());
117117
$this->setRouteParams((array) $request->get_url_params());
118-
$this->_attributes = (array) $request->get_params();
119-
$this->_rest = $request;
118+
$this->attributes = (array) $request->get_params();
119+
$this->rest = $request;
120120
}
121121

122122
/**
@@ -131,12 +131,12 @@ public function files()
131131

132132
public function all()
133133
{
134-
return $this->_attributes;
134+
return $this->attributes;
135135
}
136136

137137
public function get($offset, $default = null)
138138
{
139-
return Arr::get($this->_attributes, $offset, $default);
139+
return Arr::get($this->attributes, $offset, $default);
140140
}
141141

142142
public function input($offset, $default = null)
@@ -157,9 +157,9 @@ public function except()
157157

158158
public function has($offset)
159159
{
160-
return Arr::has($this->_attributes, $offset);
160+
return Arr::has($this->attributes, $offset);
161161

162-
// return isset($this->_attributes[$offset]);
162+
// return isset($this->attributes[$offset]);
163163
}
164164

165165
#[ReturnTypeWillChange]
@@ -189,12 +189,12 @@ public function offsetUnset($offset)
189189
#[ReturnTypeWillChange]
190190
public function jsonSerialize()
191191
{
192-
return $this->_attributes;
192+
return $this->attributes;
193193
}
194194

195195
public function validate($rules, $messages = null, $attributeLabels = null)
196196
{
197-
$validator = $this->make($this->_attributes, $rules, $messages, $attributeLabels);
197+
$validator = $this->make($this->attributes, $rules, $messages, $attributeLabels);
198198

199199
if ($validator->fails()) {
200200
$response = [
@@ -209,50 +209,52 @@ public function validate($rules, $messages = null, $attributeLabels = null)
209209
return $validator->validated();
210210
}
211211

212-
private function setQueryParams($params = [])
212+
protected function setQueryParams($params = [])
213213
{
214214
if (!empty($params)) {
215-
$this->_queryParams = $params;
215+
$this->queryParams = $params;
216216
} elseif (isset($_GET)) {
217-
$this->_queryParams = $_GET;
217+
$this->queryParams = $_GET;
218218
}
219219
}
220220

221-
private function setRouteParams($params = [])
221+
protected function setRouteParams($params = [])
222222
{
223223
if (!empty($params)) {
224-
$this->_routeParams = $params;
224+
$this->routeParams = $params;
225225
foreach ($params as $name => $value) {
226-
$this->_route->setRouteParamValue($name, $value);
226+
$this->route->setRouteParamValue($name, $value);
227227
}
228-
} elseif (isset($this->_route) && !\is_null($this->_route)) {
229-
$this->_routeParams = (array) $this->_route->getRouteParamValues();
228+
} elseif (isset($this->route) && !\is_null($this->route)) {
229+
$this->routeParams = (array) $this->route->getRouteParamValues();
230230
}
231231
}
232232

233-
private function setBody($body = [])
233+
protected function setBody($body = [])
234234
{
235235
if (!empty($body)) {
236-
$this->_body = $body;
236+
$this->body = $body;
237237
} else {
238238
if (
239239
strpos($this->contentType(), 'form-data') === false
240240
&& strpos($this->contentType(), 'x-www-form-urlencoded') === false
241241
) {
242-
$this->_body = JSON::maybeDecode(file_get_contents('php://input'));
242+
$this->body = JSON::maybeDecode(file_get_contents('php://input'));
243243
}
244244

245-
$this->_body = (array) $this->_body + (array) $_POST;
245+
if (!empty($_POST)) {
246+
$this->body = (array) $this->body + (array) $_POST;
247+
}
246248
}
247249
}
248250

249-
private function setAttribute($key, $value)
251+
protected function setAttribute($key, $value)
250252
{
251-
$this->_attributes[$key] = $value;
253+
$this->attributes[$key] = $value;
252254
}
253255

254-
private function unsetAttribute($key)
256+
protected function unsetAttribute($key)
255257
{
256-
unset($this->_attributes[$key]);
258+
unset($this->attributes[$key]);
257259
}
258260
}

0 commit comments

Comments
 (0)