Textpattern PHP Cross Reference Content Management Systems

Summary: /textpattern/vendors/Textpattern/Http/Request.php - 762 lines - 20089 bytes - Source - Print

Description: Inspects the current HTTP request.

Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Request:: (20 methods):
__construct()
getAcceptedType()
getAcceptedLanguage()
getAcceptedEncoding()
getUrl()
getHost()
getPort()
getIp()
getRemoteHostname()
getProtocol()
getReferer()
getUri()
getHeaders()
getHeader()
getCookies()
getCookie()
getQuery()
getParam()
getPost()
getAcceptsMap()

Class: Request


__construct(\Textpattern\Server\Config $request = null)  line: 109
Constructor.

<code>
echo Txp::get('\Textpattern\Http\Request', new Abc_Custom_Request_Data)->getHostName();
</code>

param: \Textpattern\Server\Config|null $request The raw request data, defaults to the current request body
getAcceptedType($formats, $threshold = 0.1)  line: 128
Checks whether the client accepts a certain response format.

By default discards formats with quality factors below an arbitrary
threshold as jQuery adds a wildcard content-type with quality of '0.01'
to the 'Accept' header for XHR requests.

Supplied format of 'html', 'txt', 'js', 'css', 'json', 'xml', 'rdf',
'atom' or 'rss' is autocompleted and matched against multiple valid MIMEs.

Both of the following will return MIME for JSON if 'json' format is
supported:

<code>
echo Txp::get('\Textpattern\Http\Request')->getAcceptedType('json');
echo Txp::get('\Textpattern\Http\Request')->getAcceptedType('application/json');
</code>

The method can also be used to check an array of types:

<code>
echo Txp::get('\Textpattern\Http\Request')->getAcceptedType(array('application/xml', 'application/x-xml'));
</code>

Stops on first accepted format.

return: string|bool Supported type, or FALSE if not
param: string|array $formats   Format to check
param: float        $threshold Quality threshold
getAcceptedLanguage($languages = null, $threshold = 0.1)  line: 180
Gets accepted language.

If $languages is NULL, returns client's favoured language. If
string, checks whether the language is supported and
if an array, returns the language that the client favours the most.

<code>
echo Txp::get('\Textpattern\Http\Request')->getAcceptedLanguage('fi-FI');
</code>

The above will return 'fi-FI' as long as the Accept-Language header
contains an identifier that matches Finnish, such as 'fi-fi', 'fi-Fi'
or 'fi'.

return: string|bool Accepted language, or FALSE
param: string|array $languages Languages to check
param: float        $threshold Quality threshold
getAcceptedEncoding($encodings = null, $threshold = 0.1)  line: 231
Gets accepted encoding.

Negotiates a common encoding between the client and the server.

<code>
if (Txp::get('\Textpattern\Http\Request')->getAcceptedEncoding('gzip')) {
echo 'Client accepts gzip.';
}
</code>

return: string|bool Encoding method, or FALSE
param: string|array $encodings Encoding
param: float        $threshold Quality threshold
getUrl()  line: 266
Gets an absolute URL pointing to the requested document.

<code>
echo Txp::get('\Textpattern\Http\Request')->getUrl();
</code>

The above will return URL pointing to the requested
page, e.g. http://example.test/path/to/subpage.

return: string The URL
getHost()  line: 290
Gets the server hostname.

<code>
echo Txp::get('\Textpattern\Http\Request')->getHost();
</code>

Returns 'example.com' if requesting
http://example.test/path/to/subpage.

return: string The host
getPort()  line: 308
Gets the port, if not default.

This method returns FALSE, if the port is the request protocol's default.
Neither '80' or 443 for HTTPS are returned.

<code>
echo Txp::get('\Textpattern\Http\Request')->getPort();
</code>

Returns '8080' if requesting http://example.test:8080/path/to/subpage.

return: int|bool Port number, or FALSE
getIp()  line: 335
Gets the client IP address.

This method supports proxies and uses 'X_FORWARDED_FOR' HTTP header if
deemed necessary.

<code>
echo Txp::get('\Textpattern\Http\Request')->getIp();
</code>

