-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathIncomingRequest.php
More file actions
48 lines (39 loc) · 1.01 KB
/
Copy pathIncomingRequest.php
File metadata and controls
48 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php namespace Clockwork\Request;
// Incoming HTTP request
class IncomingRequest
{
// Method
public $method;
// URI
public $uri;
// Headers
public $headers;
// GET and POST data
public $input = [];
// Cookies
public $cookies = [];
// Host
public $host;
public function __construct(array $data = [])
{
foreach ($data as $key => $val) $this->$key = $val;
}
// Returns a header value, or default if not set
public function header($key, $default = null)
{
return isset($this->headers[$key]) ? $this->headers[$key] : $default;
}
// Returns an input value, or default if not set
public function input($key, $default = null)
{
return isset($this->input[$key]) ? $this->input[$key] : $default;
}
// Returns true, if HTTP host is one of the common domains used for local development
public function hasLocalHost()
{
$segments = explode('.', $this->host);
$tld = $segments[count($segments) - 1];
return $this->host == '127.0.0.1'
|| in_array($tld, [ 'localhost', 'local', 'test', 'wip' ]);
}
}