mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/12479] Remove request_var function
PHPBB-12479
This commit is contained in:
parent
06d226f292
commit
f4cad55581
3 changed files with 8 additions and 76 deletions
|
@ -49,8 +49,6 @@ function register_compatibility_globals()
|
||||||
|
|
||||||
/* @var $request \phpbb\request\request_interface */
|
/* @var $request \phpbb\request\request_interface */
|
||||||
$request = $phpbb_container->get('request');
|
$request = $phpbb_container->get('request');
|
||||||
// Inject request instance, so only this instance is used with request_var
|
|
||||||
request_var('', 0, false, false, $request);
|
|
||||||
|
|
||||||
/* @var $user \phpbb\user */
|
/* @var $user \phpbb\user */
|
||||||
$user = $phpbb_container->get('user');
|
$user = $phpbb_container->get('user');
|
||||||
|
|
|
@ -19,67 +19,6 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper function of \phpbb\request\request::variable which exists for backwards compatability.
|
|
||||||
* See {@link \phpbb\request\request_interface::variable \phpbb\request\request_interface::variable} for
|
|
||||||
* documentation of this function's use.
|
|
||||||
*
|
|
||||||
* @deprecated 3.1.0 (To be removed: 4.0.0)
|
|
||||||
* @param mixed $var_name The form variable's name from which data shall be retrieved.
|
|
||||||
* If the value is an array this may be an array of indizes which will give
|
|
||||||
* direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a")
|
|
||||||
* then specifying array("var", 1) as the name will return "a".
|
|
||||||
* If you pass an instance of {@link \phpbb\request\request_interface phpbb_request_interface}
|
|
||||||
* as this parameter it will overwrite the current request class instance. If you do
|
|
||||||
* not do so, it will create its own instance (but leave superglobals enabled).
|
|
||||||
* @param mixed $default A default value that is returned if the variable was not set.
|
|
||||||
* This function will always return a value of the same type as the default.
|
|
||||||
* @param bool $multibyte If $default is a string this paramater has to be true if the variable may contain any UTF-8 characters
|
|
||||||
* Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
|
|
||||||
* @param bool $cookie This param is mapped to \phpbb\request\request_interface::COOKIE as the last param for
|
|
||||||
* \phpbb\request\request_interface::variable for backwards compatability reasons.
|
|
||||||
* @param \phpbb\request\request_interface|null|false $request
|
|
||||||
* If an instance of \phpbb\request\request_interface is given the instance is stored in
|
|
||||||
* a static variable and used for all further calls where this parameters is null. Until
|
|
||||||
* the function is called with an instance it automatically creates a new \phpbb\request\request
|
|
||||||
* instance on every call. By passing false this per-call instantiation can be restored
|
|
||||||
* after having passed in a \phpbb\request\request_interface instance.
|
|
||||||
*
|
|
||||||
* @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.
|
|
||||||
*/
|
|
||||||
function request_var($var_name, $default, $multibyte = false, $cookie = false, $request = null)
|
|
||||||
{
|
|
||||||
// This is all just an ugly hack to add "Dependency Injection" to a function
|
|
||||||
// the only real code is the function call which maps this function to a method.
|
|
||||||
static $static_request = null;
|
|
||||||
if ($request instanceof \phpbb\request\request_interface)
|
|
||||||
{
|
|
||||||
$static_request = $request;
|
|
||||||
if (empty($var_name))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ($request === false)
|
|
||||||
{
|
|
||||||
$static_request = null;
|
|
||||||
if (empty($var_name))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tmp_request = $static_request;
|
|
||||||
// no request class set, create a temporary one ourselves to keep backwards compatibility
|
|
||||||
if ($tmp_request === null)
|
|
||||||
{
|
|
||||||
// false param: enable super globals, so the created request class does not
|
|
||||||
// make super globals inaccessible everywhere outside this function.
|
|
||||||
$tmp_request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
|
||||||
}
|
|
||||||
return $tmp_request->variable($var_name, $default, $multibyte, ($cookie) ? \phpbb\request\request_interface::COOKIE : \phpbb\request\request_interface::REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Casts a variable to the given type.
|
* Casts a variable to the given type.
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,15 +13,6 @@
|
||||||
|
|
||||||
class phpbb_request_var_test extends phpbb_test_case
|
class phpbb_request_var_test extends phpbb_test_case
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Makes sure request_var has its standard behaviour.
|
|
||||||
*/
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
request_var(false, false, false, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider request_variables
|
* @dataProvider request_variables
|
||||||
*/
|
*/
|
||||||
|
@ -33,7 +24,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||||
$_POST[$variable_name] = $variable_value;
|
$_POST[$variable_name] = $variable_value;
|
||||||
$_REQUEST[$variable_name] = $variable_value;
|
$_REQUEST[$variable_name] = $variable_value;
|
||||||
|
|
||||||
$result = request_var($variable_name, $default, $multibyte);
|
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||||
|
$result = $request->variable($variable_name, $default, $multibyte);
|
||||||
|
|
||||||
$label = 'Requesting POST variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
$label = 'Requesting POST variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
||||||
$this->assertEquals($expected, $result, $label);
|
$this->assertEquals($expected, $result, $label);
|
||||||
|
@ -50,7 +42,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||||
$_GET[$variable_name] = $variable_value;
|
$_GET[$variable_name] = $variable_value;
|
||||||
$_REQUEST[$variable_name] = $variable_value;
|
$_REQUEST[$variable_name] = $variable_value;
|
||||||
|
|
||||||
$result = request_var($variable_name, $default, $multibyte);
|
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||||
|
$result = $request->variable($variable_name, $default, $multibyte);
|
||||||
|
|
||||||
$label = 'Requesting GET variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
$label = 'Requesting GET variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
||||||
$this->assertEquals($expected, $result, $label);
|
$this->assertEquals($expected, $result, $label);
|
||||||
|
@ -69,7 +62,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||||
$_REQUEST[$variable_name] = false;
|
$_REQUEST[$variable_name] = false;
|
||||||
$_COOKIE[$variable_name] = $variable_value;
|
$_COOKIE[$variable_name] = $variable_value;
|
||||||
|
|
||||||
$result = request_var($variable_name, $default, $multibyte, true);
|
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||||
|
$result = $request->variable($variable_name, $default, $multibyte, \phpbb\request\request_interface::COOKIE);
|
||||||
|
|
||||||
$label = 'Requesting COOKIE variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
$label = 'Requesting COOKIE variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
||||||
$this->assertEquals($expected, $result, $label);
|
$this->assertEquals($expected, $result, $label);
|
||||||
|
@ -109,7 +103,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = request_var($path, $default);
|
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||||
|
$result = $request->variable($path, $default);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue