mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-04 15:57:45 +02:00
[feature/request-class] Refactored request class and wrapper functions.
The request class - now makes use of the new type cast helper (dependency injection) - has no static methods anymore. - now has a constructor argument to leave super globals turned on Brought back the set_var function in functions.php. It is now a wrapper around the type cast helper. It creates an instance on the fly. The request_var wrapper function now has an optional last argument to inject the request class instance, rather than abusing the $var_name. PHPBB3-9716
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user