Not a bug XF\Http\Request and XF\Http\Response can't be extended through class proxy system

Kirby

Well-known member
Affected version
2.2.4
XF\Http\Request and XF\Http\Response currently can't be extended through the class proxy system.

Several use cases (like explicitly getting POST data without directly touching $_POST in integration scenarios) could probably benefit from being able to extend those classes.
 
Unfortunately there are situations with these where extending them may produce inconsistent results, such as if the object is available before add-ons are fetched (either as a matter of course or under some conditions) as in these cases the class extensions wouldn't be applied anyway.

So I don't think we'll be able to make changes here but there are potential other workarounds.

1) If you have specific use cases in mind, we may be able to introduce specific code events in places that are unlikely to be affected by issues mentioned.

2) If it's not for a public add-on but for internal code, you can build your own request/response objects that extend ours and return them via src/config.php:

PHP:
$c['request'] = function (\XF\Container $c)
{
    $request = new \Your\Custom\Http\Request($c['inputFilterer']);
    $request->setCookiePrefix($c['config']['cookie']['prefix']);
    return $request;
};

So for now we're not aiming to fix this but if you have any further feedback such as specific code events that might be useful then please post a new thread in the suggestions forum.
 
Top Bottom