119 $this->
files = new \Elgg\Http\ParameterBag(
$files);
120 $this->server = new \Elgg\Http\ParameterBag(
$server);
124 $this->headers = new \Elgg\Http\ParameterBag(
$headers);
133 return new \Elgg\Http\Request($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
153 'SERVER_NAME' =>
'localhost',
155 'HTTP_HOST' =>
'localhost',
156 'HTTP_USER_AGENT' =>
'Symfony/2.X',
157 'HTTP_ACCEPT' =>
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
158 'HTTP_ACCEPT_LANGUAGE' =>
'en-us,en;q=0.5',
159 'HTTP_ACCEPT_CHARSET' =>
'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
160 'REMOTE_ADDR' =>
'127.0.0.1',
162 'SCRIPT_FILENAME' =>
'',
163 'SERVER_PROTOCOL' =>
'HTTP/1.1',
164 'REQUEST_TIME' => time(),
171 if (isset($components[
'host'])) {
172 $server[
'SERVER_NAME'] = $components[
'host'];
173 $server[
'HTTP_HOST'] = $components[
'host'];
176 if (isset($components[
'scheme'])) {
177 if (
'https' === $components[
'scheme']) {
186 if (isset($components[
'port'])) {
187 $server[
'SERVER_PORT'] = $components[
'port'];
188 $server[
'HTTP_HOST'] =
$server[
'HTTP_HOST'] .
':' . $components[
'port'];
191 if (!isset($components[
'path'])) {
192 $components[
'path'] =
'/';
199 if (!isset(
$server[
'CONTENT_TYPE'])) {
200 $server[
'CONTENT_TYPE'] =
'application/x-www-form-urlencoded';
212 if (isset($components[
'query'])) {
213 parse_str(html_entity_decode($components[
'query']), $qs);
217 $queryString = http_build_query(
$query,
'',
'&');
219 $server[
'REQUEST_URI'] = $components[
'path'] . (
'' !== $queryString ?
'?' . $queryString :
'');
220 $server[
'QUERY_STRING'] = $queryString;
243 foreach (explode(
'&', $qs) as $param) {
244 if (
'' === $param ||
'=' === $param[0]) {
252 $keyValuePair = explode(
'=', $param, 2);
259 $parts[] = isset($keyValuePair[1]) ?
260 rawurlencode(urldecode($keyValuePair[0])) .
'=' . rawurlencode(urldecode($keyValuePair[1])) :
261 rawurlencode(urldecode($keyValuePair[0]));
262 $order[] = urldecode($keyValuePair[0]);
265 array_multisort($order, SORT_ASC, $parts);
267 return implode(
'&', $parts);
281 if ($this->query->has(
$key)) {
282 return $this->query->get(
$key);
283 }
else if ($this->request->has(
$key)) {
284 return $this->request->get(
$key);
296 if (null === $this->requestUri) {
333 return $this->
isSecure() ?
'https' :
'http';
347 if ((
'http' == $scheme && $port == 80) || (
'https' == $scheme && $port == 443)) {
351 return $this->
getHost() .
':' . $port;
362 if (!$host = $this->headers->get(
'HOST')) {
363 if (!$host = $this->server->get(
'SERVER_NAME')) {
364 $host = $this->server->get(
'SERVER_ADDR',
'');
370 $host = strtolower(preg_replace(
'/:\d+$/',
'', trim($host)));
375 if ($host && !preg_match(
'/^\[?(?:[a-zA-Z0-9-:\]_]+\.?)+$/', $host)) {
376 throw new \UnexpectedValueException(
'Invalid Host');
388 return 'on' == strtolower($this->server->get(
'HTTPS')) || 1 == $this->server->get(
'HTTPS');
397 return $this->server->get(
'SERVER_PORT');
414 if (null === $this->baseUrl) {
437 if (null === $this->pathInfo) {
455 return '' === $qs ? null : $qs;
466 $path = trim($this->query->get(
'__elgg_uri'),
'/');
471 return explode(
'/',
$path);
484 return array_shift($segments);
498 $ip_address =
$server->get(
'HTTP_X_FORWARDED_FOR');
499 if (!empty($ip_address)) {
500 return array_pop(explode(
',', $ip_address));
503 $ip_address =
$server->get(
'HTTP_X_REAL_IP');
504 if (!empty($ip_address)) {
505 return array_pop(explode(
',', $ip_address));
508 return $server->get(
'REMOTE_ADDR');
517 return $this->headers->get(
'X-Requested-With') ==
'XMLHttpRequest' ||
518 $this->
get(
'X-Requested-With') ===
'XMLHttpRequest';
528 if (get_magic_quotes_gpc()) {
542 $contentHeaders = array(
'CONTENT_LENGTH' =>
true,
'CONTENT_MD5' =>
true,
'CONTENT_TYPE' =>
true);
544 if (0 === strpos(
$key,
'HTTP_')) {
545 $key = strtr(strtolower(substr(
$key, 5)),
'_',
'-');
546 $key = implode(
'-', array_map(
'ucfirst', explode(
'-',
$key)));
548 } elseif (isset($contentHeaders[
$key])) {
549 $key = strtr(strtolower($key),
'_',
'-');
550 $key = implode(
'-', array_map(
'ucfirst', explode(
'-', $key)));
567 return $this->server->get(
'REQUEST_URI');
576 $filename = basename($this->server->get(
'SCRIPT_FILENAME'));
578 if (basename($this->server->get(
'SCRIPT_NAME')) ===
$filename) {
579 $baseUrl = $this->server->get(
'SCRIPT_NAME');
580 } elseif (basename($this->server->get(
'PHP_SELF')) ===
$filename) {
581 $baseUrl = $this->server->get(
'PHP_SELF');
582 } elseif (basename($this->server->get(
'ORIG_SCRIPT_NAME')) ===
$filename) {
583 $baseUrl = $this->server->get(
'ORIG_SCRIPT_NAME');
587 $path = $this->server->get(
'PHP_SELF',
'');
588 $file = $this->server->get(
'SCRIPT_FILENAME',
'');
589 $segs = explode(
'/', trim($file,
'/'));
590 $segs = array_reverse($segs);
592 $last = count($segs);
595 $seg = $segs[$index];
598 }
while (($last > $index) && (
false !== ($pos = strpos(
$path,
$baseUrl))) && (0 != $pos));
611 return rtrim($prefix,
'/');
616 $truncatedRequestUri = substr(
$requestUri, 0, $pos);
620 if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
673 private function getUrlencodedPrefix(
$string, $prefix) {
674 if (0 !== strpos(rawurldecode(
$string), $prefix)) {
678 $len = strlen($prefix);
680 if (preg_match(
"#^(%[[:xdigit:]]{2}|.){{$len}}#",
$string, $match)) {
elgg parse_str
Returns an object with key/values of the parsed query string.
__construct(array $query=array(), array $request=array(), array $cookies=array(), array $files=array(), array $server=array())
Create a request.
getHost()
Returns the host name.
getFirstUrlSegment()
Get first URL segment from the path info.
preparePathInfo()
Prepares the path info.
getClientIp()
Get the IP address of the client.
static create($uri, $method= 'GET', $parameters=array(), $cookies=array(), $files=array(), $server=array())
Creates a Request based on a given URI and configuration.
elgg parse_url
Parse a URL into its parts.
getScheme()
Gets the request's scheme.
prepareBaseUrl()
Prepares the base URL.
isXmlHttpRequest()
Is this an ajax request.
initialize(array $query=array(), array $request=array(), array $cookies=array(), array $files=array(), array $server=array())
Initialize the request.
getSchemeAndHttpHost()
Gets the scheme and HTTP host.
stripSlashesIfMagicQuotes($data)
Strip slashes if magic quotes is on.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition files
getUri()
Generates a normalized URI for the Request.
getQueryString()
Gets the normalized query string for the Request.
getRequestUri()
Returns the requested URI.
isSecure()
Is this request using SSL.
getUrlSegments()
Get URL segments from the path info.
getPort()
Returns the port on which the request is made.
getPathInfo()
Returns the path being requested relative to the executed script.
getBaseUrl()
Returns the root url from which this request is executed.
getHttpHost()
Returns the HTTP host being requested.
prepareHeaders()
Get the HTTP headers from server.
static normalizeQueryString($qs)
Normalizes a query string.
static createFromGlobals()
Creates a request from PHP's globals.
prepareRequestUri()
Set the request URI.