diff options
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r-- | phpBB/includes/functions.php | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d5132d218e..81c5c40fd1 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -18,6 +18,13 @@ if (!defined('IN_PHPBB')) // Common global functions +function set_var(&$result, $var, $type, $multibyte = false) +{ + // no need for dependency injection here, if you have the object, call the method yourself! + $type_cast_helper = new phpbb_type_cast_helper(); + $type_cast_helper->set_var($result, $var, $type, $multibyte); +} + /** * Wrapper function of phpbb_request::variable which exists for backwards compatability. * See {@link phpbb_request_interface::variable phpbb_request_interface::variable} for @@ -40,30 +47,30 @@ if (!defined('IN_PHPBB')) * @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) +function request_var($var_name, $default, $multibyte = false, $cookie = false, phpbb_request_interface $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 $request = null; + static $static_request = null; - if ($var_name instanceof phpbb_request_interface) + if ($request instanceof phpbb_request_interface) { - $request = $var_name; - return; + $static_request = $request; + + if (empty($var_name)) + { + return; + } } + $tmp_request = $static_request; + // no request class set, create a temporary one ourselves to keep backwards compatability - if ($request === null) + if ($tmp_request === null) { - $tmp_request = new phpbb_request(); - // enable super globals, so the magically created request class does not + // false param: enable super globals, so the created request class does not // make super globals inaccessible everywhere outside this function. - $tmp_request->enable_super_globals(); - } - else - { - // otherwise use the static injected instance - $tmp_request = $request; + $tmp_request = new phpbb_request(new phpbb_type_cast_helper(), false); } return $tmp_request->variable($var_name, $default, $multibyte, ($cookie) ? phpbb_request_interface::COOKIE : phpbb_request_interface::REQUEST); |