Returns the IP address the request came from, e.g. '0.0.0.0'.
Can be either IPv6 or IPv4 depending on the request.

return: string The IP address
getRemoteHostname()  line: 364
Gets client hostname.

This method resolves client's hostname.

<code>
echo Txp::get('\Textpattern\Http\Request')->getRemoteHostname();
</code>

return: string|bool The hostname, or FALSE on failure
getProtocol()  line: 395
Gets the request protocol.

<code>
echo Txp::get('\Textpattern\Http\Request')->getProtocol();
</code>

Returns 'https' if requesting https://example.test:8080/path/to/subpage.

return: string Either 'http' or 'https'
getReferer()  line: 424
Gets referer.

Returns referer header if it does not originate from the current
hostname or come from a HTTPS page to a HTTP page.

<code>
echo Txp::get('\Textpattern\Http\Request')->getReferer();
</code>

Returns full URL such as 'http://example.com/referring/page.php?id=12'.

return: string|bool Referer, or FALSE if not available
getUri()  line: 466
Gets requested URI.

<code>
echo Txp::get('\Textpattern\Http\Request')->getUri();
</code>

Returns '/some/requested/page?and=query' if requesting
http://example.com/some/requested/page?and=query.

return: string The URI
getHeaders()  line: 484
Gets an array map of raw request headers.

This method is web server agnostic.

The following:

<code>
print_r(Txp::get('\Textpattern\Http\Request')->getHeaders());
</code>

Returns:

<code>
Array
(
[Host] => example.test
[Connection] => keep-alive
[Cache-Control] => max-age=0
[User-Agent] => User-Agent
[Referer] => http://example.test/textpattern/index.php
[Accept-Encoding] => gzip,deflate,sdch
[Accept-Language] => en-US,en;q=0.8,fi;q=0.6
[Cookie] => toggle_show_spam=1
)
</code>

return: array An array of HTTP request headers
getHeader($name line: 538
Gets a raw HTTP request header value.

<code>
echo Txp::get('\Textpattern\Http\Request')->getHeader('User-Agent');
</code>

Will return the client's User-Agent header, if it has any. If the client
didn't send User-Agent, the method returns FALSE.

return: string|bool The header value, or FALSE on failure
param: string $name The header name
getCookies()  line: 563
Gets an array of HTTP cookies.

<code>
print_r(Txp::get('\Textpattern\Http\Request')->getHeaders());
</code>

Returns:

<code>
Array(
[foobar] => value
)
</code>

Returned cookie values are processed properly for you, and will not
contain runtime quoting slashes or be URL encoded. Just pick and choose.

return: array An array of cookies
getCookie($name line: 597
Gets a HTTP cookie.

<code>
echo Txp::get('\Textpattern\Http\Request')->getCookie('foobar');
</code>

return: string The value
param: string $name The cookie name
getQuery()  line: 617
Gets a query string.

<code>
print_r(Txp::get('\Textpattern\Http\Request')->getQuery());
</code>

If requesting "?event=article&amp;step=save", the above returns:

<code>
Array
(
[event] => article
[step] => save
)
</code>

return: array An array of parameters
getParam($name line: 656
Gets a HTTP query string parameter.

return: mixed
param: $name The parameter name
getPost($name line: 675
Gets a HTTP post parameter.

return: mixed
param: string $name The parameter name
getAcceptsMap($header line: 693
Builds a content-negotiation accepts map from the given value.

Keys are the accepted type and the value are the params. If client
doesn't specify quality, defaults to 1.0. Values are sorted by the
quality, from the highest to the lowest.

This method can be used to parse Accept, Accept-Charset, Accept-Encoding
and Accept-Language header values.

<code>
print_r(Txp::get('\Textpattern\Http\Request')->getAcceptsMap('en-us;q=1.0,en;q=0.9'));
</code>

Returns:

<code>
Array
(
[en-us] => Array
(
[q] => 1.0
)
[en] => Array
(
[q] => 0.9
)
)
</code>

return: array Accepts map
param: string $header The header string

title

Body