mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[ticket/10080] Allow resetting the request instance used by request_var.
PHPBB3-10080
This commit is contained in:
parent
cda3ba62b9
commit
458b8841eb
2 changed files with 25 additions and 2 deletions
|
@ -48,11 +48,16 @@ function set_var(&$result, $var, $type, $multibyte = false)
|
|||
* 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_interface::COOKIE as the last param for
|
||||
* phpbb_request_interface::variable for backwards compatability reasons.
|
||||
* @param phpbb_request_interface|null|false If an instance of phpbb_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
|
||||
* instance on every call. By passing false this per-call instantiation can be restored
|
||||
* after having passed in a phpbb_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, phpbb_request_interface $request = null)
|
||||
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.
|
||||
|
@ -67,6 +72,15 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false, p
|
|||
return;
|
||||
}
|
||||
}
|
||||
else if ($request === false)
|
||||
{
|
||||
$static_request = null;
|
||||
|
||||
if (empty($var_name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$tmp_request = $static_request;
|
||||
|
||||
|
|
|
@ -12,6 +12,15 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
|||
|
||||
class phpbb_request_var_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* Makes sure request_var has its standard behaviour.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
request_var(false, false, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider request_variables
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue