Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluent-smtp/includes/Request/Request.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace FluentMail\Includes\Request;
4 +
5 + use FluentMail\Includes\Support\Arr;
6 +
7 + class Request
8 + {
9 + use FileHandler, Cleaner;
10 +
11 + protected $app = null;
12 + protected $headers = array();
13 + protected $server = array();
14 + protected $cookie = array();
15 + protected $json = array();
16 + protected $get = array();
17 + protected $post = array();
18 + protected $files = array();
19 + protected $request = array();
20 +
21 + public function __construct($app, $get, $post, $files)
22 + {
23 + $this->app = $app;
24 + $this->server = $_SERVER;
25 + $this->cookie = $_COOKIE;
26 + $this->files = $this->prepareFiles($files);
27 + $this->request = array_merge(
28 + $this->get = $this->clean($get),
29 + $this->post = $this->clean($post)
30 + );
31 + }
32 +
33 + /**
34 + * Variable exists
35 + * @param string $key
36 + * @return bool
37 + */
38 + public function exists($key)
39 + {
40 + return Arr::has($this->request, $key);
41 + }
42 +
43 + /**
44 + * Variable exists and has truthy value
45 + * @param string $key
46 + * @return bool
47 + */
48 + public function has($key)
49 + {
50 + return $this->exists($key) && !empty(Arr::get($this->request, $key));
51 + }
52 +
53 + public function set($key, $value)
54 + {
55 + Arr::set($this->request, $key, $value);
56 +
57 + return $this;
58 + }
59 +
60 + public function all()
61 + {
62 + return $this->get();
63 + }
64 +
65 + public function get($key = null, $default = null)
66 + {
67 + return Arr::get($this->request, $key, $default);
68 + }
69 +
70 + /**
71 + * Get the files from the request.
72 + *
73 + * @return array
74 + */
75 + public function files()
76 + {
77 + return $this->files;
78 + }
79 +
80 + public function query($key = null, $default = null)
81 + {
82 + return $key ? Arr::get($this->get, $key, $default) : $this->get;
83 + }
84 +
85 + public function post($key = null, $default = null)
86 + {
87 + return $key ? Arr::get($this->post, $key, $default) : $this->post;
88 + }
89 +
90 + public function only($keys)
91 + {
92 + return Arr::only($this->request, $keys);
93 + }
94 +
95 + public function except($args)
96 + {
97 + return Arr::except($this->request, $args);
98 + }
99 +
100 + public function merge(array $data = [])
101 + {
102 + $this->request = array_replace($this->request, $data);
103 +
104 + return $this;
105 + }
106 +
107 + /**
108 + * Get user ip address
109 + * @return string
110 + */
111 + public function getIp()
112 + {
113 + if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
114 + $ip = $this->server('HTTP_CLIENT_IP');
115 + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
116 + $ip = $this->server('HTTP_X_FORWARDED_FOR');
117 + } else {
118 + $ip = $this->server('REMOTE_ADDR');
119 + }
120 +
121 + return $ip;
122 + }
123 +
124 + public function server($key = null, $default = null)
125 + {
126 + return $key ? Arr::get($this->server, $key, $default) : $this->server;
127 + }
128 +
129 + public function header($key = null, $default = null)
130 + {
131 + if (!$this->headers) {
132 + $this->headers = $this->setHeaders();
133 + }
134 +
135 + return $key ? Arr::get($this->headers, $key, $default) : $this->headers;
136 + }
137 +
138 + public function method()
139 + {
140 + return $this->server('REQUEST_METHOD');
141 + }
142 +
143 + public function cookie($key = null, $default = null)
144 + {
145 + return $key ? Arr::get($this->cookie, $key, $default) : $this->cookie;
146 + }
147 +
148 + /**
149 + * Taken and modified from Symfony
150 + */
151 + public function setHeaders()
152 + {
153 + $headers = array();
154 + $parameters = $this->server;
155 + $contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
156 + foreach ($parameters as $key => $value) {
157 + if (0 === strpos($key, 'HTTP_')) {
158 + $headers[substr($key, 5)] = $value;
159 + } // CONTENT_* are not prefixed with HTTP_
160 + elseif (isset($contentHeaders[$key])) {
161 + $headers[$key] = $value;
162 + }
163 + }
164 +
165 + if (isset($parameters['PHP_AUTH_USER'])) {
166 + $headers['PHP_AUTH_USER'] = $parameters['PHP_AUTH_USER'];
167 + $headers['PHP_AUTH_PW'] = isset($parameters['PHP_AUTH_PW']) ? $parameters['PHP_AUTH_PW'] : '';
168 + } else {
169 + /*
170 + * php-cgi under Apache does not pass HTTP Basic user/pass to PHP by default
171 + * For this workaround to work, add these lines to your .htaccess file:
172 + * RewriteCond %{HTTP:Authorization} ^(.+)$
173 + * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
174 + *
175 + * A sample .htaccess file:
176 + * RewriteEngine On
177 + * RewriteCond %{HTTP:Authorization} ^(.+)$
178 + * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
179 + * RewriteCond %{REQUEST_FILENAME} !-f
180 + * RewriteRule ^(.*)$ app.php [QSA,L]
181 + */
182 +
183 + $authorizationHeader = null;
184 + if (isset($parameters['HTTP_AUTHORIZATION'])) {
185 + $authorizationHeader = $parameters['HTTP_AUTHORIZATION'];
186 + } elseif (isset($parameters['REDIRECT_HTTP_AUTHORIZATION'])) {
187 + $authorizationHeader = $parameters['REDIRECT_HTTP_AUTHORIZATION'];
188 + }
189 +
190 + if (null !== $authorizationHeader) {
191 + if (0 === stripos($authorizationHeader, 'basic ')) {
192 + // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
193 + $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)), 2);
194 + if (count($exploded) == 2) {
195 + list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
196 + }
197 + } elseif (empty($parameters['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader, 'digest '))) {
198 + // In some circumstances PHP_AUTH_DIGEST needs to be set
199 + $headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
200 + $parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
201 + } elseif (0 === stripos($authorizationHeader, 'bearer ')) {
202 + /*
203 + * XXX: Since there is no PHP_AUTH_BEARER in PHP predefined variables,
204 + * I'll just set $headers['AUTHORIZATION'] here.
205 + * http://php.net/manual/en/reserved.variables.server.php
206 + */
207 + $headers['AUTHORIZATION'] = $authorizationHeader;
208 + }
209 + }
210 + }
211 +
212 + if (isset($headers['AUTHORIZATION'])) {
213 + return $headers;
214 + }
215 +
216 + // PHP_AUTH_USER/PHP_AUTH_PW
217 + if (isset($headers['PHP_AUTH_USER'])) {
218 + $headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
219 + } elseif (isset($headers['PHP_AUTH_DIGEST'])) {
220 + $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
221 + }
222 +
223 + return $headers;
224 + }
225 +
226 + /**
227 + * Get an input element from the request.
228 + *
229 + * @param string $key
230 + * @return mixed
231 + */
232 + public function __get($key)
233 + {
234 + return $this->get($key);
235 + }
236 + }
237 +