1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 11:44:08 +02:00

[feature/request-class] Add server(), header() and is_ajax() to request

Extend the request class with helpers for reading server vars (server())
and HTTP request headers (header()). Refactor the existing code base
to make use of these helpers, make $_SERVER a deactivated super global.

Also introduce an is_ajax() method, which checks the X-Requested-With
header for the value 'XMLHttpRequest', which is sent by JavaScript
libraries, such as jQuery.

PHPBB3-9716
This commit is contained in:
Igor Wiedler
2011-07-13 19:20:16 +02:00
parent 09e0460e5b
commit 0bf6966c52
23 changed files with 318 additions and 152 deletions

View File

@@ -29,6 +29,7 @@ interface phpbb_request_interface
const GET = 1;
const REQUEST = 2;
const COOKIE = 3;
const SERVER = 4;
/**#@-*/
/**
@@ -60,11 +61,34 @@ interface phpbb_request_interface
* Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
* @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global
* Specifies which super global should be used
* @param bool $html_encode When true, html encoding will be applied
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST);
public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $html_encode = true);
/**
* Shortcut method to retrieve SERVER variables.
*
* @param string|array $var_name See phpbb_request_interface::variable
* @param mixed $default See phpbb_request_interface::variable
* @param bool $html_encode See phpbb_request_interface::variable
*
* @return mixed The server variable value.
*/
public function server($var_name, $default = '', $html_encode = false);
/**
* Shortcut method to retrieve the value of client HTTP headers.
*
* @param string|array $header_name The name of the header to retrieve.
* @param mixed $default See phpbb_request_interface::variable
* @param bool $html_encode See phpbb_request_interface::variable
*
* @return mixed The header value.
*/
public function header($var_name, $default = '', $html_encode = false);
/**
* Checks whether a certain variable was sent via POST.
@@ -90,6 +114,13 @@ interface phpbb_request_interface
*/
public function is_set($var, $super_global = phpbb_request_interface::REQUEST);
/**
* Checks whether the current request is an AJAX request (XMLHttpRequest)
*
* @return bool True if the current request is an ajax request
*/
public function is_ajax();
/**
* Returns all variable names for a given super global
*