Skip to content
Snippets Groups Projects
Commit 27ac97ef authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1957156 by Crell, rootatwc: Add a request() method to \Drupal.

parent 2e3c6842
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -121,6 +121,32 @@ public static function service($id) {
return static::$container->get($id);
}
/**
* Retrieves the currently active request object.
*
* Note: The use of this wrapper in particular is especially discourged. Most
* code should not need to access the request directly. Doing so means it
* will only function when handling an HTTP request, and will require special
* modification or wrapping when run from a command line tool, from certain
* queue processors, or from automated tests.
*
* If code must access the request, it is considerably better to register
* an object with the Service Container and give it a setRequest() method
* that is configured to run when the service is created. That way, the
* correct request object can always be provided by the container and the
* service can still be unit tested.
*
* If this method must be used, never save the request object that is
* returned. Doing so may lead to inconsistencies as the request object is
* volatile and may change at various times, such as during a subrequest.
*
* @return \Symfony\Component\HttpFoundation\Request
* The currently active request object.
*/
public static function request() {
return static::$container->get('request');
}
/**
* Returns the current primary database.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment