NEW: Register Injector::inst()->get(HTTPRequest)

HTTPRequest is provided as a service so that global references for
session, hostname, etc can be facilitated. It’s a bit of a hack and
should be avoided but we’re unlikely to scrub it completely from the
Silverstripe 4 code.
This commit is contained in:
Sam Minnee 2017-06-23 15:34:51 +12:00 committed by Damian Mooyman
parent 10866c0809
commit 4d89daac78

View File

@ -304,6 +304,8 @@ class Director implements TemplateGlobalProvider
*/ */
public static function handleRequest(HTTPRequest $request) public static function handleRequest(HTTPRequest $request)
{ {
Injector::inst()->registerService($request, HTTPRequest::class);
$rules = Director::config()->uninherited('rules'); $rules = Director::config()->uninherited('rules');
// Get global middlewares // Get global middlewares
@ -376,11 +378,15 @@ class Director implements TemplateGlobalProvider
} }
// Call the handler with the given middlewares // Call the handler with the given middlewares
return self::callWithMiddlewares( $response = self::callWithMiddlewares(
$request, $request,
$middlewares, $middlewares,
$handler $handler
); );
Injector::inst()->unregisterNamedObject(HTTPRequest::class);
return $response;
} }
/** /**