1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Zemit Framework. |
4
|
|
|
* |
5
|
|
|
* (c) Zemit Team <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Zemit\Http; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Request |
15
|
|
|
* {@inheritDoc} |
16
|
|
|
* |
17
|
|
|
* @author Julien Turbide <[email protected]> |
18
|
|
|
* @copyright Zemit Team <[email protected]> |
19
|
|
|
* |
20
|
|
|
* @since 1.0 |
21
|
|
|
* @version 1.0 |
22
|
|
|
* |
23
|
|
|
* @package Zemit\Http |
24
|
|
|
*/ |
25
|
|
|
class Request extends \Phalcon\Http\Request |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Return true if cors request |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
|
|
public function isCors() : bool |
32
|
|
|
{ |
33
|
|
|
return !empty($this->getHeader('Origin')) && !$this->isSameOrigin(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Return true if preflight request |
38
|
|
|
* @return bool |
39
|
|
|
*/ |
40
|
|
|
public function isPreflight() : bool |
41
|
|
|
{ |
42
|
|
|
return $this->isCors() |
43
|
|
|
&& $this->isOptions() |
44
|
|
|
&& !empty($this->getHeader('Access-Control-Request-Method')); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Return true if the header origin is the same as the request http host |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
|
|
public function isSameOrigin(): bool |
52
|
|
|
{ |
53
|
|
|
$schemeHost = $this->getScheme() . '://' . $this->getHttpHost(); |
54
|
|
|
return $this->getHeader('Origin') === $schemeHost; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function toArray() |
58
|
|
|
{ |
59
|
|
|
$config = $this->getDI()->get('config'); |
60
|
|
|
if ($config->app->debug || $config->debug->enable) { |
61
|
|
|
return [ |
62
|
|
|
'body' => $this->getRawBody(), |
63
|
|
|
'post' => $this->getPost(), |
64
|
|
|
'get' => $this->get(), |
65
|
|
|
'put' => $this->getPut(), |
66
|
|
|
'headers' => $this->getHeaders(), |
67
|
|
|
'userAgent' => $this->getUserAgent(), |
68
|
|
|
'basicAuth' => $this->getBasicAuth(), |
69
|
|
|
'bestAccept' => $this->getBestAccept(), |
70
|
|
|
'bestCharset' => $this->getBestCharset(), |
71
|
|
|
'bestLanguage' => $this->getBestLanguage(), |
72
|
|
|
'clientAddress' => $this->getClientAddress(), |
73
|
|
|
'clientCharsets' => $this->getClientCharsets(), |
74
|
|
|
'contentType' => $this->getContentType(), |
75
|
|
|
'digestAuth' => $this->getDigestAuth(), |
76
|
|
|
'httpHost' => $this->getHttpHost(), |
77
|
|
|
'uri' => $this->getURI(), |
78
|
|
|
'serverName' => $this->getServerName(), |
79
|
|
|
'serverAddress' => $this->getServerAddress(), |
80
|
|
|
'method' => $this->getMethod(), |
81
|
|
|
'port' => $this->getPort(), |
82
|
|
|
'httpReferer' => $this->getHTTPReferer(), |
83
|
|
|
'languages' => $this->getLanguages(), |
84
|
|
|
'scheme' => $this->getScheme(), |
85
|
|
|
'isAjax' => $this->isAjax(), |
86
|
|
|
'isGet' => $this->isGet(), |
87
|
|
|
'isDelete' => $this->isDelete(), |
88
|
|
|
'isHead' => $this->isHead(), |
89
|
|
|
'isPatch' => $this->isPatch(), |
90
|
|
|
'isConnect' => $this->isConnect(), |
91
|
|
|
'isTrace' => $this->isTrace(), |
92
|
|
|
'isPut' => $this->isPut(), |
93
|
|
|
'isPurge' => $this->isPurge(), |
94
|
|
|
'isOptions' => $this->isOptions(), |
95
|
|
|
'isSoap' => $this->isSoap(), |
96
|
|
|
'isSecure' => $this->isSecure(), |
97
|
|
|
'isCors' => $this->isCors(), |
98
|
|
|
'isPreflight' => $this->isPreflight(), |
99
|
|
|
'isSameOrigin' => $this->isSameOrigin(), |
100
|
|
|
'isValidHttpMethod' => $this->isValidHttpMethod($this->getMethod()), |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